Prototype to be able to export the audio from a Youtube video and make it available to my smartphone.
Use case : keeping video as offline podcasts I can listen in the metro when there's no cell network available.
Linux only.
Uses the excellent https://github.com/ytdl-org/youtube-dl
If enough people have an interest, I might wrap this in something less artisanal (still only on Linux though).
Create a new XDG url-handling protocol called flodl
.
Embed a javascript call to this protocol in a browser bookmark, which pass the YT video URL as parameter to the call.
The call open a custom script making use of youtube-dl project to download the sound and convert it to mp3.
The script finally exports the mp3 file to my synchronized dropbox folder.
Documentation of youtube dl FOSS project
A free non OSS project which gave me the idea for the use of XDG URL-handling protocols and from which I reused the bookmark calling javascript code idea
http://edoceo.com/howto/xfce-custom-uri-handler
Put the following content in a file in /usr/local/share/applications/flodl.desktop
(or ~/.local/share/applications/flodl.desktop
)
[Desktop Entry]
Name=Flo DL
Comment=Launch the mp3 dl script
Exec=/home/flo/bin/youtube-dl/to_mp3.sh %u
Type=Application
Categories=Network;FileTransfer;
StartupNotify=true
MimeType=x-scheme-handler/flodl;
In a terminal
xdg-mime default flodl.desktop x-scheme-handler/flodl
sudo update-desktop-database
In a terminal
sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o youtube-dl.sh
sudo chmod a+rx /usr/local/bin/youtube-dl
Put the following content in $HOME/bin/youtube-dl/to_mp3.sh and chmod +x
it
#!/bin/zsh
a="$(echo $1 | awk -F'://|&' '{print $2}')"
notify-send "downloading $a"
tmp_dir=out_$(date '+%s')
mkdir $tmp_dir
$HOME/bin/youtube-dl/youtube-dl.sh -f bestaudio $a -x --audio-format mp3 --audio-quality 128k -o "./$tmp_dir/%(uploader)s - %(title)s.%(ext)s"
cp -r ./$tmp_dir/* "$HOME/Dropbox/Audio YT/"
rm -rf ./$tmp_dir
notify-send "Done"
In your browser, create a new bookmark, and use
javascript:if(navigator.userAgent.indexOf('Safari')%20%3E=%200){s=getSelection();}else{s=document.selection?document.selection.createRange().text:document.getSelection();}document.location.replace('flodl://'+(location.href).replace(/https?:\/\//i,''));
in the address field.
(optional) In your browser you might have to associate the flodl links to calling the system app handling flodl links (being: the script described at step 4.). I didn't have to in my firefox browser but your mileage may vary.
Just hit the bookmark whenever playing a youtube video in the active tab, the audio will be downloaded, converted to mp3 and placed to the Dropbox synchronized folder