Last active
January 17, 2020 21:58
-
-
Save NewRedsquare/506b679cddd300e39085bb0e41c7d84d to your computer and use it in GitHub Desktop.
it's a Proof-of-Concept to automatically create a XSPF playlist from .flac files, it's kinda messy i know ;D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm -f list.xspf | |
cd $1 # use the destination path as first parameter and use the web folder destination as second parameter ( /var/Music & Music for example) | |
cp /usr/local/bin/playlist-template-header ./list.xspf | |
for f in *.flac; do | |
metaflac --export-tags-to=tags.tmp --export-picture-to=covers/"$f".png "$f" | |
cp /usr/local/bin/playlist-template ./list.tmp | |
title=$(grep -P 'TITLE=' tags.tmp | sed 's/\<TITLE\>//g' | sed 's/=//g') | |
album=$(grep -P 'ALBUM=' tags.tmp | sed 's/\<ALBUM\>//g' | sed 's/=//g') | |
albumartist=$(grep -P 'ALBUMARTIST=' tags.tmp | sed 's/\<ALBUMARTIST\>//g' | sed 's/=//g') | |
tracknumber=$(grep -P 'TRACKNUMBER=' tags.tmp | sed 's/\<TRACKNUMBER\>//g' | sed 's/=//g') | |
length=$(grep -P 'LENGTH=' tags.tmp | sed 's/\<LENGTH\>//g' | sed 's/=//g' | sed 's/$/000/') | |
image=$(echo example.com/music/$(echo $2)/covers/$(echo $f).png) | |
image1=$(python -c "import urllib;print urllib.quote(raw_input())" <<< "$image") # converts into URL format | |
image2=$(echo https://$(echo $image1)) | |
location=$(echo example.com/music/$(echo $2)/$(echo $f)) | |
location1=$(python -c "import urllib;print urllib.quote(raw_input())" <<< "$location") # converts into URL format | |
location2=$(echo https://$(echo $location1)) | |
sed -i "s~\<title\>>~&$title~" list.tmp | |
sed -i "s~\<album\>>~&$album~" list.tmp | |
sed -i "s~\<creator\>>~&$albumartist~" list.tmp | |
sed -i "s~\<trackNum\>>~&$tracknumber~" list.tmp | |
sed -i "s~\<duration\>>~&$length~" list.tmp | |
sed -i "s~\<image\>>~&$image2~" list.tmp | |
sed -i "s~\<location\>>~&$location2~" list.tmp | |
cat list.tmp >> list.xspf rm list.tmp rm tags.tmp done | |
cat /usr/local/bin/playlist-template-end >> list.xspf | |
chown -R www-data:www-data covers/ | |
chmod 644 covers/* | |
chown www-data:www-data list.xspf | |
chmod 644 list.xspf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
</trackList> | |
</playlist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<playlist version="1" xmlns="http://xspf.org/ns/0/"> | |
<trackList> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment