From a0c8c88341ab0a3b9919135b424ef1470dc4d490 Mon Sep 17 00:00:00 2001 From: Kevin Groeneveld Date: Sat, 20 Jan 2024 16:44:40 -0500 Subject: [PATCH] tv_grab_zz_sdjson: improve episode/season metadata handling The program metadata from SD is an array of different providers. The previous code was specifically looking for 'Gracenote' provider in the first array element and ignoring everything else. For example, it seems the first element is now often 'TVmaze' (at least for the lineups I use) and the episode/season data was all being ignored. The code now iterates over all the metadata providers generally preferring the earlier entries unless a later one looks more complete. Fixes: https://github.com/XMLTV/xmltv/issues/221 --- grab/zz_sdjson/tv_grab_zz_sdjson | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) mode change 100644 => 100755 grab/zz_sdjson/tv_grab_zz_sdjson 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'};