-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkallvideos
executable file
·78 lines (60 loc) · 1.66 KB
/
mkallvideos
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
77
78
#!/usr/bin/env perl
use File::Path qw(make_path remove_tree);
use File::Find;
use File::Basename;
my @videoExtensions = qw(mov avi webm mp4 m4v mkv 3gp wmv flv vob ogv iso qt rm asf mpg mpeg mpv);
my @videoExtensionsUC = @videoExtensions;
tr/[a-z]/[A-Z]/ foreach (@videoExtensionsUC);
push(@videoExtensions, @videoExtensionsUC);
# prepend "."
for(@videoExtensions) {
s/^/./;
}
my $all="+all-videos";
chomp(my $rootDir = `pwd`);
# remove existing "+all-videos"
my $rmCount = remove_tree($all);
# create new "+all-videos"
@dirs = make_path($all);
if(scalar @dirs == 0) {
warn "Unable to create $all: $?\n";
exit(1);
}
find(\&filterVideos, '.');
sub filterVideos {
if($File::Find::name eq $all) {
$File::Find::prune=1;
return;
}
my ($ignored1, $ignored2, $ext) = fileparse($File::Find::name, @videoExtensions);
# skip extension-less
return unless length($ext);
# skip unreadable and directories
return if(! -r || -d);
# print "# 1 $File::Find::name\n";
my $path = $File::Find::dir;
# strip trailing /
$path =~ s#/$##;
# strip leading "./"
$path =~ s#^\.\/##;
my $dest = "$all/$path/$_";
my $destDir = "$all/$path";
# print "# \--> $dest\n";
# check for existing destination file
if(-r $dest) {
# print "## exists: $dest (from $path)\n";
return;
}
# print "# 2 $File::Find::name\n";
unless($path eq "" || $path eq "." || -d "$rootDir/$destDir") {
unless(make_path("$rootDir/$destDir") > 0) {
# failed to create directory
# print "exists!" if -d "$rootDir/$destDir";
return;
}
print "# $path\n";
}
# print "# 3 $File::Find::name\n";
# make hard link from src to dest
link($_, "$rootDir/$destDir/$_") || warn "Unable to link $_: $!\n";
}