Download mp3 from a website automatically using Python
Today I have some other simple and useful script. Couple of days back my brother asked me to download Christian songs. And I went to Google for help and got a link which has the Christian songs in form of YouTube videos. Yeah cool. But I need those as mp3 format. I just thought to use Python for this task since I am so lazy to sit for copy paste and download using fastest YouTube video download plug-in.
So, what I finally did was the below script in Python.
from BeautifulSoup import BeautifulSoup as bs
url = "http://www.yourlivingmanna.com/tamil_songs.asp"
resp = requests.get(url)
soup = bs(resp.text)
links = soup.findAll('a')
video_links = 
for l in links:
if "&video=" in l['href']:
ln = l['href']
for v in video_links:
os.system("youtube-dl -x --audio-format mp3 --prefer-ffmpeg "+v)
What it will do? Script will fetch the response of the website and find all the href links in the website and at the same time the href value should have “&video=”. That’s just a embedded video link. After collecting all the links I just stripped off all the chunk in the url and got only YouTube links. I have installed youtube-dl which has the ability to download and convert the YouTube videos into mp3. Just triggered the os.system() method with the youtube-dl command to get my job done. That’s it. Python made my job easy..
See you in the next post with some other script… Take care folks…