From 30f814ec65dd4c612ed892cdfbb823678a19402e Mon Sep 17 00:00:00 2001 From: Bezleputh Date: Tue, 26 Aug 2014 15:51:25 +0200 Subject: [PATCH] [arte] fix #1071 --- modules/arte/backend.py | 29 ++++++++++++++++++++++++++--- modules/arte/browser.py | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/modules/arte/backend.py b/modules/arte/backend.py index 0c286c55..e3b7fc97 100644 --- a/modules/arte/backend.py +++ b/modules/arte/backend.py @@ -122,6 +122,7 @@ class ArteBackend(BaseBackend, CapVideo, CapCollection): if collection.path_level == 0: yield Collection([u'arte-latest'], u'Latest Arte videos') yield Collection([u'arte-live'], u'Arte Web Live videos') + yield Collection([u'arte-program'], u'Arte Programs') if collection.path_level == 1: if collection.split_path == [u'arte-latest']: for video in self.browser.latest_videos(): @@ -129,18 +130,40 @@ class ArteBackend(BaseBackend, CapVideo, CapCollection): if collection.split_path == [u'arte-live']: for categorie in self.browser.get_arte_live_categories(): yield categorie + if collection.split_path == [u'arte-program']: + for item in self.browser.get_arte_programs(): + lang = self.TRANSLATION[self.config['lang'].get()] + + if lang == 'F': + title = 'titleFR' + elif lang == 'D': + title = 'titleDE' + else: + title = 'name' + + name = item['clusterId'] + if title in item.keys(): + name = item[title] + + yield Collection([u'arte-program', item['clusterId']], u'%s' % name) if collection.path_level == 2: if collection.split_path[0] == u'arte-live': for video in self.browser.live_videos(collection.basename): yield video + if collection.split_path[0] == u'arte-program': + for video in self.browser.program_videos(collection.split_path[1]): + yield video def validate_collection(self, objs, collection): if collection.path_level == 0: return - if BaseVideo in objs and (collection.split_path == [u'arte-latest'] or collection.split_path == [u'arte-live']): + if BaseVideo in objs and (collection.split_path == [u'arte-latest'] or + collection.split_path == [u'arte-live'] or + collection.split_path == [u'arte-program']): return - if BaseVideo in objs and collection.path_level == 2 and collection.split_path[0] == u'arte-live': + if BaseVideo in objs and collection.path_level == 2 and (collection.split_path[0] == u'arte-live' or + collection.split_path[0] == u'arte-program'): return raise CollectionNotFound(collection.split_path) - OBJECTS = {ArteVideo: fill_video, ArteLiveVideo: fill_video } + OBJECTS = {ArteVideo: fill_video, ArteLiveVideo: fill_video} diff --git a/modules/arte/browser.py b/modules/arte/browser.py index 1d166d0f..56e256a4 100644 --- a/modules/arte/browser.py +++ b/modules/arte/browser.py @@ -144,8 +144,9 @@ class ArteBrowser(BaseBrowser): response = self.openurl(url) result = simplejson.loads(response.read(), self.ENCODING) - video = self.create_video(result['abstractProgram']['VDO']) - return self.get_video(video.id, video) + if 'VDO' in result['abstractProgram'].keys(): + video = self.create_video(result['abstractProgram']['VDO']) + return self.get_video(video.id, video) def search_videos(self, pattern): class_name = 'videos/plus7' @@ -211,6 +212,38 @@ class ArteBrowser(BaseBrowser): return url + def get_arte_programs(self): + class_name = 'epg' + method_name = 'clusters' + url = self.API_URL \ + + '/' + class_name \ + + '/' + method_name \ + + '/' + self.lang \ + + '/0/ALL.json' + + response = self.openurl(url) + result = simplejson.loads(response.read(), self.ENCODING) + return result['configClusterList'] + + def program_videos(self, program): + class_name = 'epg' + method_name = 'cluster' + + url = self.API_URL \ + + '/' + class_name \ + + '/' + method_name \ + + '/' + self.lang \ + + '/' + program \ + + '.json' + + response = self.openurl(url) + result = simplejson.loads(response.read(), self.ENCODING) + for item in result['clusterWrapper']['broadcasts']: + if 'VDS' in item.keys() and len(item['VDS']) > 0: + video = self.get_video_from_program_id(item['programId']) + if video: + yield video + def latest_videos(self): class_name = 'videos' method_name = 'plus7'