One drawback with playing the youtube songs as a stream is that the title field in RuneAudio becomes a very long garbled string. Here is a workaround that first downloads the file and uses the name from youtube for the title field.
This also shows how to use plink to run the commands from a Windows computer on the same LAN as the Rune device.
The complete command- Code: Select all
plink -ssh [put local ip to rune box] -l root -pw rune "youtube-dl --no-mtime --restrict-filenames -o '/mnt/MPD/youtube/%(title)s.%(ext)s' -f141 https://www.youtube.com/watch?v=qORYO0atB6g && mpc update --wait youtube ; mpc add youtube/$(ls /mnt/MPD/youtube/ -t | head -n1)"
Prerequisites:
1 Download the command line SSH tool
Plink and open a cmd prompt in its folder.
2 A folder named /mnt/MPD/youtube must be created on the Rune device
- Code: Select all
mkdir /mnt/MPD/youtube
3 Install youtube-dl if you haven't already
- Code: Select all
pacman -Sy
pacman -S youtube-dl
I will now explain the command step by step
- Code: Select all
plink -ssh [local ip to rune box] -l root -pw rune
This connects to the rune box using the
default root credentials. Modify the ip and the pw (if your have changed it).
The rest, everything within the quote marks, is a chain of commands that will be run on the Rune device.
- Code: Select all
youtube-dl --no-mtime --restrict-filenames -o '/mnt/MPD/youtube/%(title)s.%(ext)s' -f141 https://www.youtube.com/watch?v=qORYO0atB6g
Download the youtube URL, as audio ( -f141), to the folder /mnt/MPD/youtube/ with the name [youtube title].[fileextension, usually .m4a] , with only characters A-z 0-9 _- in the filename ( --restrict-filenames ) and set the time modified of the downloaded file to now ( --no-mtime ; needed for the last step below).
- Code: Select all
&&
Run the following commands in the chain only if the first was successful
- Code: Select all
mpc update --wait youtube
Update the MPD database, but only scan the youtube folder (for quicker update( and wait for the update to finish. This makes it possible to find and play the new file in Rune.
- Code: Select all
;
Marks that a new command starts
- Code: Select all
mpc add youtube/
Tells MPC to add a file in the MPD database folder youtube to the playlist. Note that youtube is at "root" in the MPD database so should have no file system path prefix here.
- Code: Select all
$(ls /mnt/MPD/youtube/ -t | head -n1)
The $( ) bit means that the code within the parenthesis will specify the name of the file.
the ls command lists files in the folder youtube based on their "time modified" values. The head -n1 part reverts the list and picks the first one, that is the most recently modified file, i.e. the one we just downloaded. Note that the list command works with the filesystem so here the path to the youtube folder is needed.
If everything works it should take about 10 seconds until the file starts playing. I don't notice any difference in speed when playing the same URL as a stream. Can anyone see a way to speed up the process?
Ways this could be improved:
Add a command that uses some linux command line audio tagging tool to add proper artist and title tags and also download the youtube video placeholder image and use as cover image in Rune playback.
Add a command that clears all files in the youtube folder that are X days old.
Make a script on Windows that takes the youtube URL as input and runs the whole plink command in the background.
Some youtube URLs don't have -f141 audio. Add a fallback command that uses -f140.
Anything that speeds up the process.
Feel free to chip in with enhancements!
Edit:
this post on the volumio forums is relevant. Something like those php steps looks doable for Rune too. Once we can do something like
- Code: Select all
http://192.168.1.6/youtube.php?yurl=https://www.youtube.com/watch?v=qORYO0atB6g
the bookmarklet approach vikomarn suggested would work.
Edit: youtube-dl is slow to start on a Raspi . This is a possible workaround from the
raspi forums.