Test Foro de elhacker.net SMF 2.1

Programación => Scripting => Mensaje iniciado por: Kasswed en 19 Agosto 2008, 19:54 PM

Título: [Python] Script que descarga un MP3 de GOEAR
Publicado por: Kasswed en 19 Agosto 2008, 19:54 PM
Modo de uso:

python script.py <url1> <url2> <url3> ...

Ejemplo:

python script.py http://goear.com/listen.php?v=e470c04

En principio lo he hecho para Linux, no sé si en Windows se podrá usar, supongo que instalando wget (que no sé si lo trae por defecto) debería ir sin problemas.


Código (python) [Seleccionar]

#!/usr/bin/env python

import os
import sys
import string
import commands

Debug = 0
i=1

while i < (len(sys.argv)):

print i

print sys.argv[i]

print "\n\n\n"

try:
http = sys.argv[i]
except:
http = raw_input("Put the original http:")

xmlfile = string.replace(http, "listen.php?v=", "files/sst/secm")
xmlfile = xmlfile + ".xml"

command = "wget " + xmlfile + " -O file.xml"

result = commands.getstatusoutput(command)

if Debug > 1:
print result

f = open("file.xml","U")
fichero = f.read()
ini = string.find(fichero,"http://")
fin = string.find(fichero,"mp3") + 3
url = fichero[ini:fin]


artistIni = string.find(fichero,"artist=\"") + 8
artistFin = string.find(fichero,"title=") - 2

artist = fichero[artistIni:artistFin]

titleIni = string.find(fichero,"title=\"") + 7
titleFin = string.find(fichero,"\"/>") - 1

title = fichero[titleIni:titleFin]


command = "wget " + url + " -O \"" + artist + " - " + title + ".mp3\""

os.system(command)

try:
os.system("rm file.xml")
except:
os.system("del file.xml")

f.close()
i = i+1