Mauro L Alexandre
By: a guest | Mar 21st, 2009 | Syntax:
Python | Size: 2.26 KB | Hits: 165 | Expires: Never
#!/usr/bin/env python
# GOEAR 2 Mp3 File
# Developed by Mauro L. Alexandre at upmauro@gmail.com
import urllib
import urllib2
import re
import sys
import os
class Music :
def __init__(self,server,url,title,album,artist):
self.server = server
self.url = url
self.title = title
self.album = album
self.artist = artist
def download(music):
sys.stdout.write("\n ----------------------------------------------------------")
sys.stdout.write("\n Starting MP3 download ... ")
sys.stdout.write("\n MP3 : " + music.title + " - " + music.artist + " - " + music.album)
sys.stdout.write("\n Server : " + music.server)
sys.stdout.write("\n ----------------------------------------------------------")
sys.stdout.write("\n Developed by Mauro L. Alexandre at upmauro@gmail.com")
sys.stdout.write("\n ----------------------------------------------------------")
sys.stdout.write("\n")
urllib.urlretrieve(music.url, music.title + '.mp3', reporthook=download_progress)
sys.stdout.write("\n Done :P Thanks ! [ Output file = " + current_path +"/"+ music.title + '.mp3 ] \n \n' )
def download_progress(count, blockSize, totalSize):
percent = int(count*blockSize*100/totalSize)
verbose = ""
if percent > 1:
progress = percent / 2
for x in range(0,progress):
verbose = verbose + "#"
sys.stdout.write(str(" \r [ " + verbose + " ] " + str(percent) + "%"))
sys.stdout.flush()
def goear_getURL(id_song):
url = ('http://www.goear.com/files/xmlfiles/' + id_song[0:1] + '/secm' + id_song + '.xml')
xml = urllib2.urlopen(url).read()
song = Music('goear',re.findall('http://.+\.mp3',xml)[0],re.findall(r'title="(.+)"',xml)[0],'album','artist')
download(song)
def invalid_args():
print " \n Goear2Mp3 - Developed by Mauro L. Alexandre at upmauro@gmail.com"
print " Invalid arguments usage !"
print " Usage example : [ goear2mp3 http://www.goear.com/listen/2837738/Unanswered-Suicide-Silence ] \n "
if len(sys.argv) < 2 :
invalid_args()
else:
global current_path
current_path = str(os.getcwd())
url = sys.argv[1]
if (url.find('listen') == -1) or (url.find('http') == -1):
invalid_args()
sys.exit()
id = url[url.find("/listen")+8:]
id = id[:id.find("/")]
goear_getURL(id)