- #!/usr/bin/perl
- use 5.14.0;
- use strict;
- use warnings;
- #use File::Find qw(finddepth);
- #my $library = "/home/sir/Music/Songbird Music";
- my $library = "/home/sir/Music/Songbird Music";
- my (%files, @files, @dirs);
- getdirs($library);
- if (-f $ls) {
- # my @stat = stat($dn);
- # my $ino = $stat[1];
- # say "$dn has $ino";
- getfiles($dn);
- if ($fc > 0) {
- #replaygain($dn);
- for (my $n = 0; $n < $fc; $n++) {
- #say $files[$n];
- my $fn = $files[$n];
- #rmtag($fn, 'rating');
- #albumartist($fn, $fc);
- #track($fn);
- #totaltracks($fn, $fc);
- # empty($fn);
- # duplicate($fn);
- discnum($fn, $n, $fc);
- }
- }
- }
- }
- # Make this subroutine and the whole script so that each file name is stored in a hash and that each member contains an anonymous hash with the tags (the alltags hash).
- # This means it won't have to look up the tags again for the albumartist subroutine.
- sub gettags {
- my (%alltags, @mflac);
- foreach (@mflac) {
- if ($tag[1]) {
- } else {
- }
- }
- }
- sub getdirs {
- #@dirs = `find -L "$dn" -name "*" -type d -mindepth 1`;
- }
- sub getfiles {
- my $fn = "$dn/$_";
- if (/.flac$/ && -f $fn) {
- $files{$fn} = { gettags($fn) };
- }
- }
- }
- sub replaygain {
- my %replaygain;
- #foreach ('REFERENCE_LOUDNESS', 'TRACK_GAIN', 'TRACK_PEAK', 'ALBUM_GAIN', 'ALBUM_PEAK') {
- # my $tag = 'REPLAYGAIN_' . $_;
- # system('metaflac', "--remove-tag=$tag", keys(%files));
- #}
- if ($files{$fn}{replaygain_album_gain}) {
- $replaygain{$files{$fn}{replaygain_album_gain}->[0]}++;
- }
- }
- say " done";
- }
- }
- sub albumartist {
- if (!$files{$fn}{albumartist}) {
- my $albumartist = $files{$fn}{artist}->[0];
- my %artist;
- my $max;
- if ($tracks == 1) { $max = $tracks } else { $max = $tracks / 2 }
- $albumartist = 'Various Artists';
- }
- say "$fn: adding albumartist tag";
- }
- }
- sub empty {
- foreach (@{$files{$fn}{$k}}) {
- if ($_ eq 'null') {
- say "$fn: WARNING: empty $k tag";
- }
- }
- }
- }
- sub duplicate {
- foreach (@{$files{$fn}{$k}}) {
- if ($exists{$tag}) {
- say "$fn: WARNING: duplicate $k tag";
- } else {
- $exists{$tag} = 1;
- }
- }
- }
- }
- sub track {
- my $track = $files{$fn}{tracknumber}->[0];
- if (!$track) {
- say "$fn: doesn't have any tracknumber tag"
- }
- elsif ($track =~ m/^0/ && $track != 0) {
- say "$fn: fixing tracknumber tag";
- $track =~ s/^0+//;
- }
- }
- sub totaltracks {
- if (
- !$files{$fn}{totaltracks} &&
- !$files{$fn}{tracktotal}
- ) {
- say "$fn: adding totaltracks tag";
- }
- elsif (
- $files{$fn}{tracktotal} &&
- !$files{$fn}{totaltracks}
- ) {
- say "$fn: replacing tracktotal tag with totaltracks";
- system('metaflac', '--remove-tag=TRACKTOTAL', "--set-tag=TOTALTRACKS=$files{$fn}{tracktotal}->[0]", $fn);
- }
- }
- sub discnum {
- my $dn = dirname($fn);
- my $discnumber = $files{$fn}{discnumber}->[0];
- my $album = $files{$fn}{album}->[0];
- my ($match, $newfn);
- my $regex = '[[:punct:]]?(cd|disc) ?[0-9]+[[:punct:]]?$' ;
- if ($album =~ /$regex/i) {
- $album =~ s/.?${^MATCH}.?//;
- }
- if (!$discnumber) {
- if (basename($fn) =~ /^[0-9]+-/) {
- $match = ${^MATCH};
- ${^MATCH} =~ /([0-9]+)/;
- }
- elsif ($dn =~ /$regex/i) {
- $match = ${^MATCH};
- ${^MATCH} =~ /([0-9]+)/;
- $dn =~ s/ .?($match).?//;
- $newfn = "${dn}/" . "${discnumber}-" . basename($fn);
- make_path($dn) if (! -d $dn);
- }
- else {
- $discnumber = 1;
- $newfn = "${dn}/" . "${discnumber}-" . basename($fn);
- }
- if (!$newfn) { $newfn = $fn }
- say "$newfn: adding discnumber tag";
- }
- }
- sub rmtag {
- foreach my $tag (@_) {
- if ($files{$fn}{$tag}) {
- say "$fn: removing $tag tag";
- }
- }
- }
replaygain
Posted by Anonymous on Wed 5th Sep 2012 14:55
raw | new post
view followups (newest first): replaygain by Anonymous
modification of post by Anonymous (view diff)
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.