You are not logged in.

#1 2010-01-02 01:59:36

kYd
Member
Registered: 2009-01-20
Posts: 78

Bash: MPD playlist for recently added music.

Hey,

I have been looking for a way for MPD (or NCMPCPP) to add any new music I copy to my /music/ directory to a playlist, but I haven't found any way apart from using another music client.

I'm new to bash programming so I thought this might give me the opportunity to write a little script, which I run after adding each folder to the music directory:
http://pastebin.ca/1734640

I'm wondering to things: 1) How can I prevent duplicate enteries from being added to the playlist and 2) is their any other programs or tools out there that can do the same, but better, ideally being able to keep a constant watch over the /music/ directory and do this automatically.

Thanks,
JD

Last edited by kYd (2010-01-02 02:01:08)

Offline

#2 2010-01-03 03:18:57

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: Bash: MPD playlist for recently added music.

I'm not too sure I understand.  Do you want to create a play list for all your mp3 and flac files?  This command would work:

find /path/to/music/ -iname "*.mp3" -o -iname "*.flac" > /path/to/playlist.m3u

If you want it updated on the fly I would just cron the above to run once ever 1 minute.

Offline

#3 2010-01-03 04:40:02

pwd
Member
Registered: 2009-12-14
Posts: 13

Re: Bash: MPD playlist for recently added music.

Better to run find only when the dir. is modified, even more so if the library is huge:

music_dir=/path/to/music
playlist=/path/to/playlist.m3u

[ "$music_dir" -nt "$playlist" ] &&
find "$music_dir" -type f -iname "*.mp3" -o -iname "*.flac" > $playlist

Offline

#4 2010-01-03 11:04:13

jac
Member
From: /home/jac
Registered: 2009-05-19
Posts: 431
Website

Re: Bash: MPD playlist for recently added music.

For the duplicate file thing, if mpd playlists are plaintext [they are, if I remember correctly], then you can use 'sort -u' on the file to remove duplicates, if they have the same path.

Offline

#5 2010-01-03 22:32:52

kYd
Member
Registered: 2009-01-20
Posts: 78

Re: Bash: MPD playlist for recently added music.

Thanks for the replies; I think I've confussed you guys a little.

I don't want to add all the current songs in the directory into a playlist, I just want to add any new songs I put into my music folder into a playlist, called "New.m3u", just so I can easily see the latest additions to my music collection.

Offline

#6 2010-03-29 08:51:24

antisystem
Member
From: localhost
Registered: 2010-03-29
Posts: 3

Re: Bash: MPD playlist for recently added music.

I've written a script for this a long time ago... it uses find and ctime to locate new files in the music-dir
Files 'newer than n days' or 'older than n days' can be added.
For Example

 $ ctime3u -m -1

automatically updates the DB and adds all files from the subdir 'Metal' newer than 1day to a playlist.
Playlist name can be set manually or the script creates a random one.
The new playlist can be added to the current one, or replace it.
To automate this, simply use it as a cronjob

I'll paste the script when I'm home from work wink

Offline

#7 2010-03-29 09:08:24

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 881
Website

Re: Bash: MPD playlist for recently added music.

kYd wrote:

Thanks for the replies; I think I've confussed you guys a little.

I don't want to add all the current songs in the directory into a playlist, I just want to add any new songs I put into my music folder into a playlist, called "New.m3u", just so I can easily see the latest additions to my music collection.

What you want to use is inotify my friend.

Offline

#8 2010-04-03 16:22:58

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,001
Website

Re: Bash: MPD playlist for recently added music.

antisystem wrote:

I've written a script for this a long time ago
(...)
I'll paste the script when I'm home from work wink

damn. long workday..


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

Board footer

Powered by FluxBB