From 4ff5985670057a7d6a3c1567901ec14349056573 Mon Sep 17 00:00:00 2001
From: Gerhard Gonter <ggonter@gmail.com>
Date: Fri, 24 Jun 2016 15:11:48 +0200
Subject: [PATCH] rename files by album name

---
 textarchive/mp3tags.pl | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/textarchive/mp3tags.pl b/textarchive/mp3tags.pl
index b413c43..06922a9 100755
--- a/textarchive/mp3tags.pl
+++ b/textarchive/mp3tags.pl
@@ -6,12 +6,20 @@ use MP3::Info;
 use Data::Dumper;
 $Data::Dumper::Indent= 1;
 
+my $op_mode;
+my $doit= 0;
+
 my @PAR;
 while (my $arg= shift (@ARGV))
 {
   if ($arg =~ /^-/)
   {
-    &usage;
+    if ($arg eq '--mv-album') { $op_mode= 'mv_album'; }
+    elsif ($arg eq '--doit') { $doit= 1; }
+    else
+    {
+      &usage;
+    }
   }
   else
   {
@@ -19,14 +27,34 @@ while (my $arg= shift (@ARGV))
   }
 }
 
+my %albums;
 foreach my $file (@PAR)
 {
   my $tag= get_mp3tag ($file);
 
   print "file: [$file]\n";
   print "tag: ", Dumper ($tag);
+
+  if ($op_mode eq 'mv_album')
+  {
+    my $album= $tag->{'ALBUM'};
+    push (@{$albums{$album}}, $file);
+  }
 }
 
+  if ($op_mode eq 'mv_album')
+  {
+    foreach my $album (sort keys %albums)
+    {
+      print "album=[$album]\n";
+      system ('mkdir', $album) if ($doit);
+      foreach my $file (@{$albums{$album}})
+      {
+        print "file=[$file]\n";
+        system ('mv', '-i', $file, $album) if ($doit);
+      }
+    }
+  }
 
 __END__
 
-- 
GitLab