{"id":1387,"date":"2014-04-28T10:00:15","date_gmt":"2014-04-28T15:00:15","guid":{"rendered":"https:\/\/www.foell.org\/justin\/?p=1387"},"modified":"2019-10-21T11:51:52","modified_gmt":"2019-10-21T16:51:52","slug":"record-streaming-radio-program","status":"publish","type":"post","link":"https:\/\/www.foell.org\/justin\/record-streaming-radio-program\/","title":{"rendered":"Record a streaming radio program"},"content":{"rendered":"<p>With the Minnesota Orchestra <a title=\"Orchestra labor dispute over\" href=\"http:\/\/www.mprnews.org\/story\/2014\/01\/14\/minnesota-orchestra-settlement\" target=\"_blank\" rel=\"noopener noreferrer\">back in business<\/a> (and now with their <a title=\"Osmo Vanska back\" href=\"http:\/\/minnesota.publicradio.org\/display\/web\/2014\/04\/24\/osmo-vanska-back-as-minnesota-orchestra-music-director\" target=\"_blank\" rel=\"noopener noreferrer\">music director re-hired<\/a>), Jessi and I purchased a subscription package of concerts to attend. With the orchestra <a title=\"2014 Season Brochure\" href=\"http:\/\/www.minnesotaorchestra.org\/images\/subscriptions\/pdf\/1314_brochure.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">pulling out all the stops on their repertoire<\/a>, we wanted to attend almost all of the concerts. But that was unrealistic.<\/p>\n<p>So when we couldn&#8217;t attend\u00a0concerts that we wanted to hear, we could listen to them on the radio. And if we couldn&#8217;t listen in, there is the radio stream, which I could capture.<\/p>\n<p>Radio stations have for the most part made streaming easy. Some have made attempts to secure their streams from easily being captured by using proprietary protocols like <a title=\"Real Time Messaging Protocol\" href=\"http:\/\/en.wikipedia.org\/wiki\/Real_Time_Messaging_Protocol\" target=\"_blank\" rel=\"noopener noreferrer\">RTMP<\/a>. But it remains that a stream is still a stream, and it can always be saved. It may just take a greater or lesser degree of difficulty.<\/p>\n<p><!--more--><\/p>\n<p>Luckily, many stations opt for the tried-and-true streaming MP3 delivery method that every device can support without special hardware or software. My local classical affiliate is no exception. I found the address to the stream in\u00a0<a title=\"apmplayer-all.min.js\" href=\"http:\/\/common.publicradio.org\/media_player\/1.4.0\/script\/apmplayer-all.min.js\" target=\"_blank\" rel=\"noopener noreferrer\">apmplayer-all.min.js<\/a> file (I used <a title=\"7 Chrome Tips\" href=\"http:\/\/www.elijahmanor.com\/7-chrome-tips-developers-designers-may-not-know\/\" target=\"_blank\" rel=\"noopener noreferrer\">Chrome to un-minify<\/a> it).<\/p>\n<p>Then I put together a script that would save the stream&#8230;<\/p>\n<p>First, I created a script, and saved it to\u00a0<code>\/home\/justin\/bin\/record_orchestra.sh<\/code> on my system:<\/p>\n<pre>#!\/bin\/sh\r\n\r\nDATE=`date +%Y%m%d`\r\nSTREAM='http:\/\/cms.stream.publicradio.org\/cms.mp3'\r\nDESTINATION=\"\/home\/justin\/Music\/mnorch_$DATE.mp3\"\r\nSTOP='22:30'\r\n\r\ncvlc --demux dump --demuxdump-file $DESTINATION $STREAM &amp;\r\nPID=$!\r\necho \"kill $PID\" | at $STOP<\/pre>\n<p>The script needs to be added to the\u00a0<a title=\"man 5 crontab\" href=\"http:\/\/man7.org\/linux\/man-pages\/man5\/crontab.5.html\" target=\"_blank\" rel=\"noopener noreferrer\">crontab<\/a> of my\u00a0unix system to kick it off\u00a0at 8PM on every Friday.<\/p>\n<pre>$ crontab -e\r\n# m h dom mon dow command\r\n0 20 * * fri \/home\/justin\/bin\/record_orchestra.sh<\/pre>\n<h2>Script, explained<\/h2>\n<p>A little explanation of what&#8217;s going on in the script:<\/p>\n<p>I&#8217;m using the <a title=\"man date\" href=\"http:\/\/man7.org\/linux\/man-pages\/man1\/date.1.html\" target=\"_blank\" rel=\"noopener noreferrer\">date command<\/a> to help me name the files. <code>mnorch_20140214.mp3<\/code> for example is Valentines Day &#8211; Elgar&#8217;s Cello Concerto and Holst&#8217;s Planets \ud83d\ude0e<\/p>\n<p>I&#8217;m using <a title=\"VideoLAN (VLC)\" href=\"http:\/\/www.videolan.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">VLC<\/a> to capture the stream. <code>cvlc<\/code> is just a wrapper that&#8217;s included with VLC. It runs in a &#8220;headless&#8221; mode where nothing displays &#8211; perfect for a <a title=\"cron daemon (Wikipedia)\" href=\"http:\/\/en.wikipedia.org\/wiki\/Cron\" target=\"_blank\" rel=\"noopener noreferrer\">cron job<\/a>. I&#8217;m telling it to <a title=\"Save mp3 stream without transcoding\" href=\"https:\/\/forum.videolan.org\/viewtopic.php?f=4&amp;t=63804#p213257\">do a raw dump of the incoming stream<\/a>\u00a0so the file doesn&#8217;t get transcoded, just saved exactly as it was streamed from the station. The ampersand (<code>&amp;<\/code>) at the end of the <code>cvlc<\/code>\u00a0command makes it run in the background.<\/p>\n<p>Using the <a title=\"PID of a background process\" href=\"http:\/\/stackoverflow.com\/questions\/1908610\/how-to-get-pid-of-background-process\" target=\"_blank\" rel=\"noopener noreferrer\"><code>$!<\/code> shell variable<\/a>, the script saves the process ID of VLC. Then using the <a title=\"at daemon (Wikipedia)\" href=\"http:\/\/en.wikipedia.org\/wiki\/At_(Unix)\" target=\"_blank\" rel=\"noopener noreferrer\"><code>at<\/code> daemon<\/a>, we tell it to stop VLC &#8220;at 10:30PM,&#8221; when the show is likely over.<\/p>\n<div class='kindleWidget kindleLight' ><img decoding=\"async\" src=\"https:\/\/www.foell.org\/justin\/wp-content\/plugins\/send-to-kindle\/media\/white-15.png\" \/><span>Send to Kindle<\/span><\/div>","protected":false},"excerpt":{"rendered":"<p>With the Minnesota Orchestra back in business (and now with their music director re-hired), Jessi and I purchased a subscription package of concerts to attend. With the orchestra pulling out all the stops on their repertoire, we wanted to attend almost all of the concerts. But that was unrealistic. So when we couldn&#8217;t attend\u00a0concerts that&hellip; <a href=\"https:\/\/www.foell.org\/justin\/record-streaming-radio-program\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1,3,8],"tags":[166,127,94,128],"class_list":["post-1387","post","type-post","status-publish","format-standard","hentry","category-business","category-casual","category-ubuntu","tag-linux","tag-mp3","tag-music","tag-stream"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/posts\/1387","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/comments?post=1387"}],"version-history":[{"count":6,"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/posts\/1387\/revisions"}],"predecessor-version":[{"id":3583,"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/posts\/1387\/revisions\/3583"}],"wp:attachment":[{"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/media?parent=1387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/categories?post=1387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/tags?post=1387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}