-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiso2episodes.pl
executable file
·100 lines (80 loc) · 2.96 KB
/
iso2episodes.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#/usr/bin/perl -w
use Data::Dumper;
if (@ARGV == undef) {
print <<USAGE;
Usage: iso2episodes.pl <filename>
Edit script to change subtitles options, encoding profiles, ....
DESCRIPTION
Ever encountered the situation where you wanted to download some episodes but all you could find were ISO images?
This script will take an iso, use the lsdvd util to turn its info into a perl data structure and then use the CLI version
of HandBrake to encode the tracks longer than $minepisodelengthminutes. You can specify multiple HandBrake encoding profiles
in the config section, as well as multiple subtitle languages to include as subtitle tracks in the mp4.
DEPENDENCIES:
lsdvd ->
$ sudo apt-get install lsdvd
HandBrakeCLI ->
Download from site, compile from source...
USAGE
exit;
}
### Config section ####
#my @encoding_profiles = ("High Profile","Android Mid","Normal");
my @encoding_profiles = ("Android Mid");
my %wanted_subs_language = map {$_,1} ("Nederlands","English");
my $handbrake = `which HandBrakeCLI`;
chomp $handbrake;
#my @handbrakeoptions = ('-N nld');
my $minepisodelengthminutes = 20; # minimum episode length in minutes..any track longer than this will be encoded
########### End Config section ###########
my $filename = shift @ARGV;
chomp($filename);
print "Selected filename:",$filename,"\n";
print "Handbrake location:",$handbrake,"\n";
my $dvdinfo = `lsdvd -a -s -Op $filename`;
eval $dvdinfo;
if ($@) {
print $@;
}
else {
@selected_tracks = ();
%selected_subp_tracks;
foreach $track (@{$lsdvd{'track'}}) {
print "Track ID:", $track->{'ix'}," Length:",$track->{'length'};
print " ----> Minutes:",$track->{'length'}/60;
if ($track->{'length'}/60 > $minepisodelengthminutes){
print " (Selected)","\n";
push @selected_tracks, $track->{'ix'};
my $tracknr = $track->{'ix'};
foreach $subp (@{$track->{'subp'}}) {
print "\t\tSubtitle language:",$subp->{'language'};
if ($wanted_subs_language{$subp->{'language'}}) {
print " (Selected) Index:",$subp->{'ix'},"\n";
$selected_subp_tracks{"t$tracknr"}->{$subp->{'language'}} = $subp->{'ix'} unless $selected_subp_tracks{"t$tracknr"}->{$subp->{'language'}};
}
else {
print "\n";
}
}
}
print "\n";
}
}
print "Selected tracks: ", @selected_tracks, "\n";
#print Dumper(\%selected_subp_tracks);
foreach $tracknr (@selected_tracks) {
my @subtracks;
foreach $langtrack (keys %{$selected_subp_tracks{"t$tracknr"}})
{
# print "Language subtitle track: ",$selected_subp_tracks{"t$tracknr"}," ",$selected_subp_tracks{"t$tracknr"}{$langtrack},"\n";
push @subtracks, $selected_subp_tracks{"t$tracknr"}{$langtrack};
}
my $subtracks = join(',',@subtracks);
print "Subtracks: ", $subtracks,"\n";
foreach $encprof (@encoding_profiles) {
$profilemidfix = lc($encprof);
$profilemidfix =~ s/ //g;
#print $profilemidfix,"\n";
# print @{$selected_subp_tracks{t$tracknr}};
system("$handbrake -i $filename -o $filename.Title$tracknr.$profilemidfix.mp4 -t $tracknr -s $subtracks -Z \"$encprof\"");
}
}