Skip Menu |

This queue is for tickets about the MP3-PodcastFetch CPAN distribution.

Report information
The Basics
Id: 56306
Status: resolved
Priority: 0/
Queue: MP3-PodcastFetch

People
Owner: Nobody in particular
Requestors: andrew [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.04
Fixed in: (no value)



Subject: filenames are not url_decode'd
When downloading a file that is URL Encoded, with rewrite_filename not set, it doesn't decode the name, so you end up with files named "test%203.mp3" when they should be named "test 3.mp3". For the new tests to pass you need to cp "t/data/test2.mp3" "t/data/test 3.mp3" http://8bitcollective.com/rss/music
Subject: url_decode.patch
diff --git a/Build.PL b/Build.PL index bceaa69..b3d18fc 100644 --- a/Build.PL +++ b/Build.PL @@ -10,6 +10,7 @@ my $build = Module::Build->new( 'Date::Parse' => '2.20', 'HTML::Parser' => '3.50', 'Config::IniFiles' => '2.00', + 'URI::Escape' => 0, }, PL_files => { 'bin/fetch_pods.PLS' => 'bin/fetch_pods.pl', diff --git a/META.yml b/META.yml index 417d5c0..a0d3c75 100644 --- a/META.yml +++ b/META.yml @@ -1,6 +1,6 @@ --- name: MP3-PodcastFetch -version: 1.04 +version: 1.05_01 author: - Lincoln Stein E<lt>lstein@cshl.orgE<gt>. abstract: 'This is a library of tools for managing podcast subscriptions. It comes with a command-line tool, fetch_pods.pl, that can run under Cron to keep a directory of subscribed Podcasts feeds up to date.' @@ -12,11 +12,14 @@ requires: Date::Parse: 2.20 HTML::Parser: 3.50 LWP: 5.8 - perl: 5.8.0 + URI::Escape: 0 + perl: v5.8.0 +configure_requires: + Module::Build: 0.340201 provides: MP3::PodcastFetch: file: lib/MP3/PodcastFetch.pm - version: 1.04 + version: 1.05_01 MP3::PodcastFetch::Feed: file: lib/MP3/PodcastFetch/Feed.pm MP3::PodcastFetch::Feed::Channel: @@ -27,7 +30,7 @@ provides: file: lib/MP3/PodcastFetch/TagManager.pm MP3::PodcastFetch::XML::SimpleParser: file: lib/MP3/PodcastFetch/XML/SimpleParser.pm -generated_by: Module::Build version 0.3 +generated_by: Module::Build version 0.340201 meta-spec: - url: http://module-build.sourceforge.net/META-spec-v1.2.html - version: 1.2 + url: http://module-build.sourceforge.net/META-spec-v1.4.html + version: 1.4 diff --git a/lib/MP3/PodcastFetch.pm b/lib/MP3/PodcastFetch.pm index 6a9a078..a2a1499 100644 --- a/lib/MP3/PodcastFetch.pm +++ b/lib/MP3/PodcastFetch.pm @@ -8,6 +8,7 @@ use MP3::PodcastFetch::TagManager; use LWP::UserAgent; use HTTP::Status; +use URI::Escape; use File::Spec; use File::Basename 'basename'; @@ -17,7 +18,7 @@ use Digest::MD5 qw(md5_hex); use Date::Parse; use Cwd; -our $VERSION = '1.04'; +our $VERSION = '1.05_01'; =head1 NAME @@ -818,7 +819,7 @@ sub make_filename { $name .= ".$extension" if defined $extension; return $name; } else { - return basename($url); + return uri_unescape( basename($url) ); } } diff --git a/t/01.basic.t b/t/01.basic.t index 0352fdd..422117a 100644 --- a/t/01.basic.t +++ b/t/01.basic.t @@ -5,66 +5,87 @@ use strict; use warnings; -use Module::Build; -use File::Path 'rmtree'; + use FindBin '$Bin'; use File::Spec; use File::Temp qw(tempdir); -use lib "$Bin/../lib"; -use constant TEST_COUNT => 12; -use constant RSS_FILE => "$Bin/data/test.xml"; +my $DATA_DIR = File::Spec->catdir( $Bin, 'data' ); +my $RSS_FILE = File::Spec->catfile( $DATA_DIR, 'test.xml' ); BEGIN { - use Test; - plan test => TEST_COUNT; + use Test::More tests => 28; } use MP3::PodcastFetch; +my @tests = ( + { config => { + -rewrite_filename => 1, + -upgrade_tag => 0, + -verbose => 0, + -mirror_mode => 'exists', + }, + files => [ 'Test_File_1.mp3', 'Test_File_2.mp3', 'Test_File_3.mp3', ], + }, + { config => { + -rewrite_filename => 0, + -upgrade_tag => 0, + -verbose => 0, + -mirror_mode => 'exists', + }, + files => [ 'test1.mp3', 'test2.mp3', 'test 3.mp3', ], + }, +); + chdir $Bin; -my $tempdir = tempdir(CLEANUP=>1); -my $rss = File::Spec->catfile($tempdir,"test.xml"); - -# we need to create a temporary XML file in which paths are correct -open IN,RSS_FILE or die $!; -open OUT,">",$rss or die $!; -while (<IN>) { - s!\$PATH!file://$Bin/data!g; - print OUT; -} -close IN; -close OUT; -my $base = File::Spec->catfile($tempdir,'podcasts'); +foreach my $test (@tests) { + my $tempdir = tempdir( CLEANUP => 1 ); + my $base = File::Spec->catdir( $tempdir, 'podcasts' ); + my $rss = File::Spec->catfile( $tempdir, "test.xml" ); -my $feed = make_feed($base,$rss); -ok($feed); -ok($feed->fetch_pods); -ok($feed->fetched,2); -ok($feed->skipped,0); + my %config = %{ $test->{config} }; + $config{'-base'} = $base; + $config{'-rss'} = 'file://' . $rss; -my @fetched = $feed->fetched_files; -ok(@fetched == 2); + my @expect_files = sort @{ $test->{files} }; + my $file_count = @expect_files; -$feed = make_feed($base,$rss); -ok($feed->fetch_pods); -ok($feed->fetched,0); -ok($feed->skipped,2); -ok(-d $base); -ok(-d File::Spec->catfile($base,'MP3PodcastFetch')); -ok(-e File::Spec->catfile($base,'MP3PodcastFetch','Test_File_1.mp3')); -ok(-e File::Spec->catfile($base,'MP3PodcastFetch','Test_File_2.mp3')); + # we need to create a temporary XML file in which paths are correct + open my $IN, $RSS_FILE or die $!; + open my $OUT, ">", $rss or die $!; + while (<$IN>) { + s!\$PATH!file://$DATA_DIR!g; + print $OUT $_; + } + close $IN; + close $OUT; -exit 0; + my $feed = MP3::PodcastFetch->new(%config); + ok( $feed, 'created feed' ); + ok( $feed->fetch_pods, 'fetched pods' ); + is( $feed->fetched, $file_count, "fetched $file_count" ); + is( $feed->skipped, 0, 'skipped 0' ); + + my @files; + ok( @files = $feed->fetched_files, 'files we fetched' ); + @files = map { ( File::Spec->splitpath($_) )[-1] } @files; + is_deeply( \@files, \@expect_files, 'got correct files' ); -sub make_feed { - my ($base,$rss) = @_; - return MP3::PodcastFetch->new(-base => $base, - -rss => "file://$rss", - -rewrite_filename => 1, - -upgrade_tag => 'auto', - -verbose => 0, - -mirror_mode => 'exists', - ); + ok( -d $base, 'basedir exists' ); + ok( -d File::Spec->catfile( $base, 'MP3PodcastFetch' ), + 'feed dir exists' ); + + foreach my $f ( @{ $test->{files} } ) { + my $file = File::Spec->catfile( $base, 'MP3PodcastFetch', $f ); + ok( -e $file, "$f exists" ); + } + + $feed = MP3::PodcastFetch->new(%config); + ok( $feed->fetch_pods, 'refetch pods' ); + is( $feed->fetched, 0, 'fetched 0' ); + is( $feed->skipped, $file_count, "skipped $file_count" ); } + +exit 0; diff --git a/t/data/test.xml b/t/data/test.xml index d7bedda..1997adb 100644 --- a/t/data/test.xml +++ b/t/data/test.xml @@ -25,5 +25,14 @@ <itunes:duration>0:00:03</itunes:duration> <enclosure url="$PATH/test2.mp3" type="audio/mpeg"/> </item> + <item> + <title>Test File 3</title> + <description>Test File 3 Description</description> + <pubDate>Sun Dec 31 15:59:22 EST 2006</pubDate> + <link>http://www.perl.org/item/3</link> + <guid>http://www.perl.org/item/3</guid> + <itunes:duration>0:00:03</itunes:duration> + <enclosure url="$PATH/test%203.mp3" type="audio/mpeg"/> + </item> </channel> </rss>
Patch included in version 1.05.