[PATCH] Ensure output file extension changes with download mode

dinkypumpkin dinkypumpkin at gmail.com
Thu Apr 7 16:44:48 EDT 2011


This patch originated from the thread that begins here:

http://lists.infradead.org/pipermail/get_iplayer/2011-April/001267.html

This patch addresses a very occasional problem (described in the commit
message below) that crops up when iPlayer streams fail to start, e.g., 
because of erroneous metadata or inability to contact CDN servers because
of DNS problems, etc.  There are workarounds given here:

http://lists.infradead.org/pipermail/get_iplayer/2011-April/001277.html

but I also thought it would be worth fixing get_iplayer to handle this
situation automatically.

Updated get_iplayer script here:

https://github.com/dinkypumpkin/get_iplayer/raw/patched/get_iplayer

Commit history here:

https://github.com/dinkypumpkin/get_iplayer/commits/patched/

Patch follows -

If a download fails to start, e.g., because iPlayer metadata is bad,
get_iplayer will try the next available mode that matches the user's
mode preferences.  However, even if the second mode produces an output
file with a different format, the output file will be written with the
file extension appropriate for the first, failed mode.  For example, with:
radiomode=flashaudio,flashaac if the flashaudio stream fails to start,
the flashaac stream will be used.  However, the resulting AAC file will
still be written with a .mp3 extension.  This patch checks for changes
to the extension of output files and ensures the file name is altered
if necessary.
---
 get_iplayer |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/get_iplayer b/get_iplayer
index 3d68865..40e1602 100755
--- a/get_iplayer
+++ b/get_iplayer
@@ -4647,8 +4647,16 @@ sub generate_filenames {
 	# Use a dummy file ext if one isn't set - helps with readability of metadata
 	$prog->{ext} = 'EXT' if ! $prog->{ext};
 	
+	# check if file extension has changed as a result of failed attempt with different mode
+	my $ext_changed = 0;
+	if ( ! $opt->{history} && ! $opt->{multimode} && defined $prog->{filename} && $prog->{filename} ne '' ) {
+		my ($dir, $fileprefix, $ext) = ( $1, $3, $4 ) if $prog->{filename} =~ m{^((.*)[\//]+)?([^\//]+?)\.(\w+)$};
+		$ext_changed = ( defined $ext && $ext ne '' && $ext ne $prog->{ext} );
+		main::logger "DEBUG: File ext changed:   $ext -> $prog->{ext}\n" if $ext_changed && $opt->{debug};
+	}
+
 	# Don't override the {filename} if it is already set (i.e. for history info) or unless multimode option is specified
-	$prog->{filename} = "$prog->{dir}/$prog->{fileprefix}.$prog->{ext}" if ( defined $prog->{filename} && $prog->{filename} =~ /\.EXT$/ ) || $opt->{multimode} || ! $prog->{filename};
+	$prog->{filename} = "$prog->{dir}/$prog->{fileprefix}.$prog->{ext}" if ( defined $prog->{filename} && $prog->{filename} =~ /\.EXT$/ ) || $opt->{multimode} || ! $prog->{filename} || $ext_changed;
 	$prog->{filepart} = "$prog->{dir}/$prog->{fileprefix}.partial.$prog->{ext}";
 
 	# Create symlink filename if required
@@ -6941,7 +6949,6 @@ sub download {
 		$prog->download_subtitles( $ua, $subfile );
 	}
 
-
 	my $return = 0;
 	# Only get the stream if we are writing a file or streaming
 	if ( $opt->{stdout} || ! $opt->{nowrite} ) {
-- 
1.7.4.3




More information about the get_iplayer mailing list