[Python] MP3 Downloader 0.1

Iniciado por BigBear, Noviembre 28, 2012, 12:09:15 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Noviembre 28, 2012, 12:09:15 PM Ultima modificación: Noviembre 28, 2012, 02:48:56 PM por Doddy
Traduccion a Python de este simple script para buscar y bajar musica.

El codigo

Código: python

#!usr/bin/python
#MP3 Downloader 0.1
#Coded By Doddy H

import sys,urllib,urllib2,re,os,urlparse

def toma(web) :
nave = urllib2.Request(web)
nave.add_header('User-Agent','Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5');
op = urllib2.build_opener()
return op.open(nave).read()

def clean():
if sys.platform=="win32":
  os.system("cls")
else:
  os.system("clear")

def head():
print """

@     @  @@@@@   @@@     @@@@     @@@@  @         @ @    @
@     @  @    @ @   @    @   @   @    @ @         @ @@   @
@@   @@  @    @     @    @    @  @    @  @   @   @  @@   @
@@   @@  @    @     @    @    @  @    @  @   @   @  @ @  @
@ @ @ @  @@@@@    @@     @    @  @    @  @   @   @  @ @  @
@ @ @ @  @          @    @    @  @    @   @ @ @ @   @  @ @
@  @  @  @          @    @    @  @    @   @ @ @ @   @   @@
@  @  @  @      @   @    @   @   @    @    @   @    @   @@
@     @  @       @@@     @@@@     @@@@     @   @    @    @



                                         
                              Coded By Doddy H

                                       
"""

def copyright():
print "\n\n(C) Doddy Hackman 2012\n"
raw_input()
sys.exit(1)

def proxar(a,b,c):
sys.stdout.write("\r[+] Status : %s / %s" % (a * b,c))
 
def down(file,filesave):
print "\n[+] File to download : "+filesave+"\n"
try:
  urllib.urlretrieve(file,filesave,reporthook=proxar)
except:
  print "\n[-] Error\n"
  copyright()
print "\n\n[+] File Download in "+os.curdir+"/"+filesave

def buscar(titulo) :

songs = []
datas =[]
links = []
datas_back = []
links_back = []

titulo = re.sub(" ","_",titulo)

print "\n\n[+] Searching ...\n"

code = toma("http://mp3skull.com/mp3/"+titulo+".html")

if not (re.findall("Sorry, no results found for",code)):

  songs = re.findall("<div style=\"font-size:15px;\"><b>(.*)<\/b><\/div>",code)
  datas_back = re.findall("<!-- info mp3 here -->\s+(.*?)<\/div>",code)
  links_back = re.findall("<a href=\"(.*)\.mp3\"",code)

  for datac in datas_back :
   datac = re.sub("<br />"," ",datac)
   datas.append(datac)

  for li in links_back :
   lic = li+".mp3"
   links.append(lic)

  try:
   for counter in range(0,len(songs)):
    print "\n[Song "+str(counter)+"] : "+songs[counter]
    print "[Data] : "+datas[counter]
    print "[Link] : "+links[counter]

  except:
   pass

  while 1:

   print "\n[+] Options\n"
   print "[+] 1 - Download"
   print "[+] 2 - Search"
   print "[+] 3 - Exit\n"

   op = raw_input("[+] Option : ")

   if op  == "3":
    print "\n\n[+] Finished\n"
    copyright() 

   if op == "2":
    party()

   if op == "1":
    num = input("\n[?] Number :")
    down(links[num],os.path.basename(links[num]))

else:
  print "\n[-] Not Found\n";
  raw_input()
  party()

def party():

clean()
head()

bs = raw_input("\n\n[?] Song : ")

buscar(bs)

##

if not os.path.isdir("mp3_downloads"):
os.makedirs("mp3_downloads")

os.chdir("mp3_downloads")

party()

##

#The End ?