Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Tip] - Monitoring a Directory for XMMS/BMP
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
ctt
Tux's lil' helper
Tux's lil' helper


Joined: 05 Feb 2005
Posts: 136

PostPosted: Sat Apr 23, 2005 2:35 pm    Post subject: [Tip] - Monitoring a Directory for XMMS/BMP Reply with quote

Monitoring a Directory for XMMS/BMP

For me, one of the most annoying things about downloading .mp3s and playing them in XMMS is actually adding them to the playlist. As I'm only using blackbox and have no GUI file manager, it was usually an exercise in hitting the Add/File button in the playlist, and searching around in the filename sorted dialog box for the newest files.

Then, one day, I stumbled upon xmmsctrl, and whipped up the following script that I call, xmms-update-playlist:

Code:
#!/bin/bash

# What I want to do is do a diff between the current playlist in XMMS and
# the contents of the given directory.  The files which are unique to the
# given directory should be enqueued in `last modified' order.
#
# Requires...
# media-sound/xmmsctrl
# media-sound/xmms
# `system' eclass

newline_to_null () {
    perl -e '
        while ($input_line = <STDIN>) {
            chomp($input_line);
            print("$input_line\000");
        }
    '
}

remove_blank_lines () {
    sed '/^ *$/ d'
}

generate_directory_list () {
    (
        ls -d "$1"/*.[Mm][pP]3; # add new file types here
    ) | sort | uniq
}

get_update() {
    if [ -d "$1" ]
    then
        xmmsctrl playfiles                          | \
            sed 's/[0-9]*\t//'                      | \
            sort                                    | \
            uniq                                    | \
            diff - <(generate_directory_list "$1")  | \
            grep '^>'                               | \
            sed 's/^> *//'
    fi

}

sort_files_by_date () {
    perl -e '
        sub date_comp {
            my (undef,undef,undef,undef,undef,undef,undef,undef,
             $atime_l,$mtime_l,$ctime_l,undef,undef) = stat( $_[0] );

            my (undef,undef,undef,undef,undef,undef,undef,undef,
             $atime_r,$mtime_r,$ctime_r,undef,undef) = stat( $_[1] );

            return ($mtime_l - $mtime_r);
        }

        @files = <STDIN>;
        chomp(@files);

        @files = sort( { date_comp($a,$b) } @files);
        print( join("\n", @files) . "\n");
    '
}

enqueue_files () {
    xargs -0 xmms -e
}

get_update "$1" | sort_files_by_date | remove_blank_lines | newline_to_null | enqueue_files


What this ends up doing is, given a directory...:


  • Generate a list of .mp3s, etc in that directory.
  • Generate a list of files in the xmms playlist.
  • Filter the list of .mp3s in the directory such that it only contains `new' files.
  • Sort this list by `last modified date', and enqueue it.


This way, I can start up xmms and run something like this in an xterm:

Code:

while true; do xmms-update-playlist /my/mp3/directory; sleep 10; done


...and just monitor the bottom of my playlist in XMMS. Something like this should be possible as well...

Code:

while true; do xmms-update-playlist /my/mp3/directory; xmms-update-playlist /my/other/mp3/directory; sleep 10; done


...which will monitor more than one directory.

Hopefully this helps someone else,

[ just noticed...this also works for the XMMS based BMP as well ]
_________________
- chris
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum