move id2url to tools
This commit is contained in:
parent
735b79a75d
commit
0667774952
12 changed files with 119 additions and 18 deletions
|
|
@ -23,6 +23,10 @@ from weboob.capabilities.video import ICapVideoProvider
|
|||
|
||||
from .browser import YoujizzBrowser
|
||||
|
||||
|
||||
__all__ = ['YoujizzBackend']
|
||||
|
||||
|
||||
class YoujizzBackend(BaseBackend, ICapVideoProvider):
|
||||
NAME = 'youjizz'
|
||||
MAINTAINER = 'Roger Philibert'
|
||||
|
|
@ -41,6 +45,10 @@ 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]
|
||||
|
|
|
|||
|
|
@ -37,9 +37,6 @@ class YoujizzBrowser(BaseBrowser):
|
|||
r'http://.*youjizz\.com/search/.+\.html': IndexPage,
|
||||
}
|
||||
|
||||
def id2url(self, _id):
|
||||
return 'http://www.youjizz.com/videos/%s.html' % _id
|
||||
|
||||
def get_video(self, url):
|
||||
self.location(url)
|
||||
return self.page.video
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ import re
|
|||
from weboob.capabilities.video import Video
|
||||
from weboob.tools.browser import BasePage
|
||||
|
||||
from .. import tools
|
||||
|
||||
|
||||
__all__ = ['IndexPage']
|
||||
|
||||
|
|
@ -59,4 +61,5 @@ class IndexPage(BasePage):
|
|||
title=title,
|
||||
duration=duration,
|
||||
preview_url=preview_url,
|
||||
nsfw=True)
|
||||
nsfw=True,
|
||||
id2url=tools.id2url)
|
||||
|
|
|
|||
22
weboob/backends/youjizz/tools.py
Normal file
22
weboob/backends/youjizz/tools.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Copyright(C) 2010 Roger Philibert
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
"""
|
||||
|
||||
def id2url(_id):
|
||||
return 'http://www.youjizz.com/videos/%s.html' % _id
|
||||
|
|
@ -23,6 +23,10 @@ from weboob.capabilities.video import ICapVideoProvider
|
|||
|
||||
from .browser import YoupornBrowser
|
||||
|
||||
|
||||
__all__ = ['YoupornBackend']
|
||||
|
||||
|
||||
class YoupornBackend(BaseBackend, ICapVideoProvider):
|
||||
NAME = 'youporn'
|
||||
MAINTAINER = 'Romain Bignon'
|
||||
|
|
@ -41,6 +45,13 @@ 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,6 +22,7 @@ import urllib
|
|||
|
||||
from weboob.tools.browser import BaseBrowser
|
||||
|
||||
from . import tools
|
||||
from .pages.index import IndexPage
|
||||
from .pages.video import VideoPage
|
||||
|
||||
|
|
@ -42,12 +43,6 @@ class YoupornBrowser(BaseBrowser):
|
|||
# Disallow arguments
|
||||
BaseBrowser.__init__(self)
|
||||
|
||||
def id2url(self, _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 iter_search_results(self, pattern, sortby):
|
||||
if not pattern:
|
||||
self.home()
|
||||
|
|
@ -58,5 +53,5 @@ class YoupornBrowser(BaseBrowser):
|
|||
return self.page.iter_videos()
|
||||
|
||||
def get_video(self, _id):
|
||||
self.location(self.id2url(_id))
|
||||
self.location(tools.id2url(_id))
|
||||
return self.page.video
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ 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
|
||||
|
||||
|
||||
|
|
@ -71,4 +72,5 @@ class IndexPage(PornPage):
|
|||
rating_max=rating_max,
|
||||
duration=duration,
|
||||
preview_url=preview_url,
|
||||
nsfw=True)
|
||||
nsfw=True,
|
||||
id2url=tools.id2url)
|
||||
|
|
|
|||
25
weboob/backends/youporn/tools.py
Normal file
25
weboob/backends/youporn/tools.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Copyright(C) 2010 Roger Philibert
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
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)
|
||||
|
|
@ -24,8 +24,13 @@ import re
|
|||
from weboob.backend import BaseBackend
|
||||
from weboob.capabilities.video import ICapVideoProvider, Video
|
||||
|
||||
from . import tools
|
||||
from .browser import YoutubeBrowser
|
||||
|
||||
|
||||
__all__ = ['YoutubeBackend']
|
||||
|
||||
|
||||
class YoutubeBackend(BaseBackend, ICapVideoProvider):
|
||||
NAME = 'youtube'
|
||||
MAINTAINER = 'Christophe Benz'
|
||||
|
|
@ -44,6 +49,10 @@ 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)
|
||||
|
||||
|
|
@ -69,7 +78,8 @@ class YoutubeBackend(BaseBackend, ICapVideoProvider):
|
|||
title=entry.media.title.text.decode('utf-8').strip(),
|
||||
author=author,
|
||||
duration=int(entry.media.duration.seconds.decode('utf-8').strip()),
|
||||
preview_url=entry.media.thumbnail[0].url.decode('utf-8').strip())
|
||||
preview_url=entry.media.thumbnail[0].url.decode('utf-8').strip(),
|
||||
id2url=tools.id2url)
|
||||
|
||||
def iter_page_urls(self, mozaic_url):
|
||||
raise NotImplementedError()
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import urllib
|
|||
|
||||
from weboob.tools.browser import BaseBrowser
|
||||
|
||||
from . import tools
|
||||
from .pages import VideoPage
|
||||
|
||||
__all__ = ['YoutubeBrowser']
|
||||
|
|
@ -30,9 +31,6 @@ class YoutubeBrowser(BaseBrowser):
|
|||
PAGES = {'.*youtube\.com/watch\?v=(.+)': VideoPage,
|
||||
}
|
||||
|
||||
def id2url(self, _id):
|
||||
return _id if 'youtube.com' in _id else 'http://www.youtube.com/watch?v=%s' % _id
|
||||
|
||||
def get_video(self, _id):
|
||||
self.location(self.id2url(_id))
|
||||
self.location(tools.id2url(_id))
|
||||
return self.page.video
|
||||
|
|
|
|||
22
weboob/backends/youtube/tools.py
Normal file
22
weboob/backends/youtube/tools.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Copyright(C) 2010 Christophe Benz
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
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
|
||||
|
|
@ -26,7 +26,7 @@ __all__ = ['ICapVideoProvider', 'Video']
|
|||
|
||||
class Video(object):
|
||||
def __init__(self, _id, title=None, url=None, author=None, duration=0, date=None,
|
||||
rating=0.0, rating_max=0.0, preview_url=None, nsfw=False):
|
||||
rating=0.0, rating_max=0.0, preview_url=None, nsfw=False, id2url=None):
|
||||
self.id = _id
|
||||
self.title = title
|
||||
self.url = url
|
||||
|
|
@ -37,11 +37,19 @@ class Video(object):
|
|||
self.rating_max = float(rating_max)
|
||||
self.preview_url = preview_url
|
||||
self.nsfw = nsfw
|
||||
self.id2url = id2url
|
||||
|
||||
@property
|
||||
def formatted_duration(self):
|
||||
return '%d:%02d:%02d' % (self.duration / 3600, (self.duration % 3600 / 60), self.duration % 60)
|
||||
|
||||
@property
|
||||
def page_url(self):
|
||||
if self.id2url:
|
||||
return self.id2url(self.id)
|
||||
else:
|
||||
return None
|
||||
|
||||
class ICapVideoProvider(ICap):
|
||||
def iter_page_urls(self, mozaic_url):
|
||||
raise NotImplementedError()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue