-
Notifications
You must be signed in to change notification settings - Fork 34
/
rem-mp3tags.pl
executable file
·70 lines (49 loc) · 1.39 KB
/
rem-mp3tags.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/perl
# Daniel "Trizen" Șuteu
# License: GPLv3
# Date: 15 August 2011
# Edit: 11 August 2019
# https://github.com/trizen
# Removes tags of MP3 audio files in a given directory and its subdirectories.
use 5.010;
use strict;
use warnings;
use MP3::Tag;
use File::Find qw(find);
use File::Copy qw(copy);
use File::Temp qw(tempfile);
use File::Basename qw(basename);
my (@files) = grep { -e $_ } @ARGV;
die "Usage: $0 <dirs|files>\n" unless @files;
my $quiet = scalar grep { /^--?(?:q|quiet)\z/ } @ARGV;
my @mp3_files;
find(\&wanted_files, @files);
sub wanted_files {
my $file = $File::Find::name;
push @mp3_files, $file if $file =~ /\.mp3\z/i;
}
foreach my $filename (@mp3_files) {
my (undef, $tmpfile) = tempfile(basename($filename) . ' - XXXXXX', TMPDIR => 1);
unlink($tmpfile);
$tmpfile =~ s/ - .{6}\z//;
copy($filename, $tmpfile);
my $mp3 = 'MP3::Tag'->new($tmpfile);
$mp3->get_tags;
my $had_tags = 0;
if (exists $mp3->{'ID3v1'}) {
say "[ID3v1] Removing tag: $filename" unless $quiet;
$mp3->{'ID3v1'}->remove_tag;
$had_tags = 1;
}
if (exists $mp3->{'ID3v2'}) {
say "[ID3v2] Removing tag: $filename" unless $quiet;
$mp3->{'ID3v2'}->remove_tag;
$had_tags = 1;
}
$mp3->close;
if ($had_tags) {
unlink($filename);
copy($tmpfile, $filename);
}
unlink($tmpfile);
}