LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Blogs > invalidid
User Name
Password

Notices

Rate this Entry

Simple shell script to create playlists from file structure

Posted 03-01-2010 at 11:28 AM by invalidid
Updated 12-03-2013 at 03:15 PM by invalidid

Hi everybody!
In my first post on this blog I want to publish something simple but useful for guys who prefer to use applications like xine, mplayer or totem for playing music. It's a bash script, which creates playlists using the unix tool "find". Basic documentation can be found in the header of the script file.

I hope you find it useful and comfortable. Have fun with it!

Code:
#!/bin/bash
# mkpls.sh - Create a playlist from a bunch of files.
#
# Information how to use it
# =========================
# Invocation:
# $ mkpls.sh "[FULL PATH]"
# 
# This will create a playlist file with ".pls" as extension. This file has the
# same name like the given directory, except its extension and is stored on the
# same place like the given directory. 
# 
# Setup example:
# It is useful in cases, where following directory structure is used:
# /home/[user]/music/[ARTIST]/[NAME OF CD]/[NR][NAME OF SONG].[EXT]
#
# And to create the playlist for [NAME OF CD] mkpls.sh has to be invoked like
# this:
# $ mkpls.sh "/home/[user]/music/[ARTIST]/[NAME OF CD]"
# If the execution was successfull, you will get following output, printed on 
# the console:
#
# ~/[ARTIST] ~/[ARTIST]
# ~/[ARTIST]
#
# This is because of the commands "pushd" and "popd", which will save and 
# restore the current working directory. 
# If you find a bug, don't hesitate to mail me.
# Have fun!

outfile=`basename "$1"`.pls

pushd .

cd /
touch "$1/$outfile"
find "$1/" -type f | grep -v "$outfile" | sort > "$1/$outfile"
mv "$1/$outfile" "$1/.."
popd
Views 1806 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 06:56 AM.

Main Menu
Advertisement

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration