From 9f4bba446ad211c5691778da3a6f6e8e0cfd80f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Arnauts?= Date: Sun, 16 Oct 2022 15:32:56 +0200 Subject: [PATCH] Fix clips (#108) --- resources/lib/viervijfzes/content.py | 17 +++++++++++++++-- tests/test_api.py | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/resources/lib/viervijfzes/content.py b/resources/lib/viervijfzes/content.py index f957ce6..3517219 100644 --- a/resources/lib/viervijfzes/content.py +++ b/resources/lib/viervijfzes/content.py @@ -309,7 +309,7 @@ class ContentApi: result = regex_video_data.search(page) if result: video_id = json.loads(unescape(result.group(1)))['id'] - video_json_data = self._get_url('%s/api/video/%s' % (self.SITE_URL, video_id)) + video_json_data = self._get_url('%s/web/v1/videos/short-form/%s' % (self.API_GOPLAY, video_id)) video_json = json.loads(video_json_data) return dict(video=video_json) @@ -336,7 +336,7 @@ class ContentApi: if 'video' in data and data['video']: # We have found detailed episode information - episode = self._parse_episode_data(data['video']) + episode = self._parse_clip_data(data['video']) return episode if 'program' in data and 'episode' in data and data['program'] and data['episode']: @@ -696,6 +696,19 @@ class ContentApi: ) return episode + @staticmethod + def _parse_clip_data(data): + """ Parse the Clip JSON. + :type data: dict + :rtype Episode + """ + episode = Episode( + uuid=data.get('videoUuid'), + program_title=data.get('title'), + title=data.get('title'), + ) + return episode + def _get_url(self, url, params=None, authentication=None): """ Makes a GET request for the specified URL. :type url: str diff --git a/tests/test_api.py b/tests/test_api.py index c80991e..c78cc9f 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -55,7 +55,7 @@ class TestApi(unittest.TestCase): self.assertIsInstance(program.episodes[0], Episode) def test_clips(self): - for program in ['gert-late-night']: + for program in ['de-tafel-van-vier']: program = self._api.get_program(program, extract_clips=True, cache=CACHE_PREVENT) self.assertIsInstance(program.clips, list)