Changeset ca8acb7 for client


Ignore:
Timestamp:
Oct 2, 2010, 10:15:20 PM (14 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
master, debian, mac, no-cups
Children:
43ddb7a
Parents:
addd785
git-author:
Jessica B. Hamrick <jhamrick@…> (10/02/10 22:15:20)
git-committer:
Jessica B. Hamrick <jhamrick@…> (10/02/10 22:15:20)
Message:

Add recursive file playing to gbr (Trac #29)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/bin/gbr

    raddd785 rca8acb7  
    1212use Image::ExifTool qw(ImageInfo);
    1313use List::Util 'shuffle';
     14use File::Find;
    1415
    1516# the usage for this script
     
    1920        -q, --queue             Specify a queue other than the default
    2021        -d, --dryrun            Just list what would be done
    21         -r, --shuffle           Randomize the order that the songs are queued in
     22        -s, --shuffle           Randomize the order that the songs are queued in
     23        -r, --recursive         Recursively find files if a directory is passed in
    2224        -h, --help              Print this message
    2325USAGE
     
    2830my $help = 0;
    2931my $shuffle = 0;
     32my $recursive = 0;
    3033
    3134# parse the options
     
    3336            'd|dryrun' => \$dryrun,
    3437            'h|help' => \$help,
    35             's|shuffle' => \$shuffle);
     38            's|shuffle' => \$shuffle,
     39            'r|recursive' => \$recursive);
    3640
    3741# if the -h flag was passed, then print the usage and exit
     
    4347# get the files to print from the arguments
    4448my @files = @ARGV[0 .. $#ARGV];
     49my @allfiles;
     50
     51# if the recursive flag was passed, then recursively find files
     52if ($recursive) {
     53
     54    # helper function to add a file to the end of the list, but only
     55    # if it is a file (and not a directory)
     56    sub append {
     57        my $name = $File::Find::name;
     58        if (-f $name) {
     59            push(@allfiles, $name);
     60        }
     61    }
     62   
     63    # recursively find all the files and add them to @allfiles
     64    find(\&append, @files);
     65
     66    # if we're not shuffling the list, then sort the files.  If we are
     67    # shuffling the list, then don't bother sorting (since we're going
     68    # to shuffle it anyway)
     69    unless ($shuffle) {
     70        @files = sort(@allfiles);
     71    } else {
     72        @files = @allfiles;
     73    }
     74}
    4575
    4676# if the shuffle flag was passed, then shuffle the order of the files
Note: See TracChangeset for help on using the changeset viewer.