Commit 4f5580f3 authored by Joakim Nylén's avatar Joakim Nylén

Merge branch 'master' of gitlab.com:xmltv-se/nonametv

parents 4fbe45ce 8d64729d
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
use 5.010;
use strict;
use warnings;
use URI::Encode;
package OMDB::API;
# ABSTRACT: Interface to http://www.omdbapi.com/
use LWP::UserAgent;
use JSON;
use constant BASE_URL => 'http://www.omdbapi.com/';
sub search {
my ( $s, $options ) = @_;
die "search string is required" unless $s;
my $response = _get( 's', $s, $options );
if ( $response->is_success ) {
my $content = decode_json( $response->content );
return $content->{Search};
}
else {
die $response->status_line;
}
}
sub id {
my ( $i, $options ) = @_;
die "id is required" unless $i;
my $response = _get( 'i', $i, $options );
if ( $response->is_success ) {
my $content = decode_json( $response->content );
return $content;
}
else {
die $response->status_line;
}
}
sub title {
my ( $t, $options ) = @_;
die "title is required" unless $t;
my $response = _get( 't', $t, $options );
if ( $response->is_success ) {
my $content = decode_json( $response->content );
return $content;
}
else {
die $response->status_line;
}
}
sub _get {
my ( $search_param, $search_term, $options ) = @_;
my $url = _generate_url( $search_param, $search_term, $options );
my $ua = LWP::UserAgent->new();
$ua->agent( $options->{user_agent} ) if $options->{user_agent};
return $ua->get($url);
}
# generates a url from the options
sub _generate_url {
my ( $search_param, $search_term, $options ) = @_;
my $url = sprintf( "%s?%s=%s", BASE_URL, $search_param, $search_term );
while ( my ( $key, $value ) = each(%$options) ) {
$url .= sprintf( "&%s=%s", $key, $value // 0 );
}
$url = URI::Encode->new()->encode($url);
print("url: $url\n");
return $url;
}
1;
__END__
=head1 SYNOPSIS
my $search_results = WebService::OMDB::search('The Geen Mile');
# returns...
[
{
'Year' => '1999',
'Type' => 'movie',
'imdbID' => 'tt0120689',
'Title' => 'The Green Mile'
},
{
'Year' => '1999',
'Type' => 'movie',
'imdbID' => 'tt0338255',
'Title' => 'The Miracle of \'The Green Mile\''
},
{
'Year' => '2006',
'Type' => 'movie',
'imdbID' => 'tt0960803',
'Title' => 'Miracles and Mystery: Creating \'The Green Mile\''
},
{
'Year' => '2009',
'Type' => 'episode',
'imdbID' => 'tt1903167',
'Title' => 'The Green Mile'
}
];
my $id_result = WebService::OMDB::id('tt0120689');
# returns...
{
'Director' => 'Frank Darabont',
'imdbID' => 'tt0120689',
'Poster' => '...',
'Actors' => 'Tom Hanks, David Morse, Michael Clarke Duncan, Bonnie Hunt',
'Metascore' => '61',
'imdbRating' => '8.5',
'imdbVotes' => '477,025',
'Released' => '10 Dec 1999',
'Awards' => 'Nominated for 4 Oscars. Another 15 wins & 23 nominations.',
'Title' => 'The Green Mile',
'Plot' => 'The lives of guards on Death Row are affected by one of their charges: a black man accused of child murder and rape, yet who has a mysterious gift.',
'Year' => '1999',
'Rated' => 'R',
'Writer' => 'Stephen King (novel), Frank Darabont (screenplay)',
'Type' => 'movie',
'Runtime' => '189 min',
'Genre' => 'Crime, Drama, Fantasy',
'Language' => 'English, French',
'Response' => 'True',
'Country' => 'USA'
};
my $title_result = WebService::OMDB::title('The Green Mile');
# returns the same as id
=head1 DESCRIPTION
WebService::OMDB is an interface to L<http://www.omdbapi.com/>.
=cut
=method search( $search_term, $options )
Searches based on the title. Returns an array of results.
=over 4
=item search_term
String. Required.
=item options
The options shown at L<http://www.omdbapi.com/>. Hash reference. Optional.
=back
=method id( $id )
Gets a result based on the IMDB id. Returns a single result.
=over 4
=item id
String. Required.
=item options
The options shown at L<http://www.omdbapi.com/>. Hash reference. Optional.
=back
=method title( $title )
Gets a result based on the title. Returns a single result.
=over 4
=item title
String. Required.
=item options
The options shown at L<http://www.omdbapi.com/>. Hash reference. Optional.
=back
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment