Last active
November 30, 2017 16:27
-
-
Save sanjaymhj/956df18761eaef95eda1ac56c5192f9b to your computer and use it in GitHub Desktop.
Download the mp3 of the youtube video
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
import urllib2 | |
import urlparse | |
import re | |
import string | |
import sys | |
import wget | |
import os | |
result = {"videoID": "", "name": ""} | |
videoURL = "" | |
if len(sys.argv) > 1: | |
videoURL = sys.argv[1] | |
print sys.argv[1] | |
possibleGarbageWord = ["\(Official Video\)", "\[Official Audio\]", | |
"\(Lyric\)", "\(Official Music Video\)"] | |
print "*** Getting the HTML ***" | |
content = urllib2.urlopen(videoURL).read() | |
videoID = urlparse.parse_qs(urlparse.urlparse(videoURL).query)['v'][0] | |
result['videoID'] = videoID | |
soup = BeautifulSoup(content, 'html.parser') | |
title = soup.findAll('span', id='eow-title')[0].string | |
print "*** Finding possible garbage text ***" | |
for gb in possibleGarbageWord: | |
title = re.sub(gb, '', title).strip() | |
result['name'] = title | |
print "\n\nDownloading: " + result['name'] | |
downloadURL = "http://youtubeconverter.me/download/%s/%s?quality=128" % ( | |
result['videoID'], 'a') | |
print "*** Initiating File Download ***" | |
file_name = wget.download(downloadURL) | |
# print "*** Initiating File Download ***" | |
# Renaming | |
src = './a[YoutubeConverter.me].mp3' | |
dest = './%s.mp3' % (result['name']) | |
os.rename(src, dest) | |
print "ENJOY!!! MP3 downloaded" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment