-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdupe_tv_by_episode
executable file
·76 lines (66 loc) · 1.77 KB
/
dupe_tv_by_episode
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
71
72
73
74
75
76
#!/usr/bin/perl
# abstract: only keep the best quality tv show
use strict;
# Remove duplicate TV show episodes.
# Prefer 1080 and 720 over SD.
#
# Given these:
# Antikrundan.S22E05.SWEDiSH.720p.HDTV.x264-xD2V/
# Antikrundan.S22E05.SWEDiSH.HDTV.XviD-D2V/
# Remove this:
# Antikrundan.S22E05.SWEDiSH.HDTV.XviD-D2V/
# Keep this:
# Antikrundan.S22E05.SWEDiSH.720p.HDTV.x264-xD2V/
use Carp qw(croak);
use File::Path qw(remove_tree);
use Data::Dumper qw(Dumper);
use Term::ExtendedColor qw(:attributes);
{
package Data::Dumper;
no strict 'vars';
$Terse = $Indent = $Useqq = $Deparse = $Sortkeys = 1;
$Quotekeys = 0;
}
my $dir = shift // '/mnt/TV_1/.new';
my %files;
$files{$_}++ for(glob("$dir/*"));
my %show;
for my $f(sort(keys(%files))) {
my ($base) = $f =~ m{.*/(.+)$};
my ($show, $episode) = $base =~ m{^(.+)\.(S[0-9]+E[0-9]+)};
next if !defined($episode);
push(@{$show{$show}->{episode}{$episode}}, $f);
}
my @hd;
for my $s(sort(keys(%show))) {
for my $e(keys(%{$show{$s}->{episode}})) {
if(scalar(@{$show{$s}->{episode}{$e}}) > 1) {
my $i = 0;
for my $dupe(sort(@{$show{$s}->{episode}{$e}})) {
if($dupe =~ m{(?:720|1080)}) {
push(@hd, $dupe);
splice(@{$show{$s}->{episode}{$e}}, $i, 1);
next;
}
else {
print "Remove ",
bold(fg('red1', sprintf("%67.67s", $dupe))), " [y/N] ";
chomp(my $answer = <STDIN>);
if(lc($answer) eq 'y') {
if(remove_tree($dupe)) {
print "removed '$dupe'\n";
}
else {
Carp::croak("remove_tree($dupe) - $!\n");
}
}
else {
next;
}
}
$i++;
}
}
}
}
print Dumper \@hd;