{"id":1865,"date":"2016-02-01T16:57:18","date_gmt":"2016-02-01T14:57:18","guid":{"rendered":"http:\/\/www.wittwer.nl\/?p=1865"},"modified":"2016-02-01T16:57:18","modified_gmt":"2016-02-01T14:57:18","slug":"playlists-in-pi-musicbox","status":"publish","type":"post","link":"https:\/\/www.wittwer.nl\/?p=1865","title":{"rendered":"Playlists in Pi Musicbox"},"content":{"rendered":"<p>Pi Musicbox has no built-in functionality for creating playlists for local music files that are located on the SD card or a USB drive. Playlists (m3u files) need to be located (by default at least, this can be changed in settings.ini) in <em>\/var\/lib\/mopidy\/playlists<\/em>. Filenames must be absolute of course. I started out by creating these playlists manually, but since they are simple text files, it can be done in a few lines of bash script:<\/p>\n<pre>#!\/bin\/bash\r\nrm -f \/var\/lib\/mopidy\/playlists\/\"$2\".m3u\r\nfor filename in \"$1\"\/*.mp3\r\ndo\r\n\u00a0\u00a0\u00a0 echo $filename &gt;&gt; \/var\/lib\/mopidy\/playlists\/\"$2.m3u\"\r\ndone<\/pre>\n<p>Save it in the root directory as <em>playlist.sh<\/em> and make it executable via <em>chmod a+x playlist.sh<\/em>. You can then run it via <em>.\/playlist.sh directory playlistname<\/em>, e.g. <em>.\/playlist.sh \/music\/USB\/Free Free<\/em>. It is important to supply the directory without trailing backslash.<\/p>\n<p>This works fine for adding playlists for one or two directories, but it still quite slow when adding them for a couple. In comes the following script, that automatically does the same thing for all subdirectories in a given directory (<strong>Caution: This deletes all existing m3u files<\/strong>):<\/p>\n<pre>#!\/bin\/bash\r\nrm -f \/var\/lib\/mopidy\/playlists\/*.m3u\r\nfind \"$1\" -type d |\r\nwhile read subdir\r\ndo\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 for filename in \"$subdir\"\/*.mp3\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 do\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if [ -e \"$filename\" ]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo $filename &gt;&gt; \/var\/lib\/mopidy\/playlists\/\"${subdir##*\/}.m3u\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fi\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 done\r\ndone<\/pre>\n<p>It is invoked, after saving to <em>playlists.sh<\/em> and <em>chmod a+x playlists.sh<\/em>, with <em>.\/playlists.sh \/music\/USB<\/em>, or wherever the MP3 files are located. Mopidy then needs to be restarted via <em>\/etc\/init.d\/mopidy restart<\/em> to make the playlists visible in the web interface.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pi Musicbox has no built-in functionality for creating playlists for local music files that are located on the SD card or a USB drive. Playlists (m3u files) need to be located (by default at least, this can be changed in settings.ini) in \/var\/lib\/mopidy\/playlists. Filenames must be absolute of course. I started out by creating these [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1871,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"_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":[78],"tags":[87],"class_list":{"0":"post-1865","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-tech","8":"tag-raspberry-pi","9":"czr-hentry"},"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.wittwer.nl\/wp-content\/uploads\/2016\/01\/pmblogo.png","jetpack_shortlink":"https:\/\/wp.me\/plKIk-u5","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.wittwer.nl\/index.php?rest_route=\/wp\/v2\/posts\/1865","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wittwer.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wittwer.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wittwer.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wittwer.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1865"}],"version-history":[{"count":3,"href":"https:\/\/www.wittwer.nl\/index.php?rest_route=\/wp\/v2\/posts\/1865\/revisions"}],"predecessor-version":[{"id":1870,"href":"https:\/\/www.wittwer.nl\/index.php?rest_route=\/wp\/v2\/posts\/1865\/revisions\/1870"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wittwer.nl\/index.php?rest_route=\/wp\/v2\/media\/1871"}],"wp:attachment":[{"href":"https:\/\/www.wittwer.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wittwer.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wittwer.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}