Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.


Help with Playlist creation script


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Help with Playlist creation script

Hello. I am hoping to have an automated way to create Playlist files from Genre txt files I'll be making with my music collection. This is for use with my WD Live player, and is so that certain albums / artists can live in multiple genre directories when I browse to them from my WD Live player.

Here's an example of my directory structure:
Code:
/mnt/user/Music/+Acoustic Guitar/Kaki King/Kaki King - 2003 - Everybody Loves You/.Genre.txt
/mnt/user/Music/Beck/Beck - 2008 - Modern Guilt/.Genre.txt
/mnt/user/Music/Maroon 5/Maroon 5 - 2010 - Hands All Over/.Genre.txt
/mnt/user/Music/_Playlists/*.m3u

The goal is to take each directory with a .Genre.txt file (not all directories have this), add that root Folder to the appropriate playlist.m3u file/s based on genre/s in .Genre.txt using relative paths in the Playlist file. Then take each of those m3u files and alphabetize the contents of the m3u file based on the Folder Name that the Genre.txt file lives in. Here's what I mean:


Genre.txt contents:
Kaki King - 2003 - Everybody Loves You -> .Genre.txt
Acoustic Guitar
Rock
Beck - 2008 - Modern Guilt -> .Genre.txt
Alternative
Rock
Maroon 5 - 2010 - Hands All Over -> .Genre.txt
Alternative
Rock

The m3u files should look like this:

/mnt/user/Music/_Playlists/Acoustic Guitar.m3u
Code:
../+Acoustic Guitar/Kaki King/Kaki King - 2003 - Everybody Loves You/

/mnt/user/Music/_Playlists/Alternative.m3u
Code:
../Beck/Beck - 2008 - Modern Guilt/
../Maroon 5/Maroon 5 - 2010 - Hands All Over/

/mnt/user/Music/_Playlists/Rock.m3u
Code:
../Beck/Beck - 2008 - Modern Guilt/
../+Acoustic Guitar/Kaki King/Kaki King - 2003 - Everybody Loves You/
../Maroon 5/Maroon 5 - 2010 - Hands All Over/


I'm fine with the m3u files being completely deleted and recreated each time this script runs, as I expect that will be the easiest solution.

Is this easily possible using Bash? I know there are some GUI solutions to what I'm looking to do, but if I'm able to get a solution using the .Genre.txt files, it would be so much more elegant.

---------- Post updated at 06:04 PM ---------- Previous update was at 03:49 PM ----------

Alright, here's what I have so far.

Code:
MusicDIR=/mnt/user/Music/
PlaylistDIR=/mnt/user/Music/_Playlists/

find $PlaylistDIR -type f -name "*.m3u" -exec rm -f {} \;

find $MusicDIR -type d | while read FOLDER
do
        if ls -A "$FOLDER" | grep .Genre.txt > /dev/null
        then
			cat "${FOLDER}/.Genre.txt" | while read thisGENRE; do
				echo "$FOLDER" | sed 's/\/mnt\/user\/Music/../g' >> "${PlaylistDIR}${thisGENRE}".m3u
			done
        fi
done

This will create all of the m3u files I need. The next step will be alphabetizing the m3u files based on the Folder name.


Currently one of my m3u files looks like this:
/mnt/user/Music/_Playlists/Rock.m3u
Code:
../+Acoustic Guitar/Kaki King/Kaki King - 2003 - Everybody Loves You/
../Beck/Beck - 2008 - Modern Guilt/
../Maroon 5/Maroon 5 - 2010 - Hands All Over/

However I want it to look like this:
/mnt/user/Music/_Playlists/Rock.m3u
Code:
../Beck/Beck - 2008 - Modern Guilt/
../+Acoustic Guitar/Kaki King/Kaki King - 2003 - Everybody Loves You/
../Maroon 5/Maroon 5 - 2010 - Hands All Over/


I know the Sort command is likely what I need, but I'm not certain how to sort only based on the folder name. Any help would be greatly appreciated.
# 2  
put the original folder together with the dir name together and sort base on the 2nd field.

Code:
sep="|"
while read d
do
  # get rid of the trailing /
  dd=${d%/}

  # print the orginal and dirname, separated by a "|" (hopefully no "|" in the folder name
  echo "$d$sep${dd##*/}"
done < /mnt/user/Music/_Playlists/Rock.m3u | sort -t"$sep" -k 2 | cut -d"$sep" -f1

This User Gave Thanks to chihung For This Post:
# 3  
Quote:
Originally Posted by chihung
put the original folder together with the dir name together and sort base on the 2nd field.

Code:
sep="|"
while read d
do
  # get rid of the trailing /
  dd=${d%/}

  # print the orginal and dirname, separated by a "|" (hopefully no "|" in the folder name
  echo "$d$sep${dd##*/}"
done < /mnt/user/Music/_Playlists/Rock.m3u | sort -t"$sep" -k 2 | cut -d"$sep" -f1

Thanks! I think this is almost what I need. I'm a little confused about what "while read d" does (I'm very much a bash noob who uses Google extensively to program). I'm hoping to add some lines to my code which will look for any m3u files in my $PlaylistDIR (the ones that my script just created - currently set to /mnt/user/Music/_Playlists/), and sort them all one by one using your code.

How would your code need to be altered for that to work?
# 4  
Code:
while read d

is the same as your
Code:
while read FOLDER

In my code, I get the input from the redirection whereas your's is getting it from the pipe
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

4 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Music Playlist parse/grep

Hi. Please help with a single line bash that will match field 3, and field 2 , if not then echo "Not Found". Original Music List name; Musiclists.m3u Format: \Music\The Rolling Stones - Angel.mp3 \Music\Maroon 5\Moves Like Jagger.mp3 Make a groomed playlist variable... $... (0 Replies)
Discussion started by: DSommers
0 Replies

2. Shell Programming and Scripting

a playlist for ffmpeg streamer

Hi, I hope I am posting in the right place. I use to stream to justin tv using ffmpeg with that command ffmpeg -re -i "path/to/input.avi" -vcodec libx264 -preset fast -crf 30 -acodec libfaac -ab 128k -ar 44100 -f flv rtmp://live.justin.tv/app/xxxxxxxxxxx I would like to know if a bash... (2 Replies)
Discussion started by: undercash
2 Replies

3. UNIX for Dummies Questions & Answers

[solved] Script creation (how to include options in the script)

Hi guys i have written a script which takes the options given to him and execute itself accordingly. for example if a script name is doctortux then executing doctortux without option should made doctortux to be executed in automatic mode i.e. doctortux -a or if a doctortux is needed to run in... (4 Replies)
Discussion started by: pinga123
4 Replies

4. Shell Programming and Scripting

Need help in a shell script to edit a tablespace creation script.

Hi, CREATE TABLESPACE aps_blob_large01 DATAFILE '/c2r6u13/u03/oradata/qnoldv01/aps_blob_large0101.dbf' SIZE X 270532608 REUSE DEFAULT STORAGE (INITIAL 134217728 NEXT... (2 Replies)
Discussion started by: rparavastu
2 Replies

Featured Tech Videos