Commit d710c93b authored by Romain Bignon's avatar Romain Bignon

fetch thumbnails asynchroneously

parent e5a27692
...@@ -87,7 +87,7 @@ class MainWindow(QtMainWindow): ...@@ -87,7 +87,7 @@ class MainWindow(QtMainWindow):
self.ui.searchEdit.setEnabled(True) self.ui.searchEdit.setEnabled(True)
self.process = None self.process = None
return return
minivideo = MiniVideo(backend, video) minivideo = MiniVideo(self.weboob, backend, video)
self.ui.scrollAreaContent.layout().addWidget(minivideo) self.ui.scrollAreaContent.layout().addWidget(minivideo)
self.minivideos.append(minivideo) self.minivideos.append(minivideo)
if (video.nsfw and not self.ui.nsfwCheckBox.isChecked() or if (video.nsfw and not self.ui.nsfwCheckBox.isChecked() or
......
...@@ -19,15 +19,17 @@ ...@@ -19,15 +19,17 @@
import urllib2 import urllib2
from PyQt4.QtGui import QFrame, QImage, QPixmap from PyQt4.QtGui import QFrame, QImage, QPixmap
from weboob.tools.application.qt import QtDo
from weboob.applications.qvideoob.ui.minivideo_ui import Ui_MiniVideo from weboob.applications.qvideoob.ui.minivideo_ui import Ui_MiniVideo
from .video import Video from .video import Video
class MiniVideo(QFrame): class MiniVideo(QFrame):
def __init__(self, backend, video, parent=None): def __init__(self, weboob, backend, video, parent=None):
QFrame.__init__(self, parent) QFrame.__init__(self, parent)
self.ui = Ui_MiniVideo() self.ui = Ui_MiniVideo()
self.ui.setupUi(self) self.ui.setupUi(self)
self.weboob = weboob
self.backend = backend self.backend = backend
self.video = video self.video = video
self.ui.titleLabel.setText(video.title) self.ui.titleLabel.setText(video.title)
...@@ -40,9 +42,15 @@ class MiniVideo(QFrame): ...@@ -40,9 +42,15 @@ class MiniVideo(QFrame):
else: else:
self.ui.ratingLabel.setText('%s' % video.rating) self.ui.ratingLabel.setText('%s' % video.rating)
if video.thumbnail_url: self.process_thumbnail = QtDo(self.weboob, self.gotThumbnail)
data = urllib2.urlopen(video.thumbnail_url).read() self.process_thumbnail.do('fillobj', self.video, ['thumbnail'], backends=backend)
img = QImage.fromData(data)
def gotThumbnail(self, backend, video):
if not backend:
return
if video.thumbnail.data:
img = QImage.fromData(video.thumbnail.data)
self.ui.imageLabel.setPixmap(QPixmap.fromImage(img)) self.ui.imageLabel.setPixmap(QPixmap.fromImage(img))
def enterEvent(self, event): def enterEvent(self, event):
......
...@@ -57,8 +57,14 @@ class YoujizzBackend(BaseBackend, ICapVideo): ...@@ -57,8 +57,14 @@ class YoujizzBackend(BaseBackend, ICapVideo):
return self.browser.iter_search_results(pattern) return self.browser.iter_search_results(pattern)
def fill_video(self, video, fields): def fill_video(self, video, fields):
# ignore the fields param: VideoPage.get_video() returns all the information if fields != ['thumbnail']:
with self.browser: # if we don't want only the thumbnail, we probably want also every fields
return self.browser.get_video(YoujizzVideo.id2url(video.id), video) with self.browser:
video = self.browser.get_video(YoujizzVideo.id2url(video.id), video)
if 'thumbnail' in fields:
with self.browser:
video.thumbnail.data = self.browser.openurl(video.thumbnail.url).read()
return video
OBJECTS = {YoujizzVideo: fill_video} OBJECTS = {YoujizzVideo: fill_video}
...@@ -56,8 +56,14 @@ class YoupornBackend(BaseBackend, ICapVideo): ...@@ -56,8 +56,14 @@ class YoupornBackend(BaseBackend, ICapVideo):
raise NotImplementedError() raise NotImplementedError()
def fill_video(self, video, fields): def fill_video(self, video, fields):
# ignore the fields param: VideoPage.get_video() returns all the information if fields != ['thumbnail']:
with self.browser: # if we don't want only the thumbnail, we probably want also every fields
return self.browser.get_video(YoupornVideo.id2url(video.id), video) with self.browser:
video = self.browser.get_video(YoupornVideo.id2url(video.id), video)
if 'thumbnail' in fields:
with self.browser:
video.thumbnail.data = self.browser.openurl(video.thumbnail.url).read()
return video
OBJECTS = {YoupornVideo: fill_video} OBJECTS = {YoupornVideo: fill_video}
...@@ -72,8 +72,14 @@ class YoutubeBackend(BaseBackend, ICapVideo): ...@@ -72,8 +72,14 @@ class YoutubeBackend(BaseBackend, ICapVideo):
raise NotImplementedError() raise NotImplementedError()
def fill_video(self, video, fields): def fill_video(self, video, fields):
# ignore the fields param: VideoPage.get_video() returns all the information if fields != ['thumbnail']:
with self.browser: # if we don't want only the thumbnail, we probably want also every fields
return self.browser.get_video(YoutubeVideo.id2url(video.id), video) with self.browser:
video = self.browser.get_video(YoutubeVideo.id2url(video.id), video)
if 'thumbnail' in fields:
with self.browser:
video.thumbnail.data = self.browser.openurl(video.thumbnail.url).read()
return video
OBJECTS = {YoutubeVideo: fill_video} OBJECTS = {YoutubeVideo: fill_video}
...@@ -22,9 +22,23 @@ from .cap import ICap ...@@ -22,9 +22,23 @@ from .cap import ICap
__all__ = ['BaseVideo', 'ICapVideo'] __all__ = ['BaseVideo', 'ICapVideo']
class ContactThumbnail(object):
def __init__(self, url):
self.url = url
self.data = None
def __str__(self):
return '<%s>' % self.url
def __repr__(self):
return '<Thumbnail url="%s">' % self.url
def __iscomplete__(self):
return self.data
class BaseVideo(object): class BaseVideo(object):
def __init__(self, _id, title=None, url=None, author=None, duration=None, date=None, def __init__(self, _id, title=None, url=None, author=None, duration=None, date=None,
rating=0.0, rating_max=0.0, thumbnail_url=None, nsfw=False): rating=0.0, rating_max=0.0, thumbnail=None, thumbnail_url=None, nsfw=False):
self.id = unicode(_id) self.id = unicode(_id)
self.title = title self.title = title
self.url = url self.url = url
...@@ -33,7 +47,9 @@ class BaseVideo(object): ...@@ -33,7 +47,9 @@ class BaseVideo(object):
self.date = date self.date = date
self.rating = float(rating) self.rating = float(rating)
self.rating_max = float(rating_max) self.rating_max = float(rating_max)
self.thumbnail_url = thumbnail_url self.thumbnail = thumbnail
if thumbnail_url and not self.thumbnail:
self.thumbnail = ContactThumbnail(thumbnail_url)
self.nsfw = nsfw self.nsfw = nsfw
@classmethod @classmethod
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment