Skip to content

Commit

Permalink
uk_freeview: fix source returns no content (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
honir committed Sep 12, 2024
1 parent 8c47a4b commit 9f9b936
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions grab/uk_freeview/tv_grab_uk_freeview
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,20 @@ sub trim_all( $ ) {
return $_[0];
}

# Prevent croak on empty JSON content
sub fudgeprogs( $ ) {
# site sometimes return no content (even though status code 200)
# this is naughty: it should really return empty JSON string
# to prevent JSON->decode() croaking on empty string we'll invent some data
#
my $content = shift;
if (length($content) == 0) {
print STDERR 'no content - creating empty file'."\n" if $opt_debug;
return '{"status":"success","data":{"programs":[]}}';
}
return $content;
}


sub get_programmes {
my ($ch_xmltv_ids) = @_;
Expand All @@ -549,7 +563,7 @@ sub get_programmes {
t $url;

# fetch json content (will be decoded from utf8)
my $data = get_nice_json( $url );
my $data = get_nice_json( $url, \&fudgeprogs );
if ($data->{status} ne 'success') { print STDERR " PROGRAMME fetch failed : ".$data->{status}."\n" if $opt_debug; }

#print STDERR Dumper($data);die();
Expand Down Expand Up @@ -661,7 +675,7 @@ sub get_programmes {
t $url;

# fetch json content (will be decoded from utf8)
my $data = get_nice_json( $url );
my $data = get_nice_json( $url, \&fudgeprogs );
if ($data->{status} ne 'success') { print STDERR " DETAILS fetch failed : ".$data->{status}."\n" if $opt_debug; }

#print STDERR Dumper($data);die();
Expand Down

0 comments on commit 9f9b936

Please sign in to comment.