diff --git a/grab/zz_sdjson/tv_grab_zz_sdjson b/grab/zz_sdjson/tv_grab_zz_sdjson old mode 100644 new mode 100755 index e315f6ae6..895bb7a04 --- a/grab/zz_sdjson/tv_grab_zz_sdjson +++ b/grab/zz_sdjson/tv_grab_zz_sdjson @@ -1265,11 +1265,22 @@ sub get_program_episode { my $part = ''; my @result; - my $metadata = $details->{'metadata'}->[0]->{'Gracenote'}; - if($metadata) - { - $season = _get_program_episode($metadata->{'season'}, $metadata->{'totalSeason'}); - $episode = _get_program_episode($metadata->{'episode'}, $metadata->{'totalEpisodes'}); + metadata: for my $metadata (@{$details->{'metadata'}}) { + while(my ($key, $value) = each %{$metadata}) { + my $_season = _get_program_episode($value->{'season'}, $value->{'totalSeason'}); + my $_episode = _get_program_episode($value->{'episode'}, $value->{'totalEpisodes'}); + + my $complete = (index($_season, '/') >= 0 && index($_episode, '/') >= 0); + my $season_and_episode = (length($_season) && length($_episode)); + + # store current metadata if it is more complete than what we already have + if ($complete || !length($episode) && $season_and_episode || !length($season)) { + $season = $_season; + $episode = $_episode; + } + + last metadata if $complete; + } } my $multipart = $program->{'multipart'};