correctly parse input of get_video
This commit is contained in:
parent
54b66983e6
commit
a2c5566e96
2 changed files with 15 additions and 12 deletions
|
|
@ -18,7 +18,7 @@
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
from weboob.capabilities.video import ICapVideo, BaseVideo
|
from weboob.capabilities.video import ICapVideo, BaseVideo
|
||||||
from weboob.capabilities.collection import ICapCollection, CollectionNotFound, Collection
|
from weboob.capabilities.collection import ICapCollection, CollectionNotFound, Collection
|
||||||
|
|
@ -46,19 +46,22 @@ class ArteBackend(BaseBackend, ICapVideo, ICapCollection):
|
||||||
def create_default_browser(self):
|
def create_default_browser(self):
|
||||||
return self.create_browser(lang=self.config['lang'].get(), quality=self.config['quality'].get())
|
return self.create_browser(lang=self.config['lang'].get(), quality=self.config['quality'].get())
|
||||||
|
|
||||||
def split_id(self, _id):
|
def parse_id(self, _id):
|
||||||
try:
|
m = re.match('^(\w+)\.(.*)', _id)
|
||||||
site, _id = _id.split('.', 1)
|
if m:
|
||||||
except ValueError:
|
return m.groups()
|
||||||
site = 'videos'
|
|
||||||
|
|
||||||
return site, _id
|
m = re.match('https?://videos.arte.tv/\w+/videos/(?P<id>.+)\.html', _id)
|
||||||
|
if m:
|
||||||
|
return 'videos', m.group(1)
|
||||||
|
|
||||||
|
# TODO support live videos
|
||||||
|
|
||||||
|
return 'videos', _id
|
||||||
|
|
||||||
def get_video(self, _id):
|
def get_video(self, _id):
|
||||||
if _id.startswith('http://') and not _id.startswith('http://videos.arte.tv'):
|
|
||||||
return None
|
|
||||||
with self.browser:
|
with self.browser:
|
||||||
site, _id = self.split_id(_id)
|
site, _id = self.parse_id(_id)
|
||||||
|
|
||||||
if site == 'live':
|
if site == 'live':
|
||||||
return self.browser.get_live_video(_id)
|
return self.browser.get_live_video(_id)
|
||||||
|
|
@ -73,7 +76,7 @@ class ArteBackend(BaseBackend, ICapVideo, ICapCollection):
|
||||||
if fields != ['thumbnail']:
|
if fields != ['thumbnail']:
|
||||||
# if we don't want only the thumbnail, we probably want also every fields
|
# if we don't want only the thumbnail, we probably want also every fields
|
||||||
with self.browser:
|
with self.browser:
|
||||||
site, _id = self.split_id(video.id)
|
site, _id = self.parse_id(video.id)
|
||||||
|
|
||||||
if isinstance(video,ArteVideo):
|
if isinstance(video,ArteVideo):
|
||||||
video = self.browser.get_video(_id, video)
|
video = self.browser.get_video(_id, video)
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ __all__ = ['ArteVideo','ArteLiveVideo']
|
||||||
class ArteVideo(BaseVideo):
|
class ArteVideo(BaseVideo):
|
||||||
@classmethod
|
@classmethod
|
||||||
def id2url(cls, _id):
|
def id2url(cls, _id):
|
||||||
return 'http://videos.arte.tv/fr/videos/--%s.html' % _id
|
return 'http://videos.arte.tv/fr/videos/%s.html' % _id
|
||||||
|
|
||||||
|
|
||||||
class ArteLiveVideo(BaseVideo):
|
class ArteLiveVideo(BaseVideo):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue