DmitrySandalov / xbmc-repo

Kodi plugin: plays latest news from Russian 1tv
GNU General Public License v2.0
4 stars 3 forks source link

Not all videos are listed #15

Open maxbambi opened 3 years ago

maxbambi commented 3 years ago

When you select a show , not all videos are listed. This happens because in some pages there are more than one data-playlist-url. To catch all links, change this code

class ShowItemsParser(HTMLParser):
    def __init__(self):
        HTMLParser.__init__(self)
        self.json_link = None

    def error(self, message):
        xbmc.log(xbmc.LOGERROR, "ShowItemsParser error")

    def handle_starttag(self, tag, attrs):
        if tag == 'div':
            for name, value in attrs:
                if 'data-playlist-url' in name:
                    self.json_link = 'https://www.1tv.ru' + value

    def get_show_items(self):
        json_data = urlopen(self.json_link).read()
        return json.loads(json_data)

in something similar to:

class ShowItemsParser(HTMLParser):
    def __init__(self):
        HTMLParser.__init__(self)
        self.json_link = []

    def error(self, message):
        xbmc.log(xbmc.LOGERROR, "ShowItemsParser error")

    def handle_starttag(self, tag, attrs):
        if tag == 'div':
            for name, value in attrs:
                if 'data-playlist-url' in name:
                    self.json_link.append('https://www.1tv.ru' + value)

    def get_show_items(self):
        return json.loads(json_data)

    def get_show_items(self):
        total_data = []

        for l in self.json_link:
            try:
                json_data = urlopen(l).read()
                total_data.extend(json.loads(json_data))
            except:
                pass

        return total_data
DmitrySandalov commented 3 years ago

Thanks! Could you please send an example of such show?

maxbambi commented 3 years ago

@DmitrySandalov

For example: https://www.1tv.ru/shows/lednikovyy-period-2020 in html code there are two data-playlist-url /playlist?admin=false&collection_id=3227&single=false&sort=none&video_id=185695 and /playlist?admin=false&single=true&sort=none&video_id=174546 With the old version of the code, you catch only videos in the last playlist, but most of videos are in the first one.

With the new version you can grab videos from all playlists.