move id2url to Video class
This commit is contained in:
parent
f7a92d9c72
commit
7bd936c11b
14 changed files with 69 additions and 76 deletions
|
|
@ -19,13 +19,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
"""
|
||||
|
||||
import logging
|
||||
import re
|
||||
|
||||
from weboob.backend import BaseBackend
|
||||
from weboob.capabilities.video import ICapVideoProvider, Video
|
||||
from weboob.capabilities.video import ICapVideoProvider
|
||||
|
||||
from . import tools
|
||||
from .browser import YoutubeBrowser
|
||||
from .video import YoutubeVideo
|
||||
|
||||
|
||||
__all__ = ['YoutubeBackend']
|
||||
|
|
@ -49,10 +48,6 @@ class YoutubeBackend(BaseBackend, ICapVideoProvider):
|
|||
return self._browser
|
||||
raise AttributeError, name
|
||||
|
||||
@classmethod
|
||||
def id2url(cls, _id):
|
||||
return _id if 'youtube.com' in _id else 'http://www.youtube.com/watch?v=%s' % _id
|
||||
|
||||
def get_video(self, _id):
|
||||
return self.browser.get_video(_id)
|
||||
|
||||
|
|
@ -74,12 +69,11 @@ class YoutubeBackend(BaseBackend, ICapVideoProvider):
|
|||
author = entry.media.name.text.decode('utf-8').strip()
|
||||
else:
|
||||
author = None
|
||||
yield Video(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(),
|
||||
id2url=tools.id2url)
|
||||
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())
|
||||
|
||||
def iter_page_urls(self, mozaic_url):
|
||||
raise NotImplementedError()
|
||||
|
|
|
|||
|
|
@ -18,12 +18,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
"""
|
||||
|
||||
import urllib
|
||||
|
||||
from weboob.tools.browser import BaseBrowser
|
||||
|
||||
from . import tools
|
||||
from .pages import VideoPage
|
||||
from .video import YoutubeVideo
|
||||
|
||||
__all__ = ['YoutubeBrowser']
|
||||
|
||||
|
|
@ -32,5 +30,5 @@ class YoutubeBrowser(BaseBrowser):
|
|||
}
|
||||
|
||||
def get_video(self, _id):
|
||||
self.location(tools.id2url(_id))
|
||||
self.location(YoutubeVideo.id2url(_id))
|
||||
return self.page.video
|
||||
|
|
|
|||
|
|
@ -22,14 +22,16 @@ import re
|
|||
from logging import warning
|
||||
|
||||
from weboob.tools.browser import BasePage
|
||||
from weboob.capabilities.video import Video
|
||||
|
||||
from ..video import YoutubeVideo
|
||||
|
||||
|
||||
class VideoPage(BasePage):
|
||||
URL_REGEX = re.compile(r"https?://[w\.]*youtube.com/watch\?v=(.+)")
|
||||
VIDEO_SIGNATURE_REGEX = re.compile(r'&t=([^ ,&]*)')
|
||||
|
||||
def on_loaded(self):
|
||||
self.video = Video(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)
|
||||
|
|
|
|||
|
|
@ -18,5 +18,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
"""
|
||||
|
||||
def id2url(_id):
|
||||
return _id if 'youtube.com' in _id else 'http://www.youtube.com/watch?v=%s' % _id
|
||||
from weboob.capabilities.video import BaseVideo
|
||||
|
||||
class YoutubeVideo(BaseVideo):
|
||||
@classmethod
|
||||
def id2url(cls, _id):
|
||||
return _id if 'youtube.com' in _id else 'http://www.youtube.com/watch?v=%s' % _id
|
||||
Loading…
Add table
Add a link
Reference in a new issue