Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # GOEAR 2 Mp3 File
- # Developed by Mauro L. Alexandre at [email protected]
- 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 ----------------------------------------------------------")
- 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 [email protected]"
- 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)
Advertisement
Add Comment
Please, Sign In to add comment