Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

malformed JSON string #3

Closed
jmwislez opened this issue Jul 5, 2010 · 10 comments
Closed

malformed JSON string #3

jmwislez opened this issue Jul 5, 2010 · 10 comments

Comments

@jmwislez
Copy link

jmwislez commented Jul 5, 2010

when running the grabber I get:

malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "(end of string)") at ./tv_grab_uk_sky_2 line 205.

Any clue?

@jmwislez
Copy link
Author

jmwislez commented Jul 9, 2010

Solved after I found on a forum that one needs to search and replace www.sky.com/portletepg
with
epgservices.sky.com/tvlistings-proxy

But now I bump into the next problem:
malformed UTF-8 character in JSON string, at character offset 17142 (before "\x{9b6f}i movies","c...") at /usr/local/bin/tv_grab_uk_sky line 205.

@Floppy
Copy link
Owner

Floppy commented Jul 13, 2010

Hm, interesting - looks like they've changed the URL, and might be using UTF-16 encoding. Does changing JSON.parse(...) to JSON.parse(..., "UTF-16") make any difference?

@Floppy
Copy link
Owner

Floppy commented Jul 13, 2010

Sorry, that's completely the wrong language, I'm used to thinking in Ruby :)

Just looking for how to do it in Perl...

@Floppy
Copy link
Owner

Floppy commented Jul 13, 2010

Looks like it should be something like this instead of decode_json():

use Encode;
$object = JSON::XS->new->decode (decode "UTF-16BE", $jsontext);

Found at http://search.cpan.org/~makamaka/JSON-2.21/lib/JSON.pm in section 'utf8'

@jmwislez
Copy link
Author

It's actually UTF-8, but it works! Thanks a lot!

@jmwislez
Copy link
Author

Maybe I shouldn't have closed this issue as long as the downloadable code is not on. If you want I can provide it by mail.

@Floppy
Copy link
Owner

Floppy commented Jul 16, 2010

Great! Yes, if you have a patch, please put it in here and I will apply it to the code. Thanks!

@jmwislez
Copy link
Author

--- /home/jmw/tv_grab_uk_sky.orig 2010-07-16 19:37:29.000000000 +0200
+++ /usr/local/bin/tv_grab_uk_sky 2010-07-15 12:46:36.000000000 +0200
@@ -73,6 +73,7 @@
use JSON;
use HTML::Entities;
use DateTime;
+use Encode;

my( $opt, $conf ) = ParseOptions( {
grabber_name => "tv_grab_uk_sky",
@@ -104,12 +105,12 @@
my $timestr = $time->strftime("%Y%m%d%H%M"); # Time and date in YYYYMMDDhhmm format
my $dur = $last_day - $grab_offset < 2 ? 1440 : 2880; # Length of data to fetch in minutes (2880 max - 2 days)
my $detail = 2; # 2 gives full epg data with descriptions, any other number gives no desc.

  • my $url = "http://www.sky.com/portletepg/TVListingsProxy/tvlistings.json?channels=$channel&dur=$dur&detail=$detail&time=$timestr";
    
  • my $url = "http://epgservices.sky.com/tvlistings-proxy/TVListingsProxy/tvlistings.json?channels=$channel&dur=$dur&detail=$detail&time=$timestr";
    

    my $res = get($url);
    $res =~ s/""$//g;
    if (length($res) > 0)
    {

  •   my $channel_data = decode_json $res;
    
  •   my $channel_data = JSON::XS->new->decode (decode "UTF-8", $res);
    # Store channel information
    

    foreach my $x ($channel_data->{channels})
    {
    @@ -200,9 +201,9 @@
    my( $conf, $opt ) = @_;
    my $channel_list = '';

  • # Load http://www.sky.com/portletepg/TVListingsProxy/init.json and convert to XML channel list
    
  • my $res = get( "http://www.sky.com/portletepg/TVListingsProxy/init.json" );
    
  • my $channel_data = decode_json $res;
    
  • # Load http://epgservices.sky.com/tvlistings-proxy/TVListingsProxy/init.json and convert to XML channel list
    
  • my $res = get( "http://epgservices.sky.com/tvlistings-proxy/TVListingsProxy/init.json" );
    
  • my $channel_data = JSON::XS->new->decode (decode "UTF-8", $res);
    

    foreach my $channel (@{$channel_data->{channels}})
    {

@jmwislez
Copy link
Author

Hmm, this formats strangely. Hope you can extract the patch. I can't find out how to submit it properly ...

@Floppy
Copy link
Owner

Floppy commented Dec 15, 2010

I've finally got around to applying this patch. Sorry it took so long! I can't test it locally (no XMLTV setup any more), so let me know if you have any problems.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants