From 8f3ce6302e53a7a7051a801335bd62ef860e8ad7 Mon Sep 17 00:00:00 2001 From: heppen-dev Date: Sun, 27 Mar 2022 09:35:56 +0200 Subject: [PATCH 1/2] Fixed sports series event listing --- resources/lib/addon.py | 64 ++++++++++++++++++++++++++++++++++++---- resources/lib/viaplay.py | 13 ++++++-- 2 files changed, 70 insertions(+), 7 deletions(-) diff --git a/resources/lib/addon.py b/resources/lib/addon.py index c4a24db..cc814cd 100644 --- a/resources/lib/addon.py +++ b/resources/lib/addon.py @@ -350,7 +350,7 @@ def list_products(url=None, search_query=None): elif product['type'] == 'sport': add_sports_event(product) elif product['type'] == 'sportSeries': - add_sports_event(product) + add_sports_series(product) elif product['type'] == 'tvEvent': add_tv_event(product) elif product['type'] == 'clip': @@ -372,6 +372,14 @@ def sports_schedule(): helper.eod() +@plugin.route('/sport_series') +def sport_series(): + categories = helper.vp.get_sport_series(plugin.args['url'][0]) + for category in categories: + helper.add_item(category['content']['title'], plugin.url_for(list_products, url=category['_links']['self']['href'])) + helper.eod() + + @plugin.route('/seasons_page') def seasons_page(): """List all series seasons.""" @@ -510,6 +518,50 @@ def add_episode(episode): def add_sports_event(event): + now = datetime.now() + date_today = now.date() + event_date = helper.vp.parse_datetime(event['epg']['start'], localize=True) + event_status = helper.vp.get_event_status(event) + + if date_today == event_date.date(): + start_time = '{0} {1}'.format(helper.language(30027), event_date.strftime('%H:%M')) + else: + start_time = event_date.strftime('%Y-%m-%d %H:%M') + + if event_status != 'upcoming': + plugin_url = plugin.url_for(play, guid=event['system']['guid'] + '-%s' % helper.get_country_code().upper(), url=None, tve='false') + playable = True + else: + plugin_url = plugin.url_for(dialog, dialog_type='ok', + heading=helper.language(30017), + message=helper.language(30016).format(start_time).encode('utf-8')) + playable = False + + details = event['content'] + + if sys.version_info[0] > 2: + title = details.get('title') + else: + title = details.get('title').encode('utf-8') + try: + plotx = details.get('synopsis') + except: + plotx = '' + + event_info = { + 'mediatype': 'video', + 'title': details.get('title'), + 'plot': plotx, + 'year': int(details['production'].get('year')), + 'genre': details['format'].get('title'), + 'list_title': '[B]{0}:[/B] {1}'.format(coloring(start_time, event_status), title) + } + + helper.add_item(event_info['list_title'], plugin_url, playable=playable, info=event_info, + art=add_art(details['images'], 'sport'), content='episodes') + + +def add_sports_series(event): now = datetime.now() date_today = now.date() if event.get('epg'): @@ -523,9 +575,11 @@ def add_sports_event(event): else: start_time = event_date.strftime('%Y-%m-%d %H:%M') + event_url = event['_links']['viaplay:page']['href'] + if event_status != 'upcoming': - plugin_url = plugin.url_for(play, guid=event['system']['guid'] + '-%s' % helper.get_country_code().upper(), url=None, tve='false') - playable = True + plugin_url = plugin.url_for(sport_series, url=event_url) + playable = False else: plugin_url = plugin.url_for(dialog, dialog_type='ok', heading=helper.language(30017), @@ -538,12 +592,12 @@ def add_sports_event(event): if details.get('title'): title = details.get('title') else: - title = details.get('series').get('title') + title = details.get('series', {}).get('title') else: if details.get('title'): title = details.get('title').encode('utf-8') else: - title = details.get('series').get('title').encode('utf-8') + title = details.get('series', {}).get('title').encode('utf-8') try: plotx = details.get('synopsis') except: diff --git a/resources/lib/viaplay.py b/resources/lib/viaplay.py index a86c57c..e365c34 100644 --- a/resources/lib/viaplay.py +++ b/resources/lib/viaplay.py @@ -384,6 +384,11 @@ def get_seasons(self, url): data = self.make_request(url=url, method='get') return [x for x in data['_embedded']['viaplay:blocks'] if x['type'] == 'season-list'] + def get_sport_series(self, url): + """Return all available sport series.""" + data = self.make_request(url=url, method='get') + return [p for x in data['_embedded']['viaplay:blocks'] if 'viaplay:products' in x['_embedded'] for p in x['_embedded']['viaplay:products']] + def download_subtitles(self, suburls): """Download the SAMI subtitles, decode the HTML entities and save to temp directory. Return a list of the path to the downloaded subtitles.""" @@ -447,15 +452,19 @@ def get_event_status(self, data): """Return whether the event/program is live/upcoming/archive.""" now = datetime.utcnow() try: - if 'startTime' in data['epg']: + if data['system']: + start_time = data['system']['availability']['start'] + end_time = data['system']['availability']['end'] + elif 'startTime' in data['epg']: start_time = data['epg']['startTime'] end_time = data['epg']['endTime'] else: start_time = data['epg']['start'] end_time = data['epg']['end'] + except: start_time = str(datetime.now()) - end_time = str(datetime.now()) + end_time = str(datetime.now()) start_time_obj = self.parse_datetime(start_time).replace(tzinfo=None) end_time_obj = self.parse_datetime(end_time).replace(tzinfo=None) From f52c770f9724340b201777e94fe0488d33f4b908 Mon Sep 17 00:00:00 2001 From: heppen-dev Date: Sun, 27 Mar 2022 12:00:26 +0200 Subject: [PATCH 2/2] 2.3.2 --- addon.xml | 4 ++-- changelog.txt | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/addon.xml b/addon.xml index 710705a..a7546d0 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@  - + @@ -17,7 +17,7 @@ Titta på innehåll från Viaplay. Oglądaj treści z Viaplay. Žiūrėkite turinį iš Viaplay. - 2022.03.24 v2.3.1[CR]+ Add NL country support[CR]+ Fixed popular sport tiles[CR]2022.02.17 v2.3.0[CR]+ Added search history function[CR][CR]2022.02.16 v2.2.9[CR]+ Sport category fix[CR][CR]2022.01.28 v2.2.8[CR]+ Kids category updates[CR][CR]2022.01.27 v2.2.7[CR]+ Fixed logout[CR][CR]2022.01.27 v2.2.6[CR]+ Fixed login error[CR][CR]2022.01.25 v2.2.5[CR]+ Fixes[CR][CR]2022.01.23 v2.2.4[CR]+ Fixed external authorization[CR][CR]2021.11.09 v2.2.3[CR]+ Added viaplay.lt[CR][CR]2021.10.24 v2.2.2[CR]+ Fixed plot[CR][CR]2021.10.06 v2.2.1[CR]+ Fixed category sport matches abbreviations[CR][CR]2021.09.29 v2.2.0[CR]+ Fixed subtitles[CR][CR]2021.09.27 v2.1.9[CR]+ Fixed product categories[CR][CR]2021.08.17 v2.1.8[CR]+ Fixed html import error[CR][CR]2021.08.11 v2.1.7[CR]+ Fixed M3U playlist generator[CR][CR]2021.08.09 v2.1.6[CR]+ Added M3U playlist generator[CR][CR]2021.08.08 v2.1.5[CR]+ Added setting "Hide previously aired Live-Tv programmes"[CR][CR]2021.08.07 v2.1.4[CR]+ Added watched and purchased categories for viaplay.pl[CR]+ Fixed category error[CR][CR]2021.08.05 v.2.1.3[CR]+ Added viaplay.pl + 2022.03.27 v2.3.2[CR]+ Fixed sports series event listing @heppen-dev[CR]2022.03.24 v2.3.1[CR]+ Add NL country support[CR]+ Fixed popular sport tiles[CR]2022.02.17 v2.3.0[CR]+ Added search history function[CR][CR]2022.02.16 v2.2.9[CR]+ Sport category fix[CR][CR]2022.01.28 v2.2.8[CR]+ Kids category updates[CR][CR]2022.01.27 v2.2.7[CR]+ Fixed logout[CR][CR]2022.01.27 v2.2.6[CR]+ Fixed login error[CR][CR]2022.01.25 v2.2.5[CR]+ Fixes[CR][CR]2022.01.23 v2.2.4[CR]+ Fixed external authorization[CR][CR]2021.11.09 v2.2.3[CR]+ Added viaplay.lt[CR][CR]2021.10.24 v2.2.2[CR]+ Fixed plot[CR][CR]2021.10.06 v2.2.1[CR]+ Fixed category sport matches abbreviations[CR][CR]2021.09.29 v2.2.0[CR]+ Fixed subtitles[CR][CR]2021.09.27 v2.1.9[CR]+ Fixed product categories[CR][CR]2021.08.17 v2.1.8[CR]+ Fixed html import error[CR][CR]2021.08.11 v2.1.7[CR]+ Fixed M3U playlist generator[CR][CR]2021.08.09 v2.1.6[CR]+ Added M3U playlist generator[CR][CR]2021.08.08 v2.1.5[CR]+ Added setting "Hide previously aired Live-Tv programmes"[CR][CR]2021.08.07 v2.1.4[CR]+ Added watched and purchased categories for viaplay.pl[CR]+ Fixed category error[CR][CR]2021.08.05 v.2.1.3[CR]+ Added viaplay.pl all sv dk no fi en pl lt diff --git a/changelog.txt b/changelog.txt index cb3f781..8c15bbd 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +2022.03.27 v2.3.2 ++ Fixed sports series event listing @heppen-dev + 2022.03.24 v2.3.1 + Add NL country support @Beanow + Fixed popular sport tiles @heppen-dev & @zuzia-dev