Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use the IMDBAPI to get data from IMDB. Fixes getting film data, but u…

…nfortunately does not seem to return episode data.
  • Loading branch information...
commit 453c25cdbb288f50c88ffe4807fa59977930da97 1 parent 7003f45
@andrewrjones authored
View
1  Changes
@@ -1,4 +1,5 @@
{{$NEXT}}
+ Use the IMDBAPI to get data from IMDB. Fixes getting film data, but unfortunately does not seem to return episode data.
1.122800 2012-10-06 18:51:06 Europe/London
POD fixes.
View
8 lib/App/MP4Meta/Command/tv.pm
@@ -10,8 +10,6 @@ use App::MP4Meta -command;
use Try::Tiny;
-#use Term::ProgressBar::Simple;
-
=head1 SYNOPSIS
mp4meta tv THE_MIGHTY_BOOSH_S1E1.m4v THE_MIGHTY_BOOSH_S1E2.m4v
@@ -46,11 +44,7 @@ sub opt_spec {
return (
[ "genre=s", "The genre of the TV Show" ],
[ "coverfile=s", "The location of the cover image" ],
- [
- "sources=s@",
- "The sources to search",
- { default => [qw/TVDB IMDB/] }
- ],
+ [ "sources=s@", "The sources to search", { default => [qw/TVDB/] } ],
[ "title=s", "The title of the TV Show" ],
[ "series=s", "The series number" ],
[ "episode=s", "The episode number" ],
View
116 lib/App/MP4Meta/Source/IMDB.pm
@@ -4,19 +4,29 @@ use warnings;
package App::MP4Meta::Source::IMDB;
-# ABSTRACT: Contains data for a TV Episode.
+# ABSTRACT: Fetches film data from the IMDB.
use App::MP4Meta::Source::Base;
our @ISA = 'App::MP4Meta::Source::Base';
-use App::MP4Meta::Source::Data::TVEpisode;
+use App::MP4Meta::Source::Data::Film;
-use IMDB::Film 0.52;
+use WebService::IMDBAPI;
use File::Temp ();
use LWP::Simple ();
use constant NAME => 'IMDB';
+sub new {
+ my $class = shift;
+ my $args = shift;
+ my $self = $class->SUPER::new($args);
+
+ $self->{imdb} = WebService::IMDBAPI->new();
+
+ return $self;
+}
+
sub name {
return NAME;
}
@@ -26,99 +36,31 @@ sub get_film {
$self->SUPER::get_film($args);
- # film data
- my $title;
- my $overview;
- my $genre;
- my $year;
- my $cover_file;
-
- my $imdb = $self->_search_imdb( $args->{title}, $args->{year} );
-
- # get genre
- my @genres = @{ $imdb->genres };
- $genre = $genres[0];
+ my $result = $self->{imdb}->search_by_title(
+ $args->{title},
+ {
+ year => $args->{year},
+ limit => 1,
+ episode => 0
+ }
+ )->[0];
# get cover file
- unless ($cover_file) {
- $cover_file = $self->_get_cover_file( $imdb->cover );
- }
-
- return App::MP4Meta::Source::Data::Film->new(
- overview => $imdb->storyline,
- title => $imdb->title,
- genre => $genre,
- cover => $cover_file,
- year => $imdb->year,
- );
-}
-
-sub get_tv_episode {
- my ( $self, $args ) = @_;
-
- $self->SUPER::get_tv_episode($args);
-
- # episode data
- my $title;
- my $overview;
- my $genre;
- my $year;
+ # FIXME: never set
my $cover_file;
-
- # do the search
- # TODO: how can I mock?
- my $imdb = $self->_search_imdb( $args->{show_title}, $args->{year} );
-
- my @episodes = @{ $imdb->episodes() };
-
- # get genre
- my @genres = @{ $imdb->genres };
- $genre = $genres[0];
-
- # get cover file
unless ($cover_file) {
- $cover_file = $self->_get_cover_file( $imdb->cover );
+ $cover_file = $self->_get_cover_file( $result->poster );
}
- # get the episode
- ( $title, $overview, $year ) =
- $self->_get_episode_data( \@episodes, $args->{season}, $args->{episode} );
-
- return App::MP4Meta::Source::Data::TVEpisode->new(
- overview => $overview,
- title => $title,
- genre => $genre,
+ return App::MP4Meta::Source::Data::Film->new(
+ overview => $result->plot_simple,
+ title => $result->title,
+ genre => $result->genres->[0],
cover => $cover_file,
- year => $year,
+ year => $result->year,
);
}
-# search on the IMDB
-sub _search_imdb {
- my ( $self, $title, $year ) = @_;
-
- my $imdb = IMDB::Film->new( crit => $title, year => $year, cache => 1 );
- die 'no data found' unless $imdb->status;
-
- return $imdb;
-}
-
-# get the episode data from the episodes array
-sub _get_episode_data {
- my ( $self, $episodes, $season, $episode ) = @_;
-
- for my $e ( @{$episodes} ) {
- if ( $e->{season} == $season && $e->{episode} == $episode ) {
- my $year;
- if ( $e->{date} =~ /(\d{4})$/ ) {
- $year = $1;
- }
- return ( $e->{title}, $e->{plot}, $year );
- }
- }
- return;
-}
-
# gets the cover file for the season and returns the filename
# also stores in cache
sub _get_cover_file {
@@ -138,6 +80,8 @@ sub _get_cover_file {
1;
+__END__
+
=method name()
Returns the name of this source.
View
4 lib/App/MP4Meta/Source/TVDB.pm
@@ -106,6 +106,8 @@ sub _get_cover_file {
1;
+__END__
+
=method new()
Create a new object. Takes no arguments
@@ -113,3 +115,5 @@ Create a new object. Takes no arguments
=method name()
Returns the name of this source.
+
+=cut
View
20 t/lib/Test/App/MP4Meta/Source/IMDB.pm
@@ -25,26 +25,6 @@ sub name : Test(1) {
is( $i->name, 'IMDB' );
}
-sub live_tv_episode : Test(6) {
- my $self = shift;
-
- return 'no live testing' unless $self->can_live_test();
-
- my $i = $self->{imdb};
-
- my $f = $i->get_tv_episode(
- { show_title => 'Extras', season => 1, episode => 1 } );
-
- isa_ok( $f, 'App::MP4Meta::Source::Data::TVEpisode' );
- ok( $f->overview, 'got overview' ); # assume its sensible
- is( $f->title, 'Ben Stiller', 'got title' );
- is( $f->year, 2005, 'got year' );
- is( $f->genre, 'Comedy', 'got comedy' );
-
- local $TODO = 'can not currently get cover image for TV series from IMDB';
- like( $f->cover, qr/\.jpg$/, 'got cover image' );
-}
-
sub live_film : Test(6) {
my $self = shift;
View
34 t/lib/Test/App/MP4Meta/TV.pm
@@ -54,40 +54,6 @@ sub live_apply_meta_tvdb_default : Test(12) {
like( $tags->artwork, qr/\.jpg$/, 'artwork' );
}
-sub live_apply_meta_imdb_default : Test(12) {
- my $self = shift;
-
- return 'no live testing' unless $self->can_live_test();
-
- my $path = 'Heroes.S01E01';
- my $t = App::MP4Meta::TV->new( { sources => ['IMDB'] } );
- my $mock = $self->mock_ap();
- $t->{ap} = $mock;
-
- my $result = $t->apply_meta($path);
- ok( !$result );
-
- # check we called AP correctly
- my ( $name, $args ) = $mock->next_call();
- my $write_path = $args->[1];
- my $tags = $args->[2];
-
- is( $name, 'write_tags' );
- is( $write_path, $path );
-
- isa_ok( $tags, 'AtomicParsley::Command::Tags' );
- is( $tags->TVEpisode, 1, 'episode num' );
- is( $tags->artist, 'Heroes', 'artist' );
- is( $tags->album, 'Heroes, Season 1', 'album' );
- is( $tags->title, 'Chapter One \'Genesis\'', 'title' );
- is( $tags->genre, 'Drama', 'genre' );
- is( $tags->year, '2006', 'year' );
- ok( $tags->description, 'description' );
-
- local $TODO = 'can not currently get cover image for TV series from IMDB';
- like( $tags->artwork, qr/\.jpg$/, 'artwork' );
-}
-
sub apply_meta_set_title : Test(9) {
my $self = shift;
Please sign in to comment.
Something went wrong with that request. Please try again.