Oggtube ya tiene alojamiento :)

Antes de empezar mi sesión de estudio de la asignatura 'Mètodes Numèrics' (una de las asignaturas que más miedo me dan, aunque el profesor que la imparte es de los que más aprecio tienen por mi parte, básicamente un tío extraordinario) tengo que anunciar una cosa:

Oggtube ya tiene un alojamiento en https://projectes.lafarga.cat/projects/oggtube . He corregido un bug que permitía bajar diferentes vídeos guardándolos con el mismo nombre de fichero (con lo que unos podían sobreescribir a otros) y ya he creado una interfaz gráfica que se puede ver con la opción -g (aunque todavía no hace nada de nada).

Podéis bajar las últimas versiones del proyecto desde el repositorio con el siguiente comando:
svn checkout --username anonymous https://svn.projectes.lafarga.cat/svn/oggtube

Bueno, ahora ya toca estudiar :) .

Más versiones

Espero que el blog no se transforme simplemente en el lugar donde cuelgo el código que voy haciendo, aunque esta vez lo voy a volver a hacer (no tengo mucho tiempo para escribir largas reflexiones porque estoy de exámenes). El código lo he escrito en el tren después de haber suspendido con casi toda seguridad el exámen de Análisis en varias variables de esta tarde, básicamente lo he hecho para relajarme un poco :p .

Changelog: corregidos "bugs" que no corregí en el otro por no haber testeado el código (nombres mal escritos de algunas variables), he mejorado ligeramente el código utilizando la librería 'shutils' y exprimiendo más la librería 'os', de forma que ahora el código es multiplataforma en toda regla. (Haría falta ver si en Windows existe el programa ffmpeg2theora, jeje. Por otro lado, es ligeramente más tosco el funcionamiento en Windows que en Linux porque no utilizo ningún directorio temporal para guardar los ficheros intermedios). Ahí va el código:

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()

A riesgo de ser pesado... :p

A riesgo de ser pesado, colgaré lo que hecho nuevo de aquel script cutrecillo, he añadido descarga múltiple, he solucionado un bug que introduje sin querer y he eliminado la necesidad de escribir "-c" antes del código de película. (Es que mientras descanso de estudiar tengo que hacer algo para relajarme):

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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
############################################################################
#                      --- oggtube 2006.06.08 ---                          #
#                                                                          #
#   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 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(code + ".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.system("test -e "+filenames[x]) == 0:
		print('The file '+filenames[x]+' already exists, try with another file name.\n')
		filenames.pop(x)
		codes.pop(x)
	else:
		x += 1
 
dir = os.getcwd()
os.chdir("/tmp")
 
if len(codes) > 0:
	os.system(youtubedl_call+" ".join(codes))
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")	
	if filenames[x][0] == '/':
		os.system("mv "+codes[x]+".ogg "+filenames[x])
	else:
		os.system("mv "+codes[x]+".ogg "+dir+"/"+filenames[x])
	os.remove(codes[x]+".flv")
 
sys.exit()

Me aburría en el tren

Hoy he ido a Barcelona para ver si puedo encontrar un trabajo decente para el verano (no, no es broma, de verdad que creo que eso existe), pero nada, parece que hoy no se ha obrado el milagro. Entre todo esto, cuando estaba de vuelta me he puesto a mejorar el script de dos posts más abajo porque me aburría en el tren, así que ahora se le pueden pasar opciones a yotube-dl a través del script. Para hacerlo me he basado en el propio código de youtube-dl, la verdad es que no conozco demasiado bien las librerías Python dedicadas a manejar la línea de consola, así que de paso he aprendido algo. Por cierto, le he cambiado el nombre, porque freetube es un nombre muy utilizado en la red (no sé para qué, pero por lo visto es así), de forma que precisaba un nombre algo más 'original' (tampoco es que lo sea mucho, pero al menos no lo utiliza nadie). Básicamente se llamará oggtube. Y aquí os dejo el código remasterizado:

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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
############################################################################
# Basat en la documentació original de:                                    #
# http://es.blogxpopuli.org/index.php/YouTube2Theora                       #
############################################################################
 
############################################################################
#                           --- oggtube ---                                #
#                                                                          #
#   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 sys
 
youtubedl_call = "youtube-dl http://www.youtube.com/v/"
 
cmdl_usage = 'usage: %prog [options] -c video_code'
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 name')
cmdl_parser.add_option('-c', '--video-code', dest='videocode', metavar='VIDEOCODE', help='video code')
(cmdl_opts, cmdl_args) = cmdl_parser.parse_args()
 
if cmdl_opts.videocode:
	code = cmdl_opts.videocode
else:
	cmdl_parser.print_help()
	sys.exit('\n')
 
if cmdl_opts.outfile:
	filename = cmdl_opts.outfile
	if filename[-4:] != ".ogg":
		filename += ".ogg"
else:
	filename = code + ".ogg"
 
if cmdl_opts.username:
	youtubedl_call += " -u "+cmdl_opts.username
 
if cmdl_opts.password:
	youtubedl_call += " -p "+cmdl_opts.password
 
if os.system("test -e "+filename) == 0:
	print "The file "+filename+" already exists, try with another file name."
	sys.exit('\n')
 
os.chdir("/tmp")
 
os.system(youtubedl_call+code)
os.system("ffmpeg2theora "+code+".flv")
 
if filename[0] == '/':
	os.system("mv "+code+".ogg "+filename)
else:
	os.system("mv "+code+".ogg "+os.getcwd()+"/"+filename)
 
os.remove(code+".flv")
 
sys.exit()

Youtube-dl no está desfasado, el .deb sí

Hoy no sé porque me ha dado por buscar el programa youtube-dl en su versión más reciente (en realidad debido a un email que he recibido, pero no me voy por las ramas), como ya dije hace tiempo la última versión que hay para Debian no funciona. Pues bien, el código sí que se ha seguido manteniendo por su creador, y la última versión data de Abril de 2008, me he bajado el archivo Python y para mi satisfacción, ¡esta vez sí funciona! :D Lo podréis encontrar en la siguiente dirección web: http://www.arrakis.es/%7Erggi3/youtube-dl/

Hace tiempo colgué un código que permitía "concatenar" yotube-dl con ffmpeg2theora para pasar vídeos de youtube.com al formato libre ogg. Lo que pasa es que lo colgué en una página a la que no se puede acceder no sé por que razón (al menos yo no puedo). Así que colgaré aquí el código (es una adaptación a Python con algun pequeño añadido de un script hecho por un compañero mío, inicialmente en Bash). Por cierto, el código es mejorable, se podrían añadir líneas que permitieran pasar opciones a youtube-dl o a ffmpeg2theora para hacer el script más versatil. Éste es el código:

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
#!/usr/bin/python
# -*- coding: utf-8 -*-
 
########################################################
# Basat en la documentació original de:                #
#  http://es.blogxpopuli.org/index.php/YouTube2Theora  #
########################################################
 
############################################################################
#   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 sys
 
argc = len(sys.argv)  #Guardo el nombre d'arguments en una variable
DIR  = os.getcwd()    #Guardo en una variable la ruta del directori actual
 
# Comprova que el programa tingui entre 1 i 2 arguments afegits
if argc != 2 and argc != 3:
	print "\nUsage:\v"+sys.argv[0]+" video_code result_file\n"
	sys.exit()
 
# Retoca els noms per simplificar el codi posterior
if   argc == 2:
	sys.argv.append(sys.argv[1]+".ogg")
elif argc == 3:
	if sys.argv[2][-4:] != ".ogg":
		sys.argv[2] += ".ogg"
 
# Comprova si ja existeix el fitxer que s'ha de construir
if os.system("test -e "+sys.argv[2]) == 0:
	print "El fitxer "+sys.argv[2]+" ja existeix, prova amb un altre nom"
	sys.exit()
 
# Anem al directori temporal per treballar allà amb els fitxers descarregats
os.chdir("/tmp")
 
# Baixem i convertim a format ogg el video de youtube
os.system("youtube-dl http://www.youtube.com/v/"+sys.argv[1])
os.system("ffmpeg2theora "+sys.argv[1]+".flv")
 
# Traslladem el fitxer resultat al directori indicat amb el nom indicat
if sys.argv[2][0] == '/':
	os.system("mv "+sys.argv[1]+".ogg "+sys.argv[2])
else:
	os.system("mv "+sys.argv[1]+".ogg "+DIR+"/"+sys.argv[2])
 
#Esborrem els fitxers temporals
os.remove(sys.argv[1]+".flv")
 
sys.exit()