fetch thumbnails asynchroneously
This commit is contained in:
parent
e5a27692b5
commit
d710c93b36
6 changed files with 58 additions and 16 deletions
|
|
@ -87,7 +87,7 @@ class MainWindow(QtMainWindow):
|
|||
self.ui.searchEdit.setEnabled(True)
|
||||
self.process = None
|
||||
return
|
||||
minivideo = MiniVideo(backend, video)
|
||||
minivideo = MiniVideo(self.weboob, backend, video)
|
||||
self.ui.scrollAreaContent.layout().addWidget(minivideo)
|
||||
self.minivideos.append(minivideo)
|
||||
if (video.nsfw and not self.ui.nsfwCheckBox.isChecked() or
|
||||
|
|
|
|||
|
|
@ -19,15 +19,17 @@
|
|||
import urllib2
|
||||
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 .video import Video
|
||||
|
||||
class MiniVideo(QFrame):
|
||||
def __init__(self, backend, video, parent=None):
|
||||
def __init__(self, weboob, backend, video, parent=None):
|
||||
QFrame.__init__(self, parent)
|
||||
self.ui = Ui_MiniVideo()
|
||||
self.ui.setupUi(self)
|
||||
|
||||
self.weboob = weboob
|
||||
self.backend = backend
|
||||
self.video = video
|
||||
self.ui.titleLabel.setText(video.title)
|
||||
|
|
@ -40,9 +42,15 @@ class MiniVideo(QFrame):
|
|||
else:
|
||||
self.ui.ratingLabel.setText('%s' % video.rating)
|
||||
|
||||
if video.thumbnail_url:
|
||||
data = urllib2.urlopen(video.thumbnail_url).read()
|
||||
img = QImage.fromData(data)
|
||||
self.process_thumbnail = QtDo(self.weboob, self.gotThumbnail)
|
||||
self.process_thumbnail.do('fillobj', self.video, ['thumbnail'], backends=backend)
|
||||
|
||||
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))
|
||||
|
||||
def enterEvent(self, event):
|
||||
|
|
|
|||
|
|
@ -57,8 +57,14 @@ class YoujizzBackend(BaseBackend, ICapVideo):
|
|||
return self.browser.iter_search_results(pattern)
|
||||
|
||||
def fill_video(self, video, fields):
|
||||
# ignore the fields param: VideoPage.get_video() returns all the information
|
||||
with self.browser:
|
||||
return self.browser.get_video(YoujizzVideo.id2url(video.id), video)
|
||||
if fields != ['thumbnail']:
|
||||
# if we don't want only the thumbnail, we probably want also every fields
|
||||
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}
|
||||
|
|
|
|||
|
|
@ -56,8 +56,14 @@ class YoupornBackend(BaseBackend, ICapVideo):
|
|||
raise NotImplementedError()
|
||||
|
||||
def fill_video(self, video, fields):
|
||||
# ignore the fields param: VideoPage.get_video() returns all the information
|
||||
with self.browser:
|
||||
return self.browser.get_video(YoupornVideo.id2url(video.id), video)
|
||||
if fields != ['thumbnail']:
|
||||
# if we don't want only the thumbnail, we probably want also every fields
|
||||
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}
|
||||
|
|
|
|||
|
|
@ -72,8 +72,14 @@ class YoutubeBackend(BaseBackend, ICapVideo):
|
|||
raise NotImplementedError()
|
||||
|
||||
def fill_video(self, video, fields):
|
||||
# ignore the fields param: VideoPage.get_video() returns all the information
|
||||
with self.browser:
|
||||
return self.browser.get_video(YoutubeVideo.id2url(video.id), video)
|
||||
if fields != ['thumbnail']:
|
||||
# if we don't want only the thumbnail, we probably want also every fields
|
||||
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}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,23 @@ from .cap import ICap
|
|||
__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):
|
||||
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.title = title
|
||||
self.url = url
|
||||
|
|
@ -33,7 +47,9 @@ class BaseVideo(object):
|
|||
self.date = date
|
||||
self.rating = float(rating)
|
||||
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
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue