move id2url to tools

This commit is contained in:
Christophe Benz 2010-04-27 12:19:48 +02:00 committed by Romain Bignon
commit 0667774952
12 changed files with 119 additions and 18 deletions

View file

@ -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]

View file

@ -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

View file

@ -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)

View 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)