Página 1 de 1

[Python] SharkTube: ¡Descarga vídeos de YouTube!

Publicado: 23 Abr 2011, 07:24
por WindHack
Imagen


SharkTube es una utilidad o aplicación gratuita que te permite descargar vídeos de YouTube.
NOTA: Esta utilidad se encuentra registrada en [Enlace externo eliminado para invitados] bajo la licencia [Enlace externo eliminado para invitados].
Sus características y mejoras son:
  • Más servidores de YouTube.
  • Disponibilidad de formatos FLV, MP4, entre otros. *
  • Ejecutable por línea de comandos y alternativa con Interfaz web.
  • Mejor rendimiento en la búsqueda de servidores.
  • Extracción de título, descripción y enlace corto.
  • Posibilidad de compartir el vídeo en servicios sociales.
Shark.py

Código: Seleccionar todo

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#   Written by SebastiᮠCastaᯠ(.:WindHack:.)
#             DaW - Labs & Cibernodo
#   - www.daw-labs.com | | www.cibernodo.net  -
#           Version: 1.1 ( Renaissance )
#              Interactive Console
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 
import urllib
import re
 
bLogo = '''
 .--. .-.               .-.   .-----.    .-.
: .--': :               : :.-.`-. .-'    : :
`. `. : `-.  .--.  .--. : `'.'  : :.-..-.: `-.  .--.
 _`, :: .. :' .; ; : ..': . `.  : :: :; :' .; :' '_.'
`.__.':_;:_;`.__,_;:_;  :_;:_;  :_;`.__.'`.__.'`.__.'
 (C) DaW - Labs & Cibernodo.
 
 Welcome!
 NOTE: Enter -e or --end to exit the application.
        '''
 
Char = ['%3A','%2F','%26','%2C','%3D','%252C','%253A','%7C','%3F']
By =   [':','/','&',',','=',',',':','<begin>','?']
 
 
def URLDecode(sURL):
    for i in range(len(Char)):
        sURL = sURL.replace(Char[i],By[i])
    return sURL
 
def CleanData(sData,IsHTML=True):
    if IsHTML == True:
        rReg = re.compile(r'\&.*?;')
    else:
        rReg = re.compile(r',[0-9].?')
    return rReg.sub('',sData)
 
def GetSourceCode(sURL):
    try:
        URL = urllib.urlopen(sURL)
        sSource = URL.read()
        URL.close()
        return sSource
    except:
        print '[+] Connection error.'
        exit()
 
def GetIndexVideo(sSource,Tags):
    return sSource.find(Tags)
 
def GetVideoInformation(sSource):
    sSource = sSource[2000:4500]
    sInfo = []
    #Title...
    sReg = re.findall(r'<meta property="og:title" content="(.+)">',sSource)
    sInfo.append(sReg[0])
    #Shortlink...
    sReg = re.findall(r'<link rel="shortlink" href="(.+)">',sSource)
    sInfo.append(sReg[0])
    #Description...
    sReg = re.findall(r'<meta property="og:description" content="(.+)">',sSource)
    sInfo.append(CleanData(sReg[0]))
    return sInfo
 
def GetDownloadURL(sSource,sTitle):
    sSource = sSource[10000:18000]
    Begin = GetIndexVideo(sSource,'width="640" id="movie_player" height="390"    flashvars=')+57
    sSource = sSource[Begin:]
    End = GetIndexVideo(sSource,'allowscriptaccess="always" allowfullscreen="true"')+49
    sSource = sSource[:End].split('<begin>')
    lClean = []
    sTitle = '&title='+sTitle.replace(' ','%20')+'%20[SharkTube]'
    for i in sSource:
        if i.startswith('http://v') and len(i) < 400:
            lClean.append(CleanData(i,IsHTML=False)+sTitle)
    return lClean
 
def __main__():
    print bLogo
    while 1:
        Id = raw_input('Please, enter the YouTube Id. >> ')
        if Id == '-e' or Id == '--end':
            print 'Thank you for using SharkTube. Goodbye'
            exit(1)
        else:
            if len(Id) == 11:
                try:
                    Source = URLDecode(GetSourceCode('http://www.youtube.com/watch?v='+Id))
                    lInfo = GetVideoInformation(Source)
                    URL = GetDownloadURL(Source,lInfo[0])
                    print '''
 
            -*- Video Information -*-
 
Title: %s
Shortlink: %s
Description:
%s
 
Link(s) available(s) to download:
%s
 
          ''' % (lInfo[0],lInfo[1],lInfo[2],'\n\n'.join(URL))
                except IndexError:
                    print 'Wrong Id. Please, try again...'
            else:
                print 'The ID must be eleven characters. Try again...'
 
if __name__ == "__main__":
   __main__()
Captura
[Enlace externo eliminado para invitados]

Para usar la versión de Interface Web ( Captura superior ) se debe de descargar el proyecto con todo lo necesario del siguiente enlace: [Enlace externo eliminado para invitados]

Más información:
- [Enlace externo eliminado para invitados]
- [Enlace externo eliminado para invitados]

Eso es todo, espero les sea de ayuda y le puedan sacar provecho.
Por último, agradecimiento especial a 5475UK1 por la ayuda en el diseño y creación del logo.




Saludos.,