for file in $(find ~/ -iname "*.mp3");do c=$(mp3info $file|grep Genre|cut -f 3 -d :|cut -f 2 -d " ");if [ -z "$c" ];then c="Uncategorized";fi;if [ ! -e $c ];then touch $c.m3u;fi;echo "$file">>$c.m3u;done

Create a simple playlist sort by Genre using mp3info

Sample Output
ls -al
total 40
drwxr-xr-x  2 alex alex  4096 2010-12-13 14:40 .
drwxr-xr-x 96 alex alex 16384 2010-12-13 14:15 ..
-rw-r--r--  1 alex alex  1426 2010-12-13 14:40 Blues.m3u
-rw-r--r--  1 alex alex  3668 2010-12-13 14:40 Other.m3u
-rw-r--r--  1 alex alex  4435 2010-12-13 14:40 Soundtrack.m3u
-rw-r--r--  1 alex alex  2375 2010-12-13 14:40 Uncategorized.m3u

1
By: dzup
2010-12-13 20:43:05

These Might Interest You

  • This will mv all your mp3 files in the current directory to $ARTIST/$ALBUM/$NAME.mp3 Make sure not to use sudo - as some weird things can happen if the mp3 file doesn't have id3 tags.


    5
    for file in *.mp3;do mkdir -p "$(mp3info -p "%a/%l" "$file")" && ln -s "$file" "$(mp3info -p "%a/%l/%t.mp3" "$file")";done
    matthewbauer · 2009-08-05 17:04:34 3
  • The command first deletes any old playlist calles playlist.tmp under /tmp. After that it recursively searches all direcotries under ~/mp3 and stores the result in /tmp/playlist.tmp. After havin created the playlist, the command will execute mplayer which will shuffle through the playlist. This command is aliased to m is aliased to `rm -rf /tmp/playlist.tmp && find ~/mp3 -name *.mp3 > /tmp/playlist.tmp && mplayer -playlist /tmp/playlist.tmp -shuffle -loop 0 | grep Playing' in my ~/.bashrc. Show Sample Output


    2
    rm -rf /tmp/playlist.tmp && find ~/mp3 -name *.mp3 > /tmp/playlist.tmp && mplayer -playlist /tmp/playlist.tmp -shuffle -loop 0 | grep Playing
    hhanff · 2010-03-23 21:33:44 9
  • I use this to generate a playlist with all the podcasts I listen to. Ordered from most recent to older. Show Sample Output


    3
    find . -type f -print0 | xargs -r0 stat -c %Y\ %n | sort -rn | gawk '{sub(/.\//,"",$2); print $2}' > /tmp/playlist.m3u
    microft · 2009-03-04 16:41:02 1
  • On my music directory, I create variable that contains all mp3s files, then I play them with mpg123. -C options enable terminal control key, s for stop, p for pause, f for forward to next song.


    -1
    PLAYLIST=$(ls -1) ; mpg123 -C $PLAYLIST
    servermanaged · 2009-03-19 17:20:28 6
  • echoprint identify your song, then return artist, song name and album name(release) in a JSON. jq parse it and mp3info set the data in your mp3 file. of course it depends on: mp3info jq echoprint You need to set the environment variable export CODEGEN_NEST_API_KEY='YOUR_ECHONEST_KEY_HERE' You can use it with find, but probably will bypass the 120 request/minute of developer account key. So, use a sleep to do it. Something like: find -name \*.mp3 | while read $f; do eval echo $(echoprint-codegen "$f" | jq ' .[0].metadata | "mp3info -a \"" + .artist + "\" -t \"" + .title + "\" -l \"" + .release + "\" \"" + .filename + "\"" ' ) | bash; sleep 1; done


    0
    eval echo $(echoprint-codegen "/path/to/file.mp3"| jq ' .[0].metadata | "mp3info -a \"" + .artist + "\" -t \"" + .title + "\" -l \"" + .release + "\" \"" + .filename + "\"" ' ) | bash
    glaudiston · 2014-08-08 21:14:53 0

  • 2
    find -name '*.mp3' -exec mp3info {} -p "%F: %r kbps\n" \; | sort | sed '/320 kbps/d'
    infojunkie · 2013-05-21 04:46:55 0

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: