Skip to content

Instantly share code, notes, and snippets.

@Nemoder
Forked from blackknight36/audacious-random-album.pl
Last active September 11, 2016 09:03
Show Gist options
  • Select an option

  • Save Nemoder/2191ee5931d4adcd6d8aa568e20bc832 to your computer and use it in GitHub Desktop.

Select an option

Save Nemoder/2191ee5931d4adcd6d8aa568e20bc832 to your computer and use it in GitHub Desktop.
random folders instead of tracks
#!/usr/bin/perl
use strict;
use List::Util qw(shuffle);
my ($dir, $num)=@ARGV;
if (not defined $dir){
$dir=`pwd`;
chomp($dir);
}
my $cmd = "find \"$dir\" -type d";
my @folders = `$cmd`;
my @rfolders = shuffle @folders;
open(LIST, ">", "/tmp/rand_playlist.m3u");
my $count=0;
foreach my $folder (@rfolders) {
chomp $folder;
my $cmd = "find \"$folder\" -maxdepth 1 -type f";
my @songs = `$cmd`;
foreach my $song (@songs){
next unless ($song =~ m/\.mp3$/) or ($song =~ m/\.ogg$/) or ($song =~ m/\.flac$/);
print LIST $song;
$count++;
}
}
close(LIST);
if($count >0){
system("audacious /tmp/rand_playlist.m3u &");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment