dan_ce wrote: ↑Wed Oct 17, 2018 1:24 pm
Can anyone advise - I'm basically looking to use youtube-dl to download BBC Radio 4 PM every day, then stream that downloaded file using the AirPlay protocol to my old school Airport Express plugged into the back of my AudioEngine A5s. Is forked-daapd the missing link that will allow me to do this? Thanks!!
Yes, it is. I'm doing exactly this (with a daily german radio show). You don't even have to use youtube-dl and also not have to wait until the episode is available online. Just record it live by using ffmpeg and a cron job. Copy the final mp3 file to your forked-daapd library afterwards.
So here is the ffmpeg command to record a radio stream, including metadata and cover:
Code: Select all
ffmpeg -i http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4fm_mf_p -i https://pbs.twimg.com/profile_images/842774198753918976/XyZcU3lM.jpg -c:a copy -c:v copy -map 0:0 -map 1:0 -id3v2_version 3 -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" -t 00:00:30 -metadata title="PM - `date +'(%a) %d-%m-%Y'`" -metadata artist="BBC Radio 4 PM" /home/pi/temp/bbc4_pm_`date +"%d-%m-%Y"`.mp3
As always with ffmpeg commands it looks complicated at first sight but it isn't that bad.
The first "-i" (input) parameter is the url of the online radio stream, in this case BBC Radio 4.
The second input is the url of a jpg for the cover in the resulting mp3 file. "-c:a copy -c:v copy" tells ffmpeg to just copy both inputs (audio and video) as they are without doing any transcoding or conversion. Afterwards the id3 tags (metadata) are defined. I'm using the date of the current day so both the title and file name look like "PM - (MO) 26-08-2019" or "bbc4_pm_26-08-2019.mp3". An important parameter is "-t 00:00:30" which tells ffmpeg to record for 30 seconds in this case and then it stops automatically. This is just for testing, you have to extend it to 1 hour (in case of BBC Radio 4 PM) or whatever fits your needs.
I'm using a shell script to run this command and this shell script is triggered by cron.
Code: Select all
crontab -l
0 17 * * 1-5 /bin/bash /home/pi/scripts/ffmpeg.sh &>/dev/null &
The cronjob is triggered from monday to friday (1-5) at 5pm (17:00). There is another cronjob which runs one hour later and moves the recorded mp3 file somewhere in my forked-daapd library. I'm doing this in two steps so that the library scanner of forked-daapd won't get triggered all the time during recording.
As soon as you come home you can then use the forked-daapd
JSON api to search for the new item in your library and then play it on your desired output. I'm using a Siri shortcut for that. Of course you could just use the web gui as well. Or the command line for maximum nerdyness.
Code: Select all
track="$(curl -X GET "http://forked-daapd.local:3689/api/search?type=tracks&expression=media_kind+is+music+order+by+time_added+desc&offset=0&limit=1" | jq -r '."tracks"["items"][0].uri')"
curl -X PUT "http://forked-daapd.local:3689/api/player/stop"
curl -X PUT "http://forked-daapd.local:3689/api/queue/clear"
curl -X POST "http://forked-daapd.local:3689/api/queue/items/add?uris=${track}"
curl -X PUT "http://forked-daapd.local:3689/api/outputs/set" --data "{"outputs":["101889459182266"]}"
curl -X PUT "http://forked-daapd.local:3689/api/player/play"
Cheers,
Marco