Skip to content

Instantly share code, notes, and snippets.

@RK11
Created January 23, 2013 11:40
Show Gist options
  • Save RK11/4604638 to your computer and use it in GitHub Desktop.
Save RK11/4604638 to your computer and use it in GitHub Desktop.
A simple python program to download in a simple way a mp3 on mp3skull.com. Features : Search, result list, download
import urllib2, urllib
number_of_result = 20
def get_page(query):
page_source = urllib2.urlopen("http://mp3skull.com/mp3/{}.html".format(query.replace(" ","_"))).read()
return page_source
def get_link(page_source, n):
# "n" is the position in the list in the results
result_start = '<div id="song_html" class="show{}">'
pos1 = page_source.find(result_start.format(n)) #The position at which the source code starts for a specific n result
link_indicator = '<a href='
link_start = page_source.find(link_indicator, pos1)+len(link_indicator)+1
link_end = page_source.find('"', link_start)
link = page_source[link_start:link_end]
return link
def get_results(page_source):
n = 1
result = []
while n < number_of_result:
pos1 = page_source.find('<div id="song_html" class="show{}">'.format(n))
if pos1 == -1:
break
title_start = page_source.find("<b>", pos1)+3
title_end = page_source.find("</b", title_start)
title = page_source[title_start:title_end]
result.append(title)
n += 1
return result
def get_size(link):
try:
return int(urllib.urlopen(link).headers.get("Content-Length"))
except:
return 0
def download(link, filename = ""):
if filename == "":
filename = link.split("/")[-1]
print "File size: {} MB (0 means unknown)".format(str(get_size(link)/10.0**6)[:5])
print "Downloading..."
try:
urllib.urlretrieve(link, filename)
except:
print "404: Couldn't download file"
print "Done!"
def download_using_wget(link): # Use instead if you have wget
from os import system
system('wget -c "{}"'.format(link))
def main():
print "MP3skull downloader\nMade by RK11\n"
query = raw_input("Query: ")
page = get_page(query)
n = 1
results = get_results(page)
for title in results:
print "{}.{}".format(n, title)
n += 1
n = input("Which track do you want to download ? ")
download(get_link(page, n)) # You can replace by download_with_wget()
print "\nThank you for using this program !\n"
main()
@aguywithnojob
Copy link

Please update this code as per new python version and url isn't available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment