rewrite video decorators to be in browser
This commit is contained in:
parent
83ec57629b
commit
0de0f2a768
19 changed files with 167 additions and 119 deletions
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
import logging
|
||||
|
||||
from weboob.backend import check_domain, id2url, BaseBackend
|
||||
from weboob.backend import BaseBackend
|
||||
from weboob.capabilities.video import ICapVideoProvider
|
||||
|
||||
from .browser import YoutubeBrowser
|
||||
|
|
@ -38,9 +38,7 @@ class YoutubeBackend(BaseBackend, ICapVideoProvider):
|
|||
|
||||
CONFIG = {}
|
||||
BROWSER = YoutubeBrowser
|
||||
domain = u'youtube.com'
|
||||
|
||||
@id2url(domain, YoutubeVideo.id2url)
|
||||
def get_video(self, _id):
|
||||
return self.browser.get_video(_id)
|
||||
|
||||
|
|
@ -48,7 +46,7 @@ class YoutubeBackend(BaseBackend, ICapVideoProvider):
|
|||
try:
|
||||
import gdata.youtube.service
|
||||
except ImportError:
|
||||
logging.warning('Youtube backend search feature requires python-gdata package.')
|
||||
logging.error('Youtube backend search feature requires python-gdata package.')
|
||||
return
|
||||
yt_service = gdata.youtube.service.YouTubeService()
|
||||
query = gdata.youtube.service.YouTubeVideoQuery()
|
||||
|
|
@ -62,12 +60,11 @@ class YoutubeBackend(BaseBackend, ICapVideoProvider):
|
|||
author = entry.media.name.text.decode('utf-8').strip()
|
||||
else:
|
||||
author = None
|
||||
yield YoutubeVideo(u'youtube:%s' % entry.id.text.split('/')[-1].decode('utf-8'),
|
||||
yield YoutubeVideo(entry.id.text.split('/')[-1].decode('utf-8'),
|
||||
title=entry.media.title.text.decode('utf-8').strip(),
|
||||
author=author,
|
||||
duration=int(entry.media.duration.seconds.decode('utf-8').strip()),
|
||||
thumbnail_url=entry.media.thumbnail[0].url.decode('utf-8').strip())
|
||||
|
||||
@check_domain(domain)
|
||||
def iter_page_urls(self, mozaic_url):
|
||||
raise NotImplementedError()
|
||||
|
|
|
|||
|
|
@ -17,17 +17,21 @@
|
|||
|
||||
|
||||
from weboob.tools.browser import BaseBrowser
|
||||
from weboob.tools.browser.decorators import check_domain, id2url
|
||||
|
||||
from .pages import VideoPage
|
||||
from .video import YoutubeVideo
|
||||
|
||||
|
||||
__all__ = ['YoutubeBrowser']
|
||||
|
||||
|
||||
class YoutubeBrowser(BaseBrowser):
|
||||
DOMAIN = u'youtube.com'
|
||||
PAGES = {'.*youtube\.com/watch\?v=(.+)': VideoPage,
|
||||
}
|
||||
|
||||
@id2url(YoutubeVideo.id2url)
|
||||
def get_video(self, url):
|
||||
self.location(url)
|
||||
return self.page.video
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class VideoPage(BasePage):
|
|||
VIDEO_SIGNATURE_REGEX = re.compile(r'&t=([^ ,&]*)')
|
||||
|
||||
def on_loaded(self):
|
||||
self.video = YoutubeVideo(u'youtube:%s' % self.get_id())
|
||||
self.video = YoutubeVideo(self.get_id())
|
||||
self.video.title = self.get_title()
|
||||
self.video.url = self.get_url()
|
||||
self.set_details(self.video)
|
||||
|
|
@ -51,7 +51,7 @@ class VideoPage(BasePage):
|
|||
continue
|
||||
for m in re.finditer(self.VIDEO_SIGNATURE_REGEX, data.text):
|
||||
video_signature = m.group(1)
|
||||
return 'http://www.youtube.com/get_video?video_id=%s&t=%s&fmt=18' % (self.video.id, video_signature)
|
||||
return 'http://www.youtube.com/get_video?video_id=%s&t=%s&fmt=18' % (self.video.provider_id, video_signature)
|
||||
|
||||
def get_title(self):
|
||||
found = self.document.getroot().cssselect('meta[name=title]')
|
||||
|
|
|
|||
|
|
@ -23,6 +23,10 @@ __all__ = ['YoutubeVideo']
|
|||
|
||||
|
||||
class YoutubeVideo(BaseVideo):
|
||||
def __init__(self, *args, **kwargs):
|
||||
BaseVideo.__init__(self, *args, **kwargs)
|
||||
self.id = u'%s@youtube.com' % self.id
|
||||
|
||||
@classmethod
|
||||
def id2url(cls, _id):
|
||||
return 'http://www.youtube.com/watch?v=%s' % _id
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue