From e0753f9a23d24f45245e063a05b1631b003a67bb Mon Sep 17 00:00:00 2001 From: Bezleputh Date: Thu, 15 May 2014 14:49:37 +0200 Subject: [PATCH] [canalplus] fix play and download --- modules/canalplus/browser.py | 16 ++++++++++++---- modules/canalplus/pages.py | 14 ++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/modules/canalplus/browser.py b/modules/canalplus/browser.py index bea24143..d274bb10 100644 --- a/modules/canalplus/browser.py +++ b/modules/canalplus/browser.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see . - +import requests import urllib import lxml.etree @@ -55,8 +55,8 @@ class CanalplusBrowser(BaseBrowser): #We need lxml.etree.XMLParser to read CDATA PARSER = XMLParser() FORMATS = { - 'sd': 'BAS_DEBIT', - 'hd': 'HD', + 'sd': 0, + 'hd': 3, } def __init__(self, quality, *args, **kwargs): @@ -73,7 +73,15 @@ class CanalplusBrowser(BaseBrowser): @id2url(CanalplusVideo.id2url) def get_video(self, url, video=None): self.location(url) - return self.page.get_video(video, self.quality) + video = self.page.get_video(video) + video.url = self.read_url(video.url)[self.quality] + return video + + def read_url(self, url): + r = requests.get(url, stream=True) + buf = r.iter_lines() + r.close() + return [line for line in buf if not line.startswith('#')] def iter_resources(self, split_path): if not self.is_on_page(ChannelsPage): diff --git a/modules/canalplus/pages.py b/modules/canalplus/pages.py index e45788a7..c76af150 100644 --- a/modules/canalplus/pages.py +++ b/modules/canalplus/pages.py @@ -58,7 +58,7 @@ class ChannelsPage(BasePage): class VideoPage(BasePage): - def parse_video(self, el, video=None, quality=None): + def parse_video(self, el, video=None): _id = el.find('ID').text if _id == '-1': # means the video is not found @@ -84,16 +84,14 @@ class VideoPage(BasePage): video.thumbnail.url = video.thumbnail.id else: video.thumbnail = NotAvailable - lastest_format = None for format in media.find('VIDEOS'): if format.text is None: continue - if format.tag == quality: + + if format.tag == 'HLS': + video.ext = u'm3u8' video.url = unicode(format.text) break - lastest_format = format - if not video.url and lastest_format is not None: - video.url = unicode(lastest_format.text) day, month, year = map(int, infos.find('PUBLICATION').find('DATE').text.split('/')) hour, minute, second = map(int, infos.find('PUBLICATION').find('HEURE').text.split(':')) @@ -116,9 +114,9 @@ class VideoPage(BasePage): video.date = datetime.now() return video - def get_video(self, video, quality): + def get_video(self, video): _id = self.group_dict['id'] for vid in self.document.getchildren(): if not _id in vid.find('ID').text: continue - return self.parse_video(vid, video, quality) + return self.parse_video(vid, video)