Ticket #6428: mythplugins-6428-mythvideo-tmdb-check_response.2.patch

File mythplugins-6428-mythvideo-tmdb-check_response.2.patch, 2.6 KB (added by sphery <mtdean@…>, 15 years ago)

Slightly prettier patch. Can check for !defined since MythVideoCommon?.pm's myth_url_get(), used by TMDBAPIRequest(), returns undef response for unsuccessful requests

  • mythvideo/mythvideo/scripts/tmdb.pl

     
    119119    my ($rc, $response) =
    120120        TMDBAPIRequest('Movie.imdbLookup', {'imdb_id' => "tt$movieid"});
    121121
     122    if (!defined $response) {
     123        die "Unable to contact themoviedb.org while retrieving ".
     124            "movie data, stopped";
     125    }
     126
    122127    my $xs = new XML::Simple(SuppressEmpty => '', ForceArray => ['movie'],
    123128        KeyAttr => []);
    124129    my $xml = $xs->XMLin($response);
     
    130135        my ($rc, $response) =
    131136            TMDBAPIRequest('Movie.getInfo', {'id' => $tmdbid});
    132137
     138        if (!defined $response) {
     139            die "Unable to contact themoviedb.org while retrieving ".
     140                "movie data, stopped";
     141        }
     142
    133143        $xml = $xs->XMLin($response,
    134144            ForceArray => ['category', 'production_countries'],
    135145            KeyAttr => ['key', 'id']);
     
    235245    my ($rc, $response) =
    236246        TMDBAPIRequest('Movie.imdbLookup', {'imdb_id' => "tt$movieid"});
    237247
     248    if (!defined $response) {
     249        die "Unable to contact themoviedb.org while retrieving ".
     250            "movie poster, stopped";
     251    }
     252
    238253    my $xml = XMLin($response, ForceArray => ['movie', 'poster', 'backdrop'],
    239254        KeyAttr => {poster => 'size'});
    240255
     
    258273    my ($rc, $response) =
    259274        TMDBAPIRequest('Movie.imdbLookup', {'imdb_id' => "tt$movieid"});
    260275
     276    if (!defined $response) {
     277        die "Unable to contact themoviedb.org while retrieving ".
     278            "movie backdrop, stopped";
     279    }
     280
    261281    my $xs = new XML::Simple(SuppressEmpty => '', ForceArray => [],
    262282        KeyAttr => []);
    263283    my $xml = $xs->XMLin($response);
     
    270290        my ($rc, $response) =
    271291            TMDBAPIRequest('Movie.getInfo', {'id' => $tmdbid});
    272292
     293        if (!defined $response) {
     294            die "Unable to contact themoviedb.org while retrieving ".
     295                "movie backdrop, stopped";
     296        }
     297
    273298        $xml = XMLin($response, ForceArray=> [], KeyAttr => ['key', 'id']);
    274299
    275300        foreach my $backdrop (@{$xml->{moviematches}->{movie}->{backdrop}}) {
     
    299324    my ($rc, $response) =
    300325        TMDBAPIRequest('Movie.search', {'title' => $query});
    301326
     327    if (!defined $response) {
     328        die "Unable to contact themoviedb.org while retrieving ".
     329            "movie list, stopped";
     330    }
     331
    302332    my $xs = new XML::Simple(SuppressEmpty => '', ForceArray => ['movie'],
    303333        KeyAttr => []);
    304334    my $xml = $xs->XMLin($response);