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

Upgrade VTMGO REST API to version 12 #325

Merged
merged 3 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pytest-timeout
python-dateutil
pysocks
requests
git+git://github.com/dagwieers/kodi-plugin-routing.git@setup#egg=routing
git+https://github.com/tamland/kodi-plugin-routing@master#egg=routing
mock
sakee
win-inet-pton; platform_system=="Windows"
8 changes: 4 additions & 4 deletions resources/lib/vtmgo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
API_ANDROID_ENDPOINT = 'https://lfvp-android-api.dpgmedia.net'

# These seem to be hardcoded
STOREFRONT_MAIN = '9620cc0b-0f97-4d96-902a-827dcfd0b227'
STOREFRONT_MOVIES = 'e3fc0750-f110-4808-ae5f-246846ff940f'
STOREFRONT_SERIES = '1c683de4-3fb0-4cc4-9d9c-c365eba1b155'
STOREFRONT_KIDS = '73f34fbf-301c-4deb-b366-13ba39e25996'
STOREFRONT_MAIN = 'main'
STOREFRONT_MOVIES = 'movies'
STOREFRONT_SERIES = 'series'
STOREFRONT_KIDS = 'kids'


class Profile:
Expand Down
4 changes: 2 additions & 2 deletions resources/lib/vtmgo/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# Setup a static session that can be reused for all calls
SESSION = requests.Session()
SESSION.headers = {
'User-Agent': 'VTMGO/11.19 (be.vmma.vtm.zenderapp; build:14554; iOS 24) okhttp/4.9.1',
'x-app-version': '11',
'User-Agent': 'VTMGO/12.12 (be.vmma.vtm.zenderapp; build:16424; Android 24) okhttp/4.9.3',
'x-app-version': '12',
'x-persgroep-mobile-app': 'true',
'x-persgroep-os': 'android',
'x-persgroep-os-version': '24',
Expand Down
46 changes: 26 additions & 20 deletions resources/lib/vtmgo/vtmgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


class ApiUpdateRequired(Exception):
""" Is thrown when the an API update is required. """
""" Is thrown when an API update is required. """


class VtmGo:
Expand All @@ -42,10 +42,11 @@ def _mode(self):
""" Return the mode that should be used for API calls """
return 'vtmgo-kids' if self.get_product() == 'VTM_GO_KIDS' else 'vtmgo'

def get_config(self):
@staticmethod
def get_config():
""" Returns the config for the app """
# This is currently not used
response = util.http_get(API_ANDROID_ENDPOINT + '/vtmgo/config', token=self._tokens.access_token)
response = util.http_get(API_ANDROID_ENDPOINT + '/vtmgo/config')
info = json.loads(response.text)

# This contains a player.updateIntervalSeconds that could be used to notify VTM GO about the playing progress
Expand Down Expand Up @@ -106,7 +107,7 @@ def get_storefront_category(self, storefront, category):
result = json.loads(response.text)

items = []
for item in result.get('row', {}).get('teasers'):
for item in result.get('teasers'):
if item.get('target', {}).get('type') == CONTENT_TYPE_MOVIE:
items.append(self._parse_movie_teaser(item))

Expand Down Expand Up @@ -222,7 +223,7 @@ def get_movie(self, movie_id, cache=CACHE_AUTO):
thumb=movie.get('teaserImageUrl'),
fanart=movie.get('bigPhotoUrl'),
year=movie.get('productionYear'),
geoblocked=movie.get('geoBlocked'),
geoblocked=movie.get('blockedFor') == 'GEO',
remaining=movie.get('remainingDaysAvailable'),
legal=movie.get('legalIcons'),
# aired=movie.get('broadcastTimestamp'),
Expand All @@ -248,29 +249,34 @@ def get_program(self, program_id, cache=CACHE_AUTO):
response = util.http_get(API_ENDPOINT + '/%s/programs/%s' % (self._mode(), program_id),
token=self._tokens.access_token if self._tokens else None,
profile=self._tokens.profile if self._tokens else None)
info = json.loads(response.text)
program = info.get('program', {})
program = json.loads(response.text)
kodiutils.set_cache(['program', program_id], program)

channel = self._parse_channel(program.get('channelLogoUrl'))

seasons = {}
for item_season in program.get('seasons', []):
for item_season in program.get('seasonIndices', []):
episodes = {}

for item_episode in item_season.get('episodes', []):
# Fetch season
season_response = util.http_get(API_ENDPOINT + '/%s/programs/%s/seasons/%s' % (self._mode(), program_id, item_season),
token=self._tokens.access_token if self._tokens else None,
profile=self._tokens.profile if self._tokens else None)
season = json.loads(season_response.text)

for item_episode in season.get('episodes', []):
episodes[item_episode.get('index')] = Episode(
episode_id=item_episode.get('id'),
program_id=program_id,
program_name=program.get('name'),
number=item_episode.get('index'),
season=item_season.get('index'),
season=item_season,
name=item_episode.get('name'),
description=item_episode.get('description'),
duration=item_episode.get('durationSeconds'),
thumb=item_episode.get('bigPhotoUrl'),
fanart=item_episode.get('bigPhotoUrl'),
geoblocked=program.get('geoBlocked'),
geoblocked=program.get('blockedFor') == 'GEO',
remaining=item_episode.get('remainingDaysAvailable'),
channel=channel,
legal=program.get('legalIcons'),
Expand All @@ -279,8 +285,8 @@ def get_program(self, program_id, cache=CACHE_AUTO):
watched=item_episode.get('doneWatching', False),
)

seasons[item_season.get('index')] = Season(
number=item_season.get('index'),
seasons[item_season] = Season(
number=item_season,
episodes=episodes,
channel=channel,
legal=program.get('legalIcons'),
Expand All @@ -291,9 +297,9 @@ def get_program(self, program_id, cache=CACHE_AUTO):
name=program.get('name'),
description=program.get('description'),
year=program.get('productionYear'),
thumb=program.get('teaserImageUrl'),
fanart=program.get('bigPhotoUrl'),
geoblocked=program.get('geoBlocked'),
thumb=program.get('landscapeTeaserImageUrl'),
fanart=program.get('backgroundImageUrl'),
geoblocked=program.get('blockedFor') == 'GEO',
seasons=seasons,
channel=channel,
legal=program.get('legalIcons'),
Expand Down Expand Up @@ -413,7 +419,7 @@ def _parse_movie_teaser(self, item, cache=CACHE_ONLY):
movie_id=item.get('target', {}).get('id'),
name=item.get('title'),
thumb=item.get('imageUrl'),
geoblocked=item.get('geoBlocked'),
geoblocked=item.get('blockedFor') == 'GEO',
)

def _parse_program_teaser(self, item, cache=CACHE_ONLY):
Expand All @@ -429,8 +435,8 @@ def _parse_program_teaser(self, item, cache=CACHE_ONLY):
return Program(
program_id=item.get('target', {}).get('id'),
name=item.get('title'),
thumb=item.get('imageUrl'),
geoblocked=item.get('geoBlocked'),
thumb=item.get('largeImageUrl'),
geoblocked=item.get('blockedFor') == 'GEO',
)

def _parse_episode_teaser(self, item, cache=CACHE_ONLY):
Expand All @@ -448,7 +454,7 @@ def _parse_episode_teaser(self, item, cache=CACHE_ONLY):
program_name=item.get('title'),
name=item.get('label'),
description=episode.description if episode else None,
geoblocked=item.get('geoBlocked'),
geoblocked=item.get('blockedFor') == 'GEO',
thumb=item.get('imageUrl'),
progress=item.get('playerPositionSeconds'),
watched=False,
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def modify_xml(file, version, news, python=None):
if os.path.isfile(f):
shutil.copy(f, dest)
else:
shutil.copytree(f, os.path.join(dest, f), dirs_exist_ok=True)
shutil.copytree(f, os.path.join(dest, f))

# Update addon.xml for matrix and create zip
modify_xml(os.path.join(dest, 'addon.xml'), addon_info['version'] + '+matrix.1', addon_info['news'], '3.0.0')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

EXAMPLE_CHANNEL = 'ea826456-6b19-4612-8969-864d1c818347' # VTM2
EXAMPLE_MOVIE = '1c758fe2-fa19-4dc1-a9f6-fcd5eeb0a284' # Belgica
EXAMPLE_PROGRAM = '96a49148-59f6-420c-9b90-8b058760c467' # Familie
EXAMPLE_PROGRAM = '5d5e5976-6ca0-43a5-be96-1467ea25cfff' # Familie
EXAMPLE_EPISODE = '03136212-d2f5-4c0f-abff-eac84ae8da42' # Instafamous S01E01


Expand Down