Share Pastebin
Guest
Public paste!

Mauro L Alexandre

By: a guest | Mar 21st, 2009 | Syntax: Python | Size: 2.26 KB | Hits: 165 | Expires: Never
Copy text to clipboard
  1. #!/usr/bin/env python
  2.  
  3. # GOEAR 2 Mp3 File
  4. # Developed by Mauro L. Alexandre at upmauro@gmail.com
  5.  
  6. import urllib
  7. import urllib2
  8. import re
  9. import sys
  10. import os
  11.        
  12. class Music :
  13.        
  14.         def __init__(self,server,url,title,album,artist):
  15.                 self.server = server
  16.                 self.url = url
  17.                 self.title = title
  18.                 self.album = album
  19.                 self.artist = artist
  20.  
  21. def download(music):
  22.         sys.stdout.write("\n  ----------------------------------------------------------")
  23.         sys.stdout.write("\n    Starting MP3 download ... ")
  24.         sys.stdout.write("\n    MP3 : " + music.title + " - " + music.artist + " - " + music.album)
  25.         sys.stdout.write("\n    Server : " + music.server)
  26.         sys.stdout.write("\n  ----------------------------------------------------------")
  27.         sys.stdout.write("\n    Developed by Mauro L. Alexandre at upmauro@gmail.com")
  28.         sys.stdout.write("\n  ----------------------------------------------------------")
  29.         sys.stdout.write("\n")
  30.         urllib.urlretrieve(music.url, music.title + '.mp3', reporthook=download_progress)
  31.         sys.stdout.write("\n  Done :P Thanks ! [ Output file = " + current_path +"/"+  music.title + '.mp3 ] \n \n' )
  32.  
  33.  
  34. def download_progress(count, blockSize, totalSize):
  35.         percent = int(count*blockSize*100/totalSize)
  36.         verbose = ""
  37.         if percent > 1:
  38.                 progress = percent / 2
  39.                 for x in range(0,progress):
  40.                         verbose = verbose + "#"
  41.  
  42.         sys.stdout.write(str(" \r  [ " +  verbose + " ] " + str(percent) + "%"))
  43.         sys.stdout.flush()
  44.                
  45.  
  46. def goear_getURL(id_song):
  47.         url = ('http://www.goear.com/files/xmlfiles/' + id_song[0:1] + '/secm' + id_song + '.xml')
  48.         xml = urllib2.urlopen(url).read()
  49.         song = Music('goear',re.findall('http://.+\.mp3',xml)[0],re.findall(r'title="(.+)"',xml)[0],'album','artist')
  50.         download(song)
  51.  
  52. def invalid_args():
  53.         print " \n  Goear2Mp3 - Developed by Mauro L. Alexandre at upmauro@gmail.com"
  54.         print "  Invalid arguments usage !"
  55.         print "  Usage example : [ goear2mp3 http://www.goear.com/listen/2837738/Unanswered-Suicide-Silence ] \n "
  56.  
  57.        
  58. if len(sys.argv) < 2 :
  59.         invalid_args()
  60. else:
  61.         global current_path
  62.         current_path = str(os.getcwd())
  63.         url = sys.argv[1]
  64.         if (url.find('listen') == -1) or (url.find('http') == -1):
  65.                 invalid_args()
  66.                 sys.exit()
  67.  
  68.         id = url[url.find("/listen")+8:]
  69.         id = id[:id.find("/")]
  70.         goear_getURL(id)