1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
############################################################################
# --- oggtube 2006.06.10 --- #
# #
# Copyright (C) 2007 by Julià Mestieri Ferrer (Original Author), #
# Andreu Correa Casablanca (Adaptation). #
# #
# Email: castarco@gmail.com (Andreu Correa Casablanca) #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the #
# Free Software Foundation, Inc., #
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
############################################################################
import os
import optparse
import shutil
import sys
youtubedl_call = "youtube-dl http://www.youtube.com/v/"
cmdl_usage = 'usage: %prog [options] videocode_1,vc_2,...,vc_n'
cmdl_version = '2008.06.04'
cmdl_parser = optparse.OptionParser(usage=cmdl_usage, version=cmdl_version, conflict_handler='resolve')
cmdl_parser.add_option('-h', '--help', action='help', help='print this help text and exit')
cmdl_parser.add_option('-v', '--version', action='version', help='print program version and exit')
cmdl_parser.add_option('-u', '--username', dest='username', metavar='USERNAME', help='account username')
cmdl_parser.add_option('-p', '--password', dest='password', metavar='PASSWORD', help='account password')
cmdl_parser.add_option('-o', '--output', dest='outfile', metavar='FILE', help='output video file names "name1,name2,..."')
(cmdl_opts, cmdl_args) = cmdl_parser.parse_args()
if len(cmdl_args) != 1:
cmdl_parser.print_help()
sys.exit('n')
codes = cmdl_args[0].split(',')
if cmdl_opts.outfile:
filenames = cmdl_opts.outfile.split(',')
else:
filenames = []
for x in range(len(filenames)):
if filenames[x][-4:] != ".ogg":
filenames[x] += ".ogg"
for x in range(len(filenames), len(codes)):
filenames.append(codes[x]+".ogg")
if cmdl_opts.username:
youtubedl_call += " -u "+cmdl_opts.username
if cmdl_opts.password:
youtubedl_call += " -p "+cmdl_opts.password
x = 0
while x < len(codes):
if os.access(filenames[x], os.F_OK):
print('The file '+filenames[x]+' already exists, try with another file name.n')
filenames.pop(x)
codes.pop(x)
else:
x += 1
if os.name == 'posix':
dir = os.getcwd()
os.chdir('/tmp')
for x in range(len(codes)):
if filenames[x][0] != '/':
filenames[x] = dir+"/"+filenames[x]
if len(codes) > 0:
if os.system(youtubedl_call+" ".join(codes)) !=0:
sys.exit("I can't download the videos you specified.n")
else:
sys.exit('There is not any file that i can download.n')
for x in range(len(codes)):
os.system("ffmpeg2theora "+codes[x]+".flv")
shutil.move(codes[x]+".ogg", filenames[x])
os.remove(codes[x]+".flv")
sys.exit() |