Python script to download currently playing youtube video/audio in firefox

344 views
Skip to first unread message

Dilawar Singh

unread,
Apr 22, 2014, 7:57:38 AM4/22/14
to wncc...@googlegroups.com
[This script](https://raw.githubusercontent.com/dilawar/Scripts/master/download_mp3_youtube.py)
searches for firefox tab which is playing youtube video and downloads it. It
also extract an mp3 version (audio only) from it (one can transfer mp3 to music
player etc.).

This script uses `youtube.dl` application. It can be downloaded using `apt-get`
on ubuntu and should be available via `pip` or `easy-install`. Also you need to
install `ffmpeg` to convert video file to mp3.

USAGE:

$ ./download_mp3_youtube.py

You should see something like the following:

I can download audio from: https://www.youtube.com/watch?v=L-9s4nTLSdA&list=FLI4baaRqmAzXBrRnDN0nGSQ&shuffle=0
[youtube:playlist] Downloading just video L-9s4nTLSdA because of --no-playlist
[youtube] Setting language
[youtube] L-9s4nTLSdA: Downloading webpage
[youtube] L-9s4nTLSdA: Downloading video info webpage
[youtube] L-9s4nTLSdA: Extracting video information
[youtube] L-9s4nTLSdA: Encrypted signatures detected.
[youtube] L-9s4nTLSdA: Downloading js player vflibLKsU
[download] Destination: /home/dilawar/Downloads/Madari - Clinton Cerejo feat Vishal Dadlani & Sonu Kakkar, Coke Studio @ MTV Season 2-L-9s4nTLSdA.mp4
[download] 100% of 138.91MiB in 04:14
[avconv] Destination: /home/dilawar/Downloads/Madari - Clinton Cerejo feat Vishal Dadlani & Sonu Kakkar, Coke Studio @ MTV Season 2-L-9s4nTLSdA.mp3

Default download directory is `~/Downloads`. It can be changed in the script.

Dilawar

Krishna Pillutla

unread,
Apr 22, 2014, 3:49:10 PM4/22/14
to wncc...@googlegroups.com
How can I get this to work with a mac?

-Krishna Pillutla


--
--
The website for the club is http://wncc-iitb.org/
To post to this group, send email to wncc...@googlegroups.com
--- You received this message because you are subscribed to the Google Groups "Web and Coding Club IIT Bombay" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wncc_iitb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dilawar Singh

unread,
Apr 23, 2014, 1:45:35 AM4/23/14
to wncc...@googlegroups.com
>How can I get this to work with a mac?

Changed default firefox directory variable for Mac. I am not sure if all version
of Mac has the same directory structure for firefox : ~/Library/Application
Support/Firefox.

The normal installation process should be.

- Install python (2.7 or 3.3) and python-pip
https://www.python.org/download/mac/
- Open terminal
- Say `pip --proxy <iitb_proxy> install youtube_dl` in terminal.
- Download the script, save it, make it executable (chmod +x script.py)
- Run the script when something is being played in firefox.

It works only with firefox. I'll change some paths variables in

If it works in terminal, then you can bind the script to some keyboard shortcut
(e.g. Alt + Ctrl + D ) later.

Let me know if it does not work. Just attach the terminal output along with
mail.

Dilawar

Saswat Padhi

unread,
Apr 23, 2014, 2:49:23 AM4/23/14
to Web and Coding Club IITB
I use DownloadHelper for Firefox and it has never disappointed me, yet.
It not only works for YouTube, but for most any website with video content.

Being able to extract mp3 stream directly is one advantage I can see with this script.
But again, an extension (I use Youtube MP3 Podcaster) is probably more convenient than a script, when you're in a browser.

Also, may be you could allow users to pass parameters to youtube-dl. For example, one might like to tweak the audio bitrate (–audio-quality 176).

Saswat Padhi  |
 Senior Undergraduate | B.Tech. CSE |  IIT Bombay




    Dilawar

Dilawar Singh

unread,
Apr 23, 2014, 3:13:23 AM4/23/14
to wncc...@googlegroups.com
The purpose of scripts - for me - to avoid mouse clicks as much as possible.
Updated the script now: any argument to this script are send to youtube-dl.
Created a separate gist for this script (https://gist.github.com/dilawar/11205336)

I bind it to keyboard shortcut and whenever something nice is playing on
youtube, I don't have to go to firefox and use mouse. Few keystrokes and it gets
downloaded and converted into mp3 which my audio-player supports. Another
scripts sync all mp3 in Downloads directory with the player at the end of the
day. I don't have to worry about downloading and transferring.

Downloading audio from currently playing video (not necessarily on youtube)
would be a next enhancement. I could not figure out how to get the link of
currently playing flash by reading the sessions file from firefox?

Dilawar
Reply all
Reply to author
Forward
0 new messages