move id2url to Video class
This commit is contained in:
parent
f7a92d9c72
commit
7bd936c11b
14 changed files with 69 additions and 76 deletions
|
|
@ -45,10 +45,6 @@ class YoujizzBackend(BaseBackend, ICapVideoProvider):
|
|||
return self._browser
|
||||
raise AttributeError, name
|
||||
|
||||
@classmethod
|
||||
def id2url(cls, _id):
|
||||
return 'http://www.youjizz.com/videos/%s.html' % _id
|
||||
|
||||
def check_url(func):
|
||||
def inner(self, *args, **kwargs):
|
||||
url = args[0]
|
||||
|
|
|
|||
|
|
@ -20,10 +20,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
import re
|
||||
|
||||
from weboob.capabilities.video import Video
|
||||
from weboob.tools.browser import BasePage
|
||||
|
||||
from .. import tools
|
||||
from ..video import YoujizzVideo
|
||||
|
||||
|
||||
__all__ = ['IndexPage']
|
||||
|
|
@ -57,9 +56,8 @@ class IndexPage(BasePage):
|
|||
minutes, seconds = time_span.text.strip().split(':')
|
||||
duration = 60 * int(minutes) + int(seconds)
|
||||
|
||||
yield Video(_id,
|
||||
title=title,
|
||||
duration=duration,
|
||||
thumbnail_url=thumbnail_url,
|
||||
nsfw=True,
|
||||
id2url=tools.id2url)
|
||||
yield YoujizzVideo(_id,
|
||||
title=title,
|
||||
duration=duration,
|
||||
thumbnail_url=thumbnail_url,
|
||||
nsfw=True)
|
||||
|
|
|
|||
|
|
@ -21,17 +21,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
from logging import error, warning
|
||||
import re
|
||||
|
||||
from weboob.capabilities.video import Video
|
||||
from weboob.tools.browser import BasePage
|
||||
|
||||
from ..video import YoujizzVideo
|
||||
|
||||
class VideoPage(BasePage):
|
||||
URL_REGEX = re.compile(r'http://.*youjizz\.com/videos/.+-(\d+)\.html')
|
||||
VIDEO_FILE_REGEX = re.compile(r'"(http://media[^ ,]+\.flv)"')
|
||||
|
||||
def on_loaded(self):
|
||||
details = self.get_details()
|
||||
self.video = Video(_id=self.get_id(), title=details.get('title', u''), url=self.get_url(),
|
||||
duration=details.get('duration', 0), nsfw=True)
|
||||
self.video = YoujizzVideo(_id=self.get_id(), title=details.get('title', u''), url=self.get_url(),
|
||||
duration=details.get('duration', 0), nsfw=True)
|
||||
|
||||
def get_id(self):
|
||||
m = self.URL_REGEX.match(self.url)
|
||||
|
|
|
|||
|
|
@ -18,5 +18,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
"""
|
||||
|
||||
def id2url(_id):
|
||||
return 'http://www.youjizz.com/videos/%s.html' % _id
|
||||
from weboob.capabilities.video import BaseVideo
|
||||
|
||||
class YoujizzVideo(BaseVideo):
|
||||
@classmethod
|
||||
def id2url(cls, _id):
|
||||
return 'http://www.youjizz.com/videos/%s.html' % _id
|
||||
|
|
@ -45,13 +45,6 @@ class YoupornBackend(BaseBackend, ICapVideoProvider):
|
|||
return self._browser
|
||||
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 inner(self, *args, **kwargs):
|
||||
url = args[0]
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ import urllib
|
|||
|
||||
from weboob.tools.browser import BaseBrowser
|
||||
|
||||
from . import tools
|
||||
from .pages.index import IndexPage
|
||||
from .pages.video import VideoPage
|
||||
from .video import YoupornVideo
|
||||
|
||||
|
||||
__all__ = ['YoupornBrowser']
|
||||
|
|
@ -53,5 +53,5 @@ class YoupornBrowser(BaseBrowser):
|
|||
return self.page.iter_videos()
|
||||
|
||||
def get_video(self, _id):
|
||||
self.location(tools.id2url(_id))
|
||||
self.location(YoupornVideo.id2url(_id))
|
||||
return self.page.video
|
||||
|
|
|
|||
|
|
@ -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 ..video import YoupornVideo
|
||||
|
||||
|
||||
__all__ = ['IndexPage']
|
||||
|
|
@ -66,11 +64,10 @@ class IndexPage(PornPage):
|
|||
rating = float(p.text.strip())
|
||||
rating_max = float(p.find('span').text.strip()[2:])
|
||||
|
||||
yield Video(int(_id),
|
||||
title=title,
|
||||
rating=rating,
|
||||
rating_max=rating_max,
|
||||
duration=duration,
|
||||
thumbnail_url=thumbnail_url,
|
||||
nsfw=True,
|
||||
id2url=tools.id2url)
|
||||
yield YoupornVideo(int(_id),
|
||||
title=title,
|
||||
rating=rating,
|
||||
rating_max=rating_max,
|
||||
duration=duration,
|
||||
thumbnail_url=thumbnail_url,
|
||||
nsfw=True)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import datetime
|
|||
from logging import warning
|
||||
|
||||
from .base import PornPage
|
||||
from weboob.capabilities.video import Video
|
||||
from ..video import YoupornVideo
|
||||
|
||||
class VideoPage(PornPage):
|
||||
URL_REGEXP = re.compile("https?://[w\.]*youporn.com/watch/(\d+)/?.*")
|
||||
|
|
@ -32,10 +32,10 @@ class VideoPage(PornPage):
|
|||
if not PornPage.on_loaded(self):
|
||||
return
|
||||
|
||||
self.video = Video(self.get_id(),
|
||||
self.get_title(),
|
||||
self.get_url(),
|
||||
nsfw=True)
|
||||
self.video = YoupornVideo(self.get_id(),
|
||||
self.get_title(),
|
||||
self.get_url(),
|
||||
nsfw=True)
|
||||
|
||||
self.set_details(self.video)
|
||||
|
||||
|
|
|
|||
|
|
@ -18,8 +18,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
"""
|
||||
|
||||
def id2url(_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)
|
||||
from weboob.capabilities.video import BaseVideo
|
||||
|
||||
class YoupornVideo(BaseVideo):
|
||||
@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)
|
||||
|
|
@ -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
|
||||
|
|
@ -21,12 +21,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
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,
|
||||
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.title = title
|
||||
self.url = url
|
||||
|
|
@ -37,7 +37,11 @@ class Video(object):
|
|||
self.rating_max = float(rating_max)
|
||||
self.thumbnail_url = thumbnail_url
|
||||
self.nsfw = nsfw
|
||||
self.id2url = id2url
|
||||
|
||||
@classmethod
|
||||
def id2url(cls, _id):
|
||||
"""Overloaded in child classes provided by backends."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
def formatted_duration(self):
|
||||
|
|
@ -45,10 +49,8 @@ class Video(object):
|
|||
|
||||
@property
|
||||
def page_url(self):
|
||||
if self.id2url:
|
||||
return self.id2url(self.id)
|
||||
else:
|
||||
return None
|
||||
return self.id2url(self.id)
|
||||
|
||||
|
||||
class ICapVideoProvider(ICap):
|
||||
def iter_page_urls(self, mozaic_url):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue