-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeardcomb
executable file
·67 lines (54 loc) · 1.7 KB
/
beardcomb
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
#!/usr/bin/env perl
# Clean the sick from your beard...
# Move the sickbeard downloads into their final locations, and create hard links
# to the outgoing directory.
use 5.12.0;
use autodie;
use warnings;
use File::Find qw( find );
use File::Spec::Functions qw( catdir catfile splitdir );
umask(0002); # want dirs to be group writable
my %CFG = (
source_root => '/var/lib/mythtv/sab/sickbeard',
dest_root => '/var/lib/mythtv/videos/TV',
link_dirs => [
'/var/lib/mythtv/sab/outgoing',
],
);
my $files = 0;
my $dry_run = (grep { /^-f$/ } @ARGV) == 0;
if ($dry_run) {
say STDERR "Dry run only. Specify -f to force.";
}
sub find_cb {
return unless -f;
my $episode_name = $_;
my $dirname = $File::Find::dir;
my $source_file = $File::Find::name;
my ($show_name) = reverse splitdir($dirname);
my $dest_dir = catdir($CFG{dest_root}, $show_name);
my $dest_file = catfile($dest_dir, $episode_name);
if (not -d $dest_dir) {
say "mkdir $dest_dir";
if (not $dry_run) {
mkdir($dest_dir);
chmod(02775, $dest_dir);
}
}
say "mv $source_file $dest_file";
rename($source_file, $dest_file) unless $dry_run;
for my $link_dir (@{ $CFG{link_dirs} }) {
my $link_file = catfile($link_dir, $episode_name);
say "ln $dest_file $link_file";
link($dest_file, $link_file) unless $dry_run;
}
$files++;
}
find({
wanted => \&find_cb,
}, $CFG{source_root});
# This is causing permission problems when called from sab, and stability
# problems if the mythtv frontend is running. Not worth it.
#if (($files > 0) && !$dry_run) {
# system(qw/ mythutil -q --scanvideos /);
#}