Skip to content

Commit

Permalink
Merge pull request #5 from zuzia-dev/master
Browse files Browse the repository at this point in the history
Fixed sport series event listing
  • Loading branch information
zuzia-dev authored Mar 27, 2022
2 parents 958f592 + f52c770 commit 9d789d8
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 9 deletions.
4 changes: 2 additions & 2 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon id="plugin.video.viaplay" version="2.3.1" name="Viaplay" provider-name="emilsvennesson, mariusz89b, heppen-dev, zuzia-dev">
<addon id="plugin.video.viaplay" version="2.3.2" name="Viaplay" provider-name="emilsvennesson, mariusz89b, heppen-dev, zuzia-dev">
<requires>
<import addon="script.module.requests" version="2.9.1" />
<import addon="script.module.iso8601" version="0.1.11" />
Expand All @@ -17,7 +17,7 @@
<description lang="sv_SE">Titta på innehåll från Viaplay.</description>
<description lang="pl_PL">Oglądaj treści z Viaplay.</description>
<description lang="lt_LT">Žiūrėkite turinį iš Viaplay.</description>
<news>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
<news>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
</news>
<platform>all</platform>
<language>sv dk no fi en pl lt</language>
Expand Down
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
64 changes: 59 additions & 5 deletions resources/lib/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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."""
Expand Down Expand Up @@ -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'):
Expand All @@ -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),
Expand All @@ -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:
Expand Down
13 changes: 11 additions & 2 deletions resources/lib/viaplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 9d789d8

Please sign in to comment.