Put Thumbnail in a tools.capabilities

This commit is contained in:
Noe Rubinstein 2011-05-02 00:51:09 +02:00
commit afe5db74b4
6 changed files with 44 additions and 40 deletions

View file

@ -20,7 +20,7 @@
from datetime import datetime
from weboob.capabilities.video import VideoThumbnail
from weboob.tools.capabilities.thumbnail import Thumbnail
from weboob.tools.browser import BasePage
from .video import CanalplusVideo
@ -49,7 +49,7 @@ class VideoPage(BasePage):
video.description = infos.find('DESCRIPTION').text
media = el.find('MEDIA')
video.thumbnail = VideoThumbnail(media.find('IMAGES').find('PETIT').text)
video.thumbnail = Thumbnail(media.find('IMAGES').find('PETIT').text)
lastest_format = None
for format in media.find('VIDEOS'):
if format.text is None:

View file

@ -21,7 +21,7 @@ import datetime
import urllib
import re
from weboob.capabilities.video import VideoThumbnail
from weboob.tools.capabilities.thumbnail import Thumbnail
from weboob.tools.misc import html2text
from weboob.tools.browser import BasePage
@ -52,7 +52,7 @@ class IndexPage(BasePage):
minutes, seconds = self.parser.select(div, 'div.duration', 1).text.split(':')
video.duration = datetime.timedelta(minutes=int(minutes), seconds=int(seconds))
url = self.parser.select(div, 'img.dmco_image', 1).attrib['src']
video.thumbnail = VideoThumbnail(url)
video.thumbnail = Thumbnail(url)
rating_div = self.parser.select(div, 'div.small_stars', 1)
video.rating_max = self.get_rate(rating_div)

View file

@ -19,7 +19,7 @@
from weboob.tools.browser import BasePage
from weboob.tools.misc import html2text
from weboob.capabilities.gallery import Thumbnail
from weboob.tools.capabilities.thumbnail import Thumbnail
from datetime import datetime
import re

View file

@ -19,27 +19,12 @@
from datetime import datetime
from weboob.tools.capabilities.thumbnail import Thumbnail
from .base import IBaseCap, CapBaseObject, NotLoaded
__all__ = ['Thumbnail', 'ICapGallery', 'BaseGallery', 'BaseImage']
class Thumbnail(CapBaseObject):
def __init__(self, url):
CapBaseObject.__init__(self, url)
self.add_field('url', basestring, url.replace(' ', '%20'))
self.add_field('data', str)
def __str__(self):
return self.url
def __repr__(self):
return '<Thumbnail url="%s">' % self.url
def __iscomplete__(self):
return self.data is not NotLoaded
class BaseGallery(CapBaseObject):
"""
Represents a gallery.

View file

@ -21,27 +21,11 @@
from datetime import datetime, timedelta
from .base import IBaseCap, CapBaseObject, NotLoaded
from weboob.tools.capabilities.thumbnail import Thumbnail
__all__ = ['BaseVideo', 'ICapVideo']
class VideoThumbnail(CapBaseObject):
def __init__(self, url):
CapBaseObject.__init__(self, url)
self.add_field('url', basestring, url.replace(' ', '%20'))
self.add_field('data', str)
def __str__(self):
return self.url
def __repr__(self):
return '<Thumbnail url="%s">' % self.url
def __iscomplete__(self):
return self.data is not NotLoaded
class BaseVideo(CapBaseObject):
"""
Represents a video.
@ -60,12 +44,12 @@ class BaseVideo(CapBaseObject):
self.add_field('date', datetime, date)
self.add_field('rating', (int,long,float), rating)
self.add_field('rating_max', (int,long,float), rating_max)
self.add_field('thumbnail', VideoThumbnail, thumbnail)
self.add_field('thumbnail', Thumbnail, thumbnail)
self.add_field('nsfw', bool, nsfw)
# XXX remove this and fix all backends
if thumbnail_url is not None and self.thumbnail is NotLoaded:
self.thumbnail = VideoThumbnail(thumbnail_url)
self.thumbnail = Thumbnail(thumbnail_url)
@classmethod
def id2url(cls, _id):

View file

@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2011 Romain Bignon, Noé Rubinstein
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.capabilities.base import CapBaseObject
class Thumbnail(CapBaseObject):
def __init__(self, url):
CapBaseObject.__init__(self, url)
self.add_field('url', basestring, url.replace(' ', '%20'))
self.add_field('data', str)
def __str__(self):
return self.url
def __repr__(self):
return '<Thumbnail url="%s">' % self.url
def __iscomplete__(self):
return self.data is not NotLoaded