Skip to content

Instantly share code, notes, and snippets.

@jnbek
Created May 10, 2016 23:53
Show Gist options
  • Save jnbek/b1107d39d2bf06c468adc37c6f17b72d to your computer and use it in GitHub Desktop.
Save jnbek/b1107d39d2bf06c468adc37c6f17b72d to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
use strict;
use warnings;
use Env qw(HOME);
use MP3::Info;
use File::Find ();
use Data::Dumper;
#my $icy = MP3::Icecast->new;
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
my @files = qw();
my @genres = qw(Metal Grind Djent Industrial Gothic);
my @ignore = qw( Slayer Bloodbath );
sub wanted {
my ($dev, $ino, $mode, $nlink, $uid, $gid);
(($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_))
&& -f _
&& push @files, $name;
}
open(my $FH, '>', "/usr/local/etc/icecast/playlist.txt") || die $!;
# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, '/mp3/music/');
foreach my $file (@files) {
my $tag = get_mp3tag($file);
if ($tag->{'ARTIST'}) {
next if $tag->{'ARTIST'} =~ m/(\[|\])/g;
next if grep {/$tag->{'ARTIST'}/} @ignore;
}
if ($tag->{'GENRE'}) {
foreach my $g (@genres) {
if ($tag->{'GENRE'} =~ m/$g/ig) {
print "$file\n";
print $FH "$file\n";
last;
}
}
}
}
close $FH;
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment