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

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