# -*- coding: utf-8 -*- # Copyright(C) 2010-2011 Romain Bignon # # This file is part of weboob. # # weboob is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # weboob is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see . import datetime import re import urllib import HTMLParser from weboob.tools.browser import BasePage, BrokenPageError from weboob.tools.capabilities.thumbnail import Thumbnail from weboob.capabilities import NotAvailable from .video import ArteVideo, ArteLiveVideo from .collection import ArteLiveCollection __all__ = ['IndexPage', 'VideoPage', 'ArteLivePage', 'ArteLiveCategorieVideoPage', 'ArteLiveVideoPage'] class ArteLiveVideoPage(BasePage): def get_video(self, video=None, lang='fr', quality='hd'): if not video: video = ArteVideo(self.group_dict['id']) urls = {} for url in self.document.xpath('//video')[0].getchildren(): if url.tag.startswith('url'): urls[url.tag[-2:]] = url.text if quality in urls: video.url = urls[quality] else: video.url = urls.popitem()[1] return video class ArteLiveCategorieVideoPage(BasePage): def iter_videos(self, lang='fr'): videos = list() xml_url = (self.document.xpath('//link')[0]).attrib['href'] datas = self.browser.readurl(xml_url) re_items = re.compile("(.*?)", re.DOTALL) items = re.findall(re_items, datas) for item in items: parsed_element = self.get_element(item, lang) if parsed_element: video = ArteLiveVideo(parsed_element['ID']) video.title = parsed_element['title'] video.description = parsed_element['pitch'] video.author = parsed_element['author'] if parsed_element['pict']: video.thumbnail = Thumbnail(parsed_element['pict']) video.set_empty_fields(NotAvailable, ('url',)) videos.append(video) return videos def get_element(self, chain, lang): ele = {} tt = re.compile("(?<=)(.*?)(?=)", re.DOTALL) lk = re.compile("(?<=)(http://liveweb.arte.tv/{0}/video/.*?)" "(?=)".format(lang), re.DOTALL) dt = re.compile("(?<=)(.*?)(?=)", re.DOTALL) pt = re.compile("(?<=)(.*?)(?=)", re.DOTALL) at = re.compile("(?<=)(.*?)(?=)", re.DOTALL) en = re.compile("", re.DOTALL) pix = re.compile("(?<=