better handle IDs in video backends, enhance user interaction

This commit is contained in:
Christophe Benz 2010-05-20 01:34:41 +02:00
commit 2b93eec3c9
16 changed files with 228 additions and 214 deletions

View file

@ -115,3 +115,36 @@ class BaseBackend(object):
if isinstance(self, c):
return True
return False
def check_domain(domain):
def wrapper(func):
def inner(self, *args, **kwargs):
url = args[0]
if isinstance(url, (str,unicode)) and not url.isdigit() and u'youjizz.com' not in url:
return None
return func(self, *args, **kwargs)
return inner
return wrapper
def id2url(domain, id2url):
def wrapper(func):
def inner(self, *args, **kwargs):
arg = unicode(args[0])
if arg.startswith('http://'):
if domain in arg:
url = arg
else:
return None
else:
provider, _id = arg.split(':')
if provider == self.name:
url = id2url(_id)
else:
return None
new_args = [url]
new_args.extend(args[1:])
return func(self, *new_args, **kwargs)
return inner
return wrapper

View file

@ -1,27 +1,26 @@
# -*- coding: utf-8 -*-
"""
Copyright(C) 2010 Roger Philibert
# 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.
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.
"""
from weboob.backend import BaseBackend
from weboob.backend import check_domain, id2url, BaseBackend
from weboob.capabilities.video import ICapVideoProvider
from .browser import YoujizzBrowser
from .video import YoujizzVideo
__all__ = ['YoujizzBackend']
@ -37,6 +36,7 @@ class YoujizzBackend(BaseBackend, ICapVideoProvider):
CONFIG = {}
_browser = None
domain = u'youjizz.com'
def __getattr__(self, name):
if name == 'browser':
@ -45,19 +45,11 @@ class YoujizzBackend(BaseBackend, ICapVideoProvider):
return self._browser
raise AttributeError, name
def check_url(func):
def inner(self, *args, **kwargs):
url = args[0]
if isinstance(url, (str,unicode)) and not url.isdigit() and u'youjizz.com' not in url:
return None
return func(self, *args, **kwargs)
return inner
@check_url
@id2url(domain, YoujizzVideo.id2url)
def get_video(self, _id):
return self.browser.get_video(_id)
@check_url
@check_domain(domain)
def iter_page_urls(self, mozaic_url):
return self.browser.iter_page_urls(mozaic_url)

View file

@ -1,22 +1,20 @@
# -*- coding: utf-8 -*-
"""
Copyright(C) 2010 Roger Philibert
# 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.
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.
"""
import re
@ -56,7 +54,7 @@ class IndexPage(BasePage):
minutes, seconds = time_span.text.strip().split(':')
duration = 60 * int(minutes) + int(seconds)
yield YoujizzVideo(_id,
yield YoujizzVideo(u'youjizz:%s' % _id,
title=title,
duration=duration,
thumbnail_url=thumbnail_url,

View file

@ -1,25 +1,27 @@
# -*- coding: utf-8 -*-
"""
Copyright(C) 2010 Roger Philibert
# 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.
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.
"""
from weboob.capabilities.video import BaseVideo
__all__ = ['YoujizzVideo']
class YoujizzVideo(BaseVideo):
@classmethod
def id2url(cls, _id):

View file

@ -1,27 +1,26 @@
# -*- coding: utf-8 -*-
"""
Copyright(C) 2010 Romain Bignon
# Copyright(C) 2010 Romain Bignon
#
# 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.
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.
"""
from weboob.backend import BaseBackend
from weboob.backend import check_domain, id2url, BaseBackend
from weboob.capabilities.video import ICapVideoProvider
from .browser import YoupornBrowser
from .video import YoupornVideo
__all__ = ['YoupornBackend']
@ -37,6 +36,7 @@ class YoupornBackend(BaseBackend, ICapVideoProvider):
CONFIG = {}
_browser = None
domain = u'youporn.com'
def __getattr__(self, name):
if name == 'browser':
@ -45,15 +45,7 @@ class YoupornBackend(BaseBackend, ICapVideoProvider):
return self._browser
raise AttributeError, name
def need_url(func):
def inner(self, *args, **kwargs):
url = args[0]
if isinstance(url, (str,unicode)) and not url.isdigit() and u'youporn.com' not in url:
return None
return func(self, *args, **kwargs)
return inner
@need_url
@id2url(domain, YoupornVideo.id2url)
def get_video(self, _id):
return self.browser.get_video(_id)
@ -63,6 +55,6 @@ class YoupornBackend(BaseBackend, ICapVideoProvider):
return iter(set())
return self.browser.iter_search_results(pattern, self.SORTBY[sortby])
@need_url
@check_domain(domain)
def iter_page_urls(self, mozaic_url):
raise NotImplementedError()

View file

@ -50,6 +50,6 @@ class YoupornBrowser(BaseBrowser):
assert self.is_on_page(IndexPage)
return self.page.iter_videos()
def get_video(self, _id):
self.location(YoupornVideo.id2url(_id))
def get_video(self, url):
self.location(url)
return self.page.video

View file

@ -64,7 +64,7 @@ class IndexPage(PornPage):
rating = float(p.text.strip())
rating_max = float(p.find('span').text.strip()[2:])
yield YoupornVideo(int(_id),
yield YoupornVideo('youporn:%d' % int(_id),
title=title,
rating=rating,
rating_max=rating_max,

View file

@ -32,7 +32,7 @@ class VideoPage(PornPage):
if not PornPage.on_loaded(self):
return
self.video = YoupornVideo(self.get_id(),
self.video = YoupornVideo('youporn:%d' % self.get_id(),
self.get_title(),
self.get_url(),
nsfw=True)

View file

@ -1,29 +1,28 @@
# -*- coding: utf-8 -*-
"""
Copyright(C) 2010 Roger Philibert
# 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.
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.
"""
from weboob.capabilities.video import BaseVideo
__all__ = ['YoupornVideo']
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)
return 'http://www.youporn.com/watch/%d' % int(_id)

View file

@ -1,21 +1,18 @@
# -*- 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.
"""
# 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.
from .backend import YoutubeBackend

View file

@ -1,26 +1,24 @@
# -*- coding: utf-8 -*-
"""
Copyright(C) 2010 Christophe Benz, Romain Bignon
# Copyright(C) 2010 Christophe Benz, Romain Bignon
#
# 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.
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.
"""
import logging
from weboob.backend import BaseBackend
from weboob.backend import check_domain, id2url, BaseBackend
from weboob.capabilities.video import ICapVideoProvider
from .browser import YoutubeBrowser
@ -40,6 +38,7 @@ class YoutubeBackend(BaseBackend, ICapVideoProvider):
CONFIG = {}
_browser = None
domain = u'youtube.com'
def __getattr__(self, name):
if name == 'browser':
@ -48,6 +47,7 @@ class YoutubeBackend(BaseBackend, ICapVideoProvider):
return self._browser
raise AttributeError, name
@id2url(domain, YoutubeVideo.id2url)
def get_video(self, _id):
return self.browser.get_video(_id)
@ -69,11 +69,12 @@ class YoutubeBackend(BaseBackend, ICapVideoProvider):
author = entry.media.name.text.decode('utf-8').strip()
else:
author = None
yield YoutubeVideo(entry.id.text.split('/')[-1].decode('utf-8'),
yield YoutubeVideo(u'youtube:%s' % 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())
@check_domain(domain)
def iter_page_urls(self, mozaic_url):
raise NotImplementedError()

View file

@ -1,34 +1,34 @@
# -*- coding: utf-8 -*-
"""
Copyright(C) 2010 Christophe Benz, Romain Bignon
# Copyright(C) 2010 Christophe Benz, Romain Bignon
#
# 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.
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.
"""
from weboob.tools.browser import BaseBrowser
from .pages import VideoPage
from .video import YoutubeVideo
__all__ = ['YoutubeBrowser']
class YoutubeBrowser(BaseBrowser):
PAGES = {'.*youtube\.com/watch\?v=(.+)': VideoPage,
}
def get_video(self, _id):
self.location(YoutubeVideo.id2url(_id))
def get_video(self, url):
self.location(url)
return self.page.video

View file

@ -1,21 +1,18 @@
# -*- 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.
"""
# 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.
from .video import VideoPage

View file

@ -1,22 +1,20 @@
# -*- coding: utf-8 -*-
"""
Copyright(C) 2010 Christophe Benz, Romain Bignon
# Copyright(C) 2010 Christophe Benz, Romain Bignon
#
# 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.
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.
"""
import re
from logging import warning
@ -26,12 +24,15 @@ from weboob.tools.browser import BasePage
from ..video import YoutubeVideo
__all__ = ['VideoPage']
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 = YoutubeVideo(self.get_id())
self.video = YoutubeVideo(u'youtube:%s' % self.get_id())
self.video.title = self.get_title()
self.video.url = self.get_url()
self.set_details(self.video)

View file

@ -1,26 +1,28 @@
# -*- coding: utf-8 -*-
"""
Copyright(C) 2010 Christophe Benz
# 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.
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.
"""
from weboob.capabilities.video import BaseVideo
__all__ = ['YoutubeVideo']
class YoutubeVideo(BaseVideo):
@classmethod
def id2url(cls, _id):
return _id if 'youtube.com' in _id else 'http://www.youtube.com/watch?v=%s' % _id
return 'http://www.youtube.com/watch?v=%s' % _id

View file

@ -49,7 +49,7 @@ class BaseVideo(object):
@property
def page_url(self):
return self.id2url(self.id)
return self.id2url(self.id.split(':')[1])
class ICapVideoProvider(ICap):