Skip to content

Instantly share code, notes, and snippets.

@rafi
Last active June 4, 2018 18:54
Show Gist options
  • Save rafi/e5b8c3dfb984ac3123be to your computer and use it in GitHub Desktop.
Save rafi/e5b8c3dfb984ac3123be to your computer and use it in GitHub Desktop.
Generate a playlist from a plain text file with songs. Using beets database to query file paths
#!/bin/bash
music_path="/mnt/media/music"
while read line
do
song=$(echo $line | sed 's/(.*)//g')
artist=$(echo ${song% - *} | sed 's/ *$//')
title=$(echo ${song#* - } | sed 's/ *$//')
if [ -n "$title" ]; then
match=$(beet ls -p artist:"$artist" title:"$title")
echo "Artist: $artist Title: $title"
if [ -n "$match" ]; then
match=${match#${music_path}/}
echo $match >> playlist_matched.m3u
else
echo $line >> playlist_missing.txt
fi
fi
done < $1
The Black Angels - Entrance Song
Caribou - Odessa
LCD Soundsystem - Dance Yrself Clean
Portugal. The Man - Evil Friends
Toro Y Moi - Still Sound
Yelle - Ce Jeu
Young the Giant - My Body
Serebro - Mi Mi Mi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment