def song_download():
song = user_input('Enter the name of song: ')
try:
query_string = encode({"search_query" : song})
content = urlopen("http://www.youtube.com/results?" + query_string)
if version == 3:
##I hate RE
search_results = re.findall(r'href=\"\/watch\?v=(.{11})', content.read().decode())
else:
##ok!! if its not going work! I'm gonna kill you!!!
search_results = re.findall(r'href=\"\/watch\?v=(.{11})', content.read())
##finally(Thanks to git)
except:
print('Something happened!!')
exit(1)
# youtube2mp3 API
downloadLinkOnly = 'http://www.youtubeinmp3.com/fetch/?video=' + 'http://www.youtube.com/watch?v=' + search_results[0]
try:
print('Downloading %s' % song)
urllib.urlretrieve(downloadLinkOnly, filename='%s.mp3' % song)
urllib.urlcleanup()
except:
print('Error %s' % song)
exit(1)
评论列表
文章目录