Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: BigBear en 28 Noviembre 2012, 16:09 pm



Título: [Python] MP3 Downloader 0.1
Publicado por: BigBear en 28 Noviembre 2012, 16:09 pm
Traduccion a Python de este simple script para buscar y bajar musica.

El codigo

Código
  1. #!usr/bin/python
  2. #MP3 Downloader 0.1
  3. #Coded By Doddy H
  4.  
  5. import sys,urllib,urllib2,re,os,urlparse
  6.  
  7. def toma(web) :
  8. nave = urllib2.Request(web)
  9. 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');
  10. op = urllib2.build_opener()
  11. return op.open(nave).read()
  12.  
  13. def clean():
  14. if sys.platform=="win32":
  15.  os.system("cls")
  16. else:
  17.  os.system("clear")
  18.  
  19. def head():
  20. print """
  21.  
  22. @     @  @@@@@   @@@     @@@@     @@@@  @         @ @    @
  23. @     @  @    @ @   @    @   @   @    @ @         @ @@   @
  24. @@   @@  @    @     @    @    @  @    @  @   @   @  @@   @
  25. @@   @@  @    @     @    @    @  @    @  @   @   @  @ @  @
  26. @ @ @ @  @@@@@    @@     @    @  @    @  @   @   @  @ @  @
  27. @ @ @ @  @          @    @    @  @    @   @ @ @ @   @  @ @
  28. @  @  @  @          @    @    @  @    @   @ @ @ @   @   @@
  29. @  @  @  @      @   @    @   @   @    @    @   @    @   @@
  30. @     @  @       @@@     @@@@     @@@@     @   @    @    @
  31.  
  32.  
  33.  
  34.  
  35.                              Coded By Doddy H
  36.  
  37.  
  38. """
  39.  
  40. def copyright():
  41. print "\n\n(C) Doddy Hackman 2012\n"
  42. raw_input()
  43. sys.exit(1)
  44.  
  45. def proxar(a,b,c):
  46. sys.stdout.write("\r[+] Status : %s / %s" % (a * b,c))
  47.  
  48. def down(file,filesave):
  49. print "\n[+] File to download : "+filesave+"\n"
  50. try:
  51.  urllib.urlretrieve(file,filesave,reporthook=proxar)
  52. except:
  53.  print "\n[-] Error\n"
  54.  copyright()
  55. print "\n\n[+] File Download in "+os.curdir+"/"+filesave
  56.  
  57. def buscar(titulo) :
  58.  
  59. songs = []
  60. datas =[]
  61. links = []
  62. datas_back = []
  63. links_back = []
  64.  
  65. titulo = re.sub(" ","_",titulo)
  66.  
  67. print "\n\n[+] Searching ...\n"
  68.  
  69. code = toma("http://mp3skull.com/mp3/"+titulo+".html")
  70.  
  71. if not (re.findall("Sorry, no results found for",code)):
  72.  
  73.  songs = re.findall("<div style=\"font-size:15px;\"><b>(.*)<\/b><\/div>",code)
  74.  datas_back = re.findall("<!-- info mp3 here -->\s+(.*?)<\/div>",code)
  75.  links_back = re.findall("<a href=\"(.*)\.mp3\"",code)
  76.  
  77.  for datac in datas_back :
  78.   datac = re.sub("<br />"," ",datac)
  79.   datas.append(datac)
  80.  
  81.  for li in links_back :
  82.   lic = li+".mp3"
  83.   links.append(lic)
  84.  
  85.  try:
  86.   for counter in range(0,len(songs)):
  87.    print "\n[Song "+str(counter)+"] : "+songs[counter]
  88.    print "[Data] : "+datas[counter]
  89.    print "[Link] : "+links[counter]
  90.  
  91.  except:
  92.   pass
  93.  
  94.  while 1:
  95.  
  96.   print "\n[+] Options\n"
  97.   print "[+] 1 - Download"
  98.   print "[+] 2 - Search"
  99.   print "[+] 3 - Exit\n"
  100.  
  101.   op = raw_input("[+] Option : ")
  102.  
  103.   if op  == "3":
  104.    print "\n\n[+] Finished\n"
  105.    copyright()  
  106.  
  107.   if op == "2":
  108.    party()
  109.  
  110.   if op == "1":
  111.    num = input("\n[?] Number :")
  112.    down(links[num],os.path.basename(links[num]))
  113.  
  114. else:
  115.  print "\n[-] Not Found\n";
  116.  raw_input()
  117.  party()
  118.  
  119. def party():
  120.  
  121. clean()
  122. head()
  123.  
  124. bs = raw_input("\n\n[?] Song : ")
  125.  
  126. buscar(bs)
  127.  
  128. ##
  129.  
  130. if not os.path.isdir("mp3_downloads"):
  131. os.makedirs("mp3_downloads")
  132.  
  133. os.chdir("mp3_downloads")
  134.  
  135. party()
  136.  
  137. ##
  138.  
  139. #The End ?
  140.  


Título: Re: [Python] MP3 Downloader 0.1
Publicado por: peib0l en 30 Noviembre 2012, 13:24 pm
ey muy bueno, esta tarde lo pruebo, tiene muuchos fallos asi que me lo re-hago con tu idea XD


Título: Re: [Python] MP3 Downloader 0.1
Publicado por: flacc en 8 Diciembre 2012, 18:34 pm
interesante a ver si mas rato le hecho un ojo...saludos


Título: Re: [Python] MP3 Downloader 0.1
Publicado por: BigBear en 16 Diciembre 2012, 17:56 pm
ey muy bueno, esta tarde lo pruebo, tiene muuchos fallos asi que me lo re-hago con tu idea XD

comenta los errores o sugerencias para ver si hago la version 0.2


Título: Re: [Python] MP3 Downloader 0.1
Publicado por: flacc en 20 Diciembre 2012, 20:03 pm
hahaha funciona y todo... esta bueno, aun no veo los errores que mencionaron pero algún día le daré el ojo xD...saludos

edit: me parece que es por la consola de windows pero cuando salen muchos resultados no me los muestra todos cuando subo la scrollbar hacia arriba xD, cosa que ubuntu si deja :(