diff --git a/.author/_pod_helpers/synopsis.pl b/.author/_pod_helpers/synopsis.pl index c58d619..af4e493 100644 --- a/.author/_pod_helpers/synopsis.pl +++ b/.author/_pod_helpers/synopsis.pl @@ -109,6 +109,15 @@ my @results = $search->collection('Star Wars'); # Search for collections my @results = $search->list('top 250'); # Search lists +# Discover +my @results = $search->discover( + { + sort_by => 'popularity.asc', + 'vote_average.gte' => '7.2', + 'vote_count.gte' => '10', + } +); + # Get Lists my $lists = $tmdb->search(); my $latest = $lists->latest(); # Latest movie added to TheMovieDB diff --git a/.author/_tests/00_test.pl b/.author/_tests/00_test.pl index 786c0f8..266246b 100755 --- a/.author/_tests/00_test.pl +++ b/.author/_tests/00_test.pl @@ -41,8 +41,9 @@ a => 0, # All cm => 0, # Company g => 0, # Genre + d => 0, # Discover ); -GetOptions( \%opts, 'c', 'm', 's', 'p', 'a', 'cm', 'g', ) +GetOptions( \%opts, 'c', 'm', 's', 'p', 'a', 'cm', 'g', 'd', ) or die "Invalid Options"; if ( $opts{a} ) { @@ -130,6 +131,24 @@ ); } ## end if ( $opts{s} ) +#################### +# DISCOVER +#################### +if ( $opts{d} ) { + _dump( + o => [ + $tmdb->search->discover( + { + sort_by => 'popularity.asc', + 'vote_average.gte' => '7.2', + 'vote_count.gte' => '10', + } + ) + ], + m => 'Discover Movies', + ); +} ## end if ( $opts{d} ) + #################### # MOVIE #################### diff --git a/lib/TMDB.pm b/lib/TMDB.pm index 1212c5a..5fbd73c 100644 --- a/lib/TMDB.pm +++ b/lib/TMDB.pm @@ -232,6 +232,15 @@ L for more details. my @results = $search->collection('Star Wars'); # Search for collections my @results = $search->list('top 250'); # Search lists + # Discover + my @results = $search->discover( + { + sort_by => 'popularity.asc', + 'vote_average.gte' => '7.2', + 'vote_count.gte' => '10', + } + ); + # Get Lists my $lists = $tmdb->search(); my $latest = $lists->latest(); # Latest movie added to TheMovieDB diff --git a/lib/TMDB/Search.pm b/lib/TMDB/Search.pm index 193aea8..1858a89 100644 --- a/lib/TMDB/Search.pm +++ b/lib/TMDB/Search.pm @@ -256,6 +256,81 @@ sub latest_person { ); } ## end sub latest_person +####################### +# DISCOVER +####################### +sub discover { + my ( $self, @args ) = @_; + my %options = validate_with( + params => [@args], + spec => { + sort_by => { + type => SCALAR, + optional => 1, + default => 'popularity.asc', + callbacks => { + 'valid flag' => sub { + ( lc $_[0] eq 'vote_average.desc' ) + or ( lc $_[0] eq 'vote_average.asc' ) + or ( lc $_[0] eq 'release_date.desc' ) + or ( lc $_[0] eq 'release_date.asc' ) + or ( lc $_[0] eq 'popularity.desc' ) + or ( lc $_[0] eq 'popularity.asc' ); + }, + }, + }, + year => { + type => SCALAR, + optional => 1, + regex => qr/^\d{4}\-\d{2}\-\d{2}$/ + }, + 'release_date.gte' => { + type => SCALAR, + optional => 1, + regex => qr/^\d{4}\-\d{2}\-\d{2}$/ + }, + 'release_date.lte' => { + type => SCALAR, + optional => 1, + regex => qr/^\d{4}\-\d{2}\-\d{2}$/ + }, + 'vote_count.gte' => { + type => SCALAR, + optional => 1, + regex => qr/^\d+$/ + }, + 'vote_average.gte' => { + type => SCALAR, + optional => 1, + regex => qr/^\d{1,2}\.\d{1,}$/, + callbacks => { + average => sub { $_[0] <= 10 }, + }, + }, + with_genres => { + type => SCALAR, + optional => 1, + }, + with_companies => { + type => SCALAR, + optional => 1, + }, + }, + ); + + return $self->_search( + { + method => 'discover/movie', + params => { + language => $self->session->lang ? $self->session->lang : undef, + include_adult => $self->include_adult, + %options, + }, + } + ); + +} ## end sub discover + ####################### # PRIVATE METHODS #######################