Skip to content

Commit

Permalink
tv_grab_zz_sdjson: improve episode/season metadata handling
Browse files Browse the repository at this point in the history
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: #221
  • Loading branch information
kgroeneveld committed Jan 20, 2024
1 parent fff85da commit a0c8c88
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions grab/zz_sdjson/tv_grab_zz_sdjson
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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'};
Expand Down

0 comments on commit a0c8c88

Please sign in to comment.