Skip to content
This repository has been archived by the owner on Jan 3, 2019. It is now read-only.

Commit

Permalink
Updated to get_iplayer v2.85-5-g7f31372
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Feb 2, 2014
1 parent 17ebbb9 commit d6787f6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>652</string>
<string>656</string>
<key>CFBundleShortVersionString</key>
<string>1.6.2</string>
<key>NSMainNibFile</key>
Expand Down
60 changes: 32 additions & 28 deletions get_iplayer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ package main;
#use warnings;
use Time::Local;
use URI;
use open qw(:utf8);

my %SIGORIG;
# Save default SIG actions
$SIGORIG{$_} = $SIG{$_} for keys %SIG;
Expand Down Expand Up @@ -172,7 +174,7 @@ package main;
emailpassword => [ 1, "emailpassword|email-password=s", 'Output', '--email-password <password>', "Email password"],
emailport => [ 1, "emailport|email-port=s", 'Output', '--email-port <port number>', "Email port number (default: appropriate port for --email-security)"],
emailuser => [ 1, "emailuser|email-user=s", 'Output', '--email-user <username>', "Email username"],
fatfilename => [ 1, "fatfilenames|fatfilename!", 'Output', '--fatfilename', "Omit characters forbidden by FAT filesystems from filenames but keep whitespace"],
fatfilename => [ 1, "fatfilenames|fatfilename!", 'Output', '--fatfilename', "Omit characters forbidden by FAT filesystems from file and directory names. Removes non-ASCII (accented) characters. Set by default on Windows."],
fileprefix => [ 1, "file-prefix|fileprefix=s", 'Output', '--file-prefix <format>', "The filename prefix (excluding dir and extension) using formatting fields. e.g. '<name>-<episode>-<pid>'"],
fxd => [ 1, "fxd=s", 'Output', '--fxd <file>', "Create Freevo FXD XML of matching programmes in specified file"],
html => [ 1, "html=s", 'Output', '--html <file>', "Create basic HTML index of matching programmes in specified file"],
Expand All @@ -191,7 +193,7 @@ package main;
thumbext => [ 1, "thumbext|thumb-ext=s", 'Output', '--thumb-ext <ext>', "Thumbnail filename extension to use"],
thumbsizecache => [ 1, "thumbsizecache=n", 'Output', '--thumbsizecache <index|width>', "Default thumbnail size/index to use when building cache and index (see --info for thumbnailN: to get size/index)"],
thumbsize => [ 1, "thumbsize|thumbsizemeta=n", 'Output', '--thumbsize <index|width>', "Default thumbnail size/index to use for the current recording and metadata (see --info for thumbnailN: to get size/index)"],
whitespace => [ 1, "whitespace|ws|w!", 'Output', '--whitespace, -w', "Keep whitespace (and escape chars) in filenames"],
whitespace => [ 1, "whitespace|ws|w!", 'Output', '--whitespace, -w', "Keep whitespace in file and directory names"],
xmlchannels => [ 1, "xml-channels|fxd-channels!", 'Output', '--xml-channels', "Create freevo/Mythtv menu of channels -> programme names -> episodes"],
xmlnames => [ 1, "xml-names|fxd-names!", 'Output', '--xml-names', "Create freevo/Mythtv menu of programme names -> episodes"],
xmlalpha => [ 1, "xml-alpha|fxd-alpha!", 'Output', '--xml-alpha', "Create freevo/Mythtv menu sorted alphabetically by programme name"],
Expand Down Expand Up @@ -320,6 +322,8 @@ (@)
$opt->{quiet} = 1 if $opt_pre->{quiet};
$opt->{pvr} = 1 if $opt_pre->{pvr};
$opt->{stdout} = 1 if $opt_pre->{stdout} || $opt_pre->{stream};
# force fatfilename as default on Windows
$opt->{fatfilename} = 1 if $^O eq "MSWin32";

# show version and exit
if ( $opt_pre->{showver} ) {
Expand Down Expand Up @@ -555,9 +559,6 @@ (@)
}
}

# force fatfilename with whitespace on Windows
$opt->{fatfilename} = 1 if ( $opt->{whitespace} && $^O eq "MSWin32" );

# Add --search option to @search_args if specified
if ( defined $opt->{search} ) {
push @search_args, $opt->{search};
Expand Down Expand Up @@ -2608,9 +2609,10 @@ sub request_url_retry {

# Only return decoded content if gzip is used - otherwise this severely slows down stco scanning! Perl bug?
main::logger "DEBUG: ".($res->header('Content-Encoding') || 'No')." Encoding used on $url\n" if $opt->{debug};
return $res->decoded_content if defined $res->header('Content-Encoding') && $res->header('Content-Encoding') eq 'gzip';

return $res->content;
# this appears to be obsolete
# return $res->decoded_content if defined $res->header('Content-Encoding') && $res->header('Content-Encoding') eq 'gzip';
# return $res->content;
return $res->decoded_content;
}


Expand Down Expand Up @@ -2865,22 +2867,24 @@ sub cleanup {


# Generic
# Make a filename/path sane (optionally allow fwd slashes)
# Make a filename/path sane
sub StringUtils::sanitize_path {
my $string = shift;
my $allow_fwd_slash = shift || 0;

# Remove fwd slash if reqd
$string =~ s/\//_/g if ! $allow_fwd_slash;

# Replace backslashes with _ regardless
$string =~ s/\\/_/g;
# Sanitize by default
$string =~ s/\s+/_/g if (! $opt->{whitespace}) && (! $allow_fwd_slash);
$string =~ s/[^\w_\-\.\/\s]//gi if ! $opt->{whitespace};
$string =~ s/[\|\\\?\*\<\"\:\>\+\[\]\/]//gi if $opt->{fatfilename};
# Truncate multiple '_'
my $is_path = shift || 0;
# Replace forward slashes with _ if not path
$string =~ s/\//_/g unless $is_path;
# Replace backslashes with _ if not Windows path
$string =~ s/\\/_/g unless $^O eq "MSWin32" && $is_path;
# Remove extra/leading/trailing whitespace
$string =~ s/\s+/ /g;
$string =~ s/(^\s+|\s+$)//g;
# Replace whitespace with _ if required
$string =~ s/\s+/_/g unless $opt->{whitespace};
# Truncate multiple replacement chars
$string =~ s/_+/_/g;
# Remove non-ASCII and forbidden chars if required
$string =~ s/[^\x{20}-\x{7E}]//g if $opt->{fatfilename};
$string =~ s/[\|\?\*\+\"\:\<\>\[\]]//g if $opt->{fatfilename};
return $string;
}

Expand Down Expand Up @@ -3627,7 +3631,7 @@ sub add {
return 0 if $opt->{nowrite};

# Add to history
if ( ! open(HIST, ">>:utf8", $historyfile) ) {
if ( ! open(HIST, ">> $historyfile") ) {
main::logger "ERROR: Cannot write or append to $historyfile\n";
exit 11;
}
Expand Down Expand Up @@ -4532,8 +4536,8 @@ sub create_metadata_file {

# Usage: print $prog{$pid}->substitute('<name>-<pid>-<episode>', [mode], [begin regex tag], [end regex tag]);
# Return a string with formatting fields substituted for a given pid
# sanitize_mode == 0 then sanitize final string but dont sanitize '/' in field values
# sanitize_mode == 1 then sanitize final string and also sanitize '/' in field values
# sanitize_mode == 0 then sanitize final string and also sanitize '/' in field values
# sanitize_mode == 1 then sanitize final string but don't sanitize '/' (and '\' on Windows) in field values
# sanitize_mode == 2 then just substitute only
# sanitize_mode == 3 then substitute then use encode entities for fields only
# sanitize_mode == 4 then substitute then escape characters in fields only for use in double-quoted shell text.
Expand Down Expand Up @@ -4606,8 +4610,9 @@ sub substitute {
$string =~ s/[\s_]+/_/g if ! $opt->{whitespace};
# Strip leading ellipsis
$string =~ s/^\.+/_/;
# Remove/replace all non-nice-filename chars if required except for fwd slashes
return StringUtils::sanitize_path( $string, 1 );
# Remove/replace all non-nice-filename chars if required
# Keep '/' (and '\' on Windows) if $sanitize_mode == 1
return StringUtils::sanitize_path( $string, $sanitize_mode );
} else {
return $string;
}
Expand Down Expand Up @@ -4694,7 +4699,7 @@ sub generate_filenames {
# Don't create subdir if we are only testing recordings
# Create a subdir for programme sorting option
if ( $opt->{subdir} ) {
my $subdir = $prog->substitute( $opt->{subdirformat} || '<longname>' );
my $subdir = $prog->substitute( $opt->{subdirformat} || '<longname>', 1 );
$prog->{dir} = File::Spec->catdir($prog->{dir}, $subdir);
main::logger("INFO: Creating subdirectory $prog->{dir} for programme\n") if $opt->{verbose};
}
Expand Down Expand Up @@ -7193,7 +7198,6 @@ sub download_subtitles {
# Open subs file
unlink($file);
open( my $fh, "> $file" );
binmode($fh, ":utf8");
# Download subs
$subs = main::request_url_retry($ua, $suburl, 2);
Expand Down

0 comments on commit d6787f6

Please sign in to comment.