move id2url to Video class

This commit is contained in:
Christophe Benz 2010-04-28 14:49:50 +02:00
commit 7bd936c11b
14 changed files with 69 additions and 76 deletions

View file

@ -45,10 +45,6 @@ class YoujizzBackend(BaseBackend, ICapVideoProvider):
return self._browser return self._browser
raise AttributeError, name raise AttributeError, name
@classmethod
def id2url(cls, _id):
return 'http://www.youjizz.com/videos/%s.html' % _id
def check_url(func): def check_url(func):
def inner(self, *args, **kwargs): def inner(self, *args, **kwargs):
url = args[0] url = args[0]

View file

@ -20,10 +20,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import re import re
from weboob.capabilities.video import Video
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
from .. import tools from ..video import YoujizzVideo
__all__ = ['IndexPage'] __all__ = ['IndexPage']
@ -57,9 +56,8 @@ class IndexPage(BasePage):
minutes, seconds = time_span.text.strip().split(':') minutes, seconds = time_span.text.strip().split(':')
duration = 60 * int(minutes) + int(seconds) duration = 60 * int(minutes) + int(seconds)
yield Video(_id, yield YoujizzVideo(_id,
title=title, title=title,
duration=duration, duration=duration,
thumbnail_url=thumbnail_url, thumbnail_url=thumbnail_url,
nsfw=True, nsfw=True)
id2url=tools.id2url)

View file

@ -21,17 +21,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from logging import error, warning from logging import error, warning
import re import re
from weboob.capabilities.video import Video
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
from ..video import YoujizzVideo
class VideoPage(BasePage): class VideoPage(BasePage):
URL_REGEX = re.compile(r'http://.*youjizz\.com/videos/.+-(\d+)\.html') URL_REGEX = re.compile(r'http://.*youjizz\.com/videos/.+-(\d+)\.html')
VIDEO_FILE_REGEX = re.compile(r'"(http://media[^ ,]+\.flv)"') VIDEO_FILE_REGEX = re.compile(r'"(http://media[^ ,]+\.flv)"')
def on_loaded(self): def on_loaded(self):
details = self.get_details() details = self.get_details()
self.video = Video(_id=self.get_id(), title=details.get('title', u''), url=self.get_url(), self.video = YoujizzVideo(_id=self.get_id(), title=details.get('title', u''), url=self.get_url(),
duration=details.get('duration', 0), nsfw=True) duration=details.get('duration', 0), nsfw=True)
def get_id(self): def get_id(self):
m = self.URL_REGEX.match(self.url) m = self.URL_REGEX.match(self.url)

View file

@ -18,5 +18,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" """
def id2url(_id): from weboob.capabilities.video import BaseVideo
return 'http://www.youjizz.com/videos/%s.html' % _id
class YoujizzVideo(BaseVideo):
@classmethod
def id2url(cls, _id):
return 'http://www.youjizz.com/videos/%s.html' % _id

View file

@ -45,13 +45,6 @@ class YoupornBackend(BaseBackend, ICapVideoProvider):
return self._browser return self._browser
raise AttributeError, name raise AttributeError, name
@classmethod
def id2url(cls, _id):
if isinstance(_id, int) or isinstance(_id, (str,unicode)) and _id.isdigit():
return 'http://www.youporn.com/watch/%d' % int(_id)
else:
return str(_id)
def need_url(func): def need_url(func):
def inner(self, *args, **kwargs): def inner(self, *args, **kwargs):
url = args[0] url = args[0]

View file

@ -22,9 +22,9 @@ import urllib
from weboob.tools.browser import BaseBrowser from weboob.tools.browser import BaseBrowser
from . import tools
from .pages.index import IndexPage from .pages.index import IndexPage
from .pages.video import VideoPage from .pages.video import VideoPage
from .video import YoupornVideo
__all__ = ['YoupornBrowser'] __all__ = ['YoupornBrowser']
@ -53,5 +53,5 @@ class YoupornBrowser(BaseBrowser):
return self.page.iter_videos() return self.page.iter_videos()
def get_video(self, _id): def get_video(self, _id):
self.location(tools.id2url(_id)) self.location(YoupornVideo.id2url(_id))
return self.page.video return self.page.video

View file

@ -18,10 +18,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" """
from weboob.capabilities.video import Video
from .. import tools
from .base import PornPage from .base import PornPage
from ..video import YoupornVideo
__all__ = ['IndexPage'] __all__ = ['IndexPage']
@ -66,11 +64,10 @@ class IndexPage(PornPage):
rating = float(p.text.strip()) rating = float(p.text.strip())
rating_max = float(p.find('span').text.strip()[2:]) rating_max = float(p.find('span').text.strip()[2:])
yield Video(int(_id), yield YoupornVideo(int(_id),
title=title, title=title,
rating=rating, rating=rating,
rating_max=rating_max, rating_max=rating_max,
duration=duration, duration=duration,
thumbnail_url=thumbnail_url, thumbnail_url=thumbnail_url,
nsfw=True, nsfw=True)
id2url=tools.id2url)

View file

@ -23,7 +23,7 @@ import datetime
from logging import warning from logging import warning
from .base import PornPage from .base import PornPage
from weboob.capabilities.video import Video from ..video import YoupornVideo
class VideoPage(PornPage): class VideoPage(PornPage):
URL_REGEXP = re.compile("https?://[w\.]*youporn.com/watch/(\d+)/?.*") URL_REGEXP = re.compile("https?://[w\.]*youporn.com/watch/(\d+)/?.*")
@ -32,10 +32,10 @@ class VideoPage(PornPage):
if not PornPage.on_loaded(self): if not PornPage.on_loaded(self):
return return
self.video = Video(self.get_id(), self.video = YoupornVideo(self.get_id(),
self.get_title(), self.get_title(),
self.get_url(), self.get_url(),
nsfw=True) nsfw=True)
self.set_details(self.video) self.set_details(self.video)

View file

@ -18,8 +18,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" """
def id2url(_id): from weboob.capabilities.video import BaseVideo
if isinstance(_id, int) or isinstance(_id, (str,unicode)) and _id.isdigit():
return 'http://www.youporn.com/watch/%d' % int(_id) class YoupornVideo(BaseVideo):
else: @classmethod
return str(_id) def id2url(cls, _id):
if isinstance(_id, int) or isinstance(_id, (str,unicode)) and _id.isdigit():
return 'http://www.youporn.com/watch/%d' % int(_id)
else:
return str(_id)

View file

@ -19,13 +19,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" """
import logging import logging
import re
from weboob.backend import BaseBackend 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 .browser import YoutubeBrowser
from .video import YoutubeVideo
__all__ = ['YoutubeBackend'] __all__ = ['YoutubeBackend']
@ -49,10 +48,6 @@ class YoutubeBackend(BaseBackend, ICapVideoProvider):
return self._browser return self._browser
raise AttributeError, name 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): def get_video(self, _id):
return self.browser.get_video(_id) return self.browser.get_video(_id)
@ -74,12 +69,11 @@ class YoutubeBackend(BaseBackend, ICapVideoProvider):
author = entry.media.name.text.decode('utf-8').strip() author = entry.media.name.text.decode('utf-8').strip()
else: else:
author = None author = None
yield Video(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(), title=entry.media.title.text.decode('utf-8').strip(),
author=author, author=author,
duration=int(entry.media.duration.seconds.decode('utf-8').strip()), duration=int(entry.media.duration.seconds.decode('utf-8').strip()),
thumbnail_url=entry.media.thumbnail[0].url.decode('utf-8').strip(), thumbnail_url=entry.media.thumbnail[0].url.decode('utf-8').strip())
id2url=tools.id2url)
def iter_page_urls(self, mozaic_url): def iter_page_urls(self, mozaic_url):
raise NotImplementedError() raise NotImplementedError()

View file

@ -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 weboob.tools.browser import BaseBrowser
from . import tools
from .pages import VideoPage from .pages import VideoPage
from .video import YoutubeVideo
__all__ = ['YoutubeBrowser'] __all__ = ['YoutubeBrowser']
@ -32,5 +30,5 @@ class YoutubeBrowser(BaseBrowser):
} }
def get_video(self, _id): def get_video(self, _id):
self.location(tools.id2url(_id)) self.location(YoutubeVideo.id2url(_id))
return self.page.video return self.page.video

View file

@ -22,14 +22,16 @@ import re
from logging import warning from logging import warning
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
from weboob.capabilities.video import Video
from ..video import YoutubeVideo
class VideoPage(BasePage): class VideoPage(BasePage):
URL_REGEX = re.compile(r"https?://[w\.]*youtube.com/watch\?v=(.+)") URL_REGEX = re.compile(r"https?://[w\.]*youtube.com/watch\?v=(.+)")
VIDEO_SIGNATURE_REGEX = re.compile(r'&t=([^ ,&]*)') VIDEO_SIGNATURE_REGEX = re.compile(r'&t=([^ ,&]*)')
def on_loaded(self): def on_loaded(self):
self.video = Video(self.get_id()) self.video = YoutubeVideo(self.get_id())
self.video.title = self.get_title() self.video.title = self.get_title()
self.video.url = self.get_url() self.video.url = self.get_url()
self.set_details(self.video) self.set_details(self.video)

View file

@ -18,5 +18,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" """
def id2url(_id): from weboob.capabilities.video import BaseVideo
return _id if 'youtube.com' in _id else 'http://www.youtube.com/watch?v=%s' % _id
class YoutubeVideo(BaseVideo):
@classmethod
def id2url(cls, _id):
return _id if 'youtube.com' in _id else 'http://www.youtube.com/watch?v=%s' % _id

View file

@ -21,12 +21,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from .cap import ICap from .cap import ICap
__all__ = ['ICapVideoProvider', 'Video'] __all__ = ['BaseVideo', 'ICapVideoProvider']
class Video(object): class BaseVideo(object):
def __init__(self, _id, title=None, url=None, author=None, duration=0, date=None, def __init__(self, _id, title=None, url=None, author=None, duration=0, date=None,
rating=0.0, rating_max=0.0, thumbnail_url=None, nsfw=False, id2url=None): rating=0.0, rating_max=0.0, thumbnail_url=None, nsfw=False):
self.id = _id self.id = _id
self.title = title self.title = title
self.url = url self.url = url
@ -37,7 +37,11 @@ class Video(object):
self.rating_max = float(rating_max) self.rating_max = float(rating_max)
self.thumbnail_url = thumbnail_url self.thumbnail_url = thumbnail_url
self.nsfw = nsfw self.nsfw = nsfw
self.id2url = id2url
@classmethod
def id2url(cls, _id):
"""Overloaded in child classes provided by backends."""
raise NotImplementedError()
@property @property
def formatted_duration(self): def formatted_duration(self):
@ -45,10 +49,8 @@ class Video(object):
@property @property
def page_url(self): def page_url(self):
if self.id2url: return self.id2url(self.id)
return self.id2url(self.id)
else:
return None
class ICapVideoProvider(ICap): class ICapVideoProvider(ICap):
def iter_page_urls(self, mozaic_url): def iter_page_urls(self, mozaic_url):