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

View file

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

View 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