From c76db754e95f650d1bde726147feb2541047b9fa Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Tue, 12 Mar 2013 19:20:24 +0100 Subject: [PATCH] [qcineoob] search and display torrent --- modules/isohunt/pages/torrents.py | 4 +- weboob/applications/qcineoob/main_window.py | 148 +++++++---- weboob/applications/qcineoob/minitorrent.py | 56 ++++ weboob/applications/qcineoob/qcineoob.py | 5 +- weboob/applications/qcineoob/torrent.py | 50 ++++ .../applications/qcineoob/ui/main_window.ui | 61 +---- .../applications/qcineoob/ui/minitorrent.ui | 129 +++++++++ weboob/applications/qcineoob/ui/torrent.ui | 250 ++++++++++++++++++ 8 files changed, 597 insertions(+), 106 deletions(-) create mode 100644 weboob/applications/qcineoob/minitorrent.py create mode 100644 weboob/applications/qcineoob/torrent.py create mode 100644 weboob/applications/qcineoob/ui/minitorrent.ui create mode 100644 weboob/applications/qcineoob/ui/torrent.ui diff --git a/modules/isohunt/pages/torrents.py b/modules/isohunt/pages/torrents.py index e0aacadc..04257872 100644 --- a/modules/isohunt/pages/torrents.py +++ b/modules/isohunt/pages/torrents.py @@ -73,9 +73,7 @@ class TorrentPage(BasePage): title = NotAvailable size = NotAvailable url = 'https://isohunt.com/download/%s/%s.torrent' % (id, id) - for a in self.document.getiterator('a'): - if 'Search more torrents of' in a.attrib.get('title', ''): - title = unicode(a.tail) + title = unicode(self.parser.select(self.document.getroot(),'head > meta[name=title]',1).attrib.get('content','')) seed = NotAvailable leech = NotAvailable tip_id = "none" diff --git a/weboob/applications/qcineoob/main_window.py b/weboob/applications/qcineoob/main_window.py index 0c971399..3104411d 100644 --- a/weboob/applications/qcineoob/main_window.py +++ b/weboob/applications/qcineoob/main_window.py @@ -21,6 +21,7 @@ from PyQt4.QtCore import SIGNAL from weboob.capabilities.cinema import ICapCinema +from weboob.capabilities.torrent import ICapTorrent from weboob.tools.application.qt import QtMainWindow, QtDo from weboob.tools.application.qt.backendcfg import BackendCfg @@ -28,8 +29,10 @@ from weboob.applications.qcineoob.ui.main_window_ui import Ui_MainWindow from .minimovie import MiniMovie from .miniperson import MiniPerson +from .minitorrent import MiniTorrent from .movie import Movie from .person import Person +from .torrent import Torrent class MainWindow(QtMainWindow): def __init__(self, config, weboob, parent=None): @@ -39,10 +42,8 @@ class MainWindow(QtMainWindow): self.config = config self.weboob = weboob - self.minimovies = [] - self.minipersons = [] - self.current_movie_widget = None - self.current_person_widget = None + self.minis = [] + self.current_info_widget = None self.history = {'last_action':None,'action_list':[]} self.connect(self.ui.backButton, SIGNAL("clicked()"), self.doBack) @@ -59,7 +60,7 @@ class MainWindow(QtMainWindow): self.backendsConfig() def backendsConfig(self): - bckndcfg = BackendCfg(self.weboob, (ICapCinema,), self) + bckndcfg = BackendCfg(self.weboob, (ICapCinema,ICapTorrent,), self) if bckndcfg.run(): self.loadBackendsList() @@ -81,6 +82,7 @@ class MainWindow(QtMainWindow): self.ui.currentActionLabel.setText(description) if self.history['last_action'] != None: self.history['action_list'].append(self.history['last_action']) + self.ui.backButton.setToolTip(self.history['last_action']['description']) self.ui.backButton.setDisabled(False) self.history['last_action'] = {'function':fun,'args':args,'description':description} return fun(*args) @@ -92,37 +94,39 @@ class MainWindow(QtMainWindow): self.history['last_action'] = todo if len(self.history['action_list']) == 0: self.ui.backButton.setDisabled(True) + else: + self.ui.backButton.setToolTip(self.history['action_list'][-1]['description']) return todo['function'](*todo['args']) def castingAction(self, id, role): - self.ui.stackedWidget.setCurrentWidget(self.ui.person_list_page) - for miniperson in self.minipersons: - self.ui.person_list_content.layout().removeWidget(miniperson) - miniperson.hide() - miniperson.deleteLater() + self.ui.stackedWidget.setCurrentWidget(self.ui.list_page) + for mini in self.minis: + self.ui.list_content.layout().removeWidget(mini) + mini.hide() + mini.deleteLater() - self.minipersons = [] + self.minis = [] self.ui.searchEdit.setEnabled(False) backend_name = str(self.ui.backendEdit.itemData(self.ui.backendEdit.currentIndex()).toString()) self.process = QtDo(self.weboob, self.addPerson) - self.process.do('iter_movie_persons', id, role, backends=backend_name) + self.process.do('iter_movie_persons', id, role, backends=backend_name, caps=ICapCinema) def filmographyAction(self, id, role): - self.ui.stackedWidget.setCurrentWidget(self.ui.movie_list_page) - for minimovie in self.minimovies: - self.ui.movie_list_content.layout().removeWidget(minimovie) - minimovie.hide() - minimovie.deleteLater() + self.ui.stackedWidget.setCurrentWidget(self.ui.list_page) + for mini in self.minis: + self.ui.list_content.layout().removeWidget(mini) + mini.hide() + mini.deleteLater() - self.minimovies = [] + self.minis = [] self.ui.searchEdit.setEnabled(False) backend_name = str(self.ui.backendEdit.itemData(self.ui.backendEdit.currentIndex()).toString()) self.process = QtDo(self.weboob, self.addMovie) - self.process.do('iter_person_movies', id, role, backends=backend_name) + self.process.do('iter_person_movies', id, role, backends=backend_name, caps=ICapCinema) def search(self): tosearch = self.ui.typeCombo.currentText() @@ -130,6 +134,8 @@ class MainWindow(QtMainWindow): self.searchPerson() elif tosearch == 'movie': self.searchMovie() + elif tosearch == 'torrent': + self.searchTorrent() def searchMovie(self): pattern = unicode(self.ui.searchEdit.text()) @@ -138,19 +144,19 @@ class MainWindow(QtMainWindow): self.doAction(u'Search movie results for "%s"'%pattern,self.searchMovieAction,[pattern]) def searchMovieAction(self,pattern): - self.ui.stackedWidget.setCurrentWidget(self.ui.movie_list_page) - for minimovie in self.minimovies: - self.ui.movie_list_content.layout().removeWidget(minimovie) - minimovie.hide() - minimovie.deleteLater() + self.ui.stackedWidget.setCurrentWidget(self.ui.list_page) + for mini in self.minis: + self.ui.list_content.layout().removeWidget(mini) + mini.hide() + mini.deleteLater() - self.minimovies = [] + self.minis = [] self.ui.searchEdit.setEnabled(False) backend_name = str(self.ui.backendEdit.itemData(self.ui.backendEdit.currentIndex()).toString()) self.process = QtDo(self.weboob, self.addMovie) - self.process.do('iter_movies', pattern, backends=backend_name) + self.process.do('iter_movies', pattern, backends=backend_name, caps=ICapCinema) def addMovie(self, backend, movie): if not backend: @@ -158,18 +164,18 @@ class MainWindow(QtMainWindow): self.process = None return minimovie = MiniMovie(self.weboob, backend, movie, self) - self.ui.movie_list_content.layout().addWidget(minimovie) - self.minimovies.append(minimovie) + self.ui.list_content.layout().addWidget(minimovie) + self.minis.append(minimovie) def displayMovie(self, movie): - self.ui.stackedWidget.setCurrentWidget(self.ui.movie_info_page) - if self.current_movie_widget != None: - self.ui.movie_info_content.layout().removeWidget(self.current_movie_widget) - self.current_movie_widget.hide() - self.current_movie_widget.deleteLater() + self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) + if self.current_info_widget != None: + self.ui.info_content.layout().removeWidget(self.current_info_widget) + self.current_info_widget.hide() + self.current_info_widget.deleteLater() wmovie = Movie(movie,self) - self.ui.movie_info_content.layout().addWidget(wmovie) - self.current_movie_widget = wmovie + self.ui.info_content.layout().addWidget(wmovie) + self.current_info_widget = wmovie def searchPerson(self): pattern = unicode(self.ui.searchEdit.text()) @@ -178,19 +184,19 @@ class MainWindow(QtMainWindow): self.doAction(u'Search person results for "%s"'%pattern,self.searchPersonAction,[pattern]) def searchPersonAction(self,pattern): - self.ui.stackedWidget.setCurrentWidget(self.ui.person_list_page) - for miniperson in self.minipersons: - self.ui.person_list_content.layout().removeWidget(miniperson) - miniperson.hide() - miniperson.deleteLater() + self.ui.stackedWidget.setCurrentWidget(self.ui.list_page) + for mini in self.minis: + self.ui.list_content.layout().removeWidget(mini) + mini.hide() + mini.deleteLater() - self.minipersons = [] + self.minis = [] self.ui.searchEdit.setEnabled(False) backend_name = str(self.ui.backendEdit.itemData(self.ui.backendEdit.currentIndex()).toString()) self.process = QtDo(self.weboob, self.addPerson) - self.process.do('iter_persons', pattern, backends=backend_name) + self.process.do('iter_persons', pattern, backends=backend_name, caps=ICapCinema) def addPerson(self, backend, person): if not backend: @@ -198,18 +204,58 @@ class MainWindow(QtMainWindow): self.process = None return miniperson = MiniPerson(self.weboob, backend, person, self) - self.ui.person_list_content.layout().addWidget(miniperson) - self.minipersons.append(miniperson) + self.ui.list_content.layout().addWidget(miniperson) + self.minis.append(miniperson) def displayPerson(self, person): - self.ui.stackedWidget.setCurrentWidget(self.ui.person_info_page) - if self.current_person_widget != None: - self.ui.person_info_content.layout().removeWidget(self.current_person_widget) - self.current_person_widget.hide() - self.current_person_widget.deleteLater() + self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) + if self.current_info_widget != None: + self.ui.info_content.layout().removeWidget(self.current_info_widget) + self.current_info_widget.hide() + self.current_info_widget.deleteLater() wperson = Person(person,self) - self.ui.person_info_content.layout().addWidget(wperson) - self.current_person_widget = wperson + self.ui.info_content.layout().addWidget(wperson) + self.current_info_widget = wperson + + def searchTorrent(self): + pattern = unicode(self.ui.searchEdit.text()) + if not pattern: + return + self.doAction(u'Search torrent for "%s"'%pattern,self.searchTorrentAction,[pattern]) + + def searchTorrentAction(self,pattern): + self.ui.stackedWidget.setCurrentWidget(self.ui.list_page) + for mini in self.minis: + self.ui.list_content.layout().removeWidget(mini) + mini.hide() + mini.deleteLater() + + self.mini = [] + self.ui.searchEdit.setEnabled(False) + + backend_name = str(self.ui.backendEdit.itemData(self.ui.backendEdit.currentIndex()).toString()) + + self.process = QtDo(self.weboob, self.addTorrent) + self.process.do('iter_torrents', pattern, backends=backend_name, caps=ICapTorrent) + + def addTorrent(self, backend, torrent): + if not backend: + self.ui.searchEdit.setEnabled(True) + self.process = None + return + minitorrent = MiniTorrent(self.weboob, backend, torrent, self) + self.ui.list_content.layout().addWidget(minitorrent) + self.minis.append(minitorrent) + + def displayTorrent(self, torrent): + self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) + if self.current_info_widget != None: + self.ui.info_content.layout().removeWidget(self.current_info_widget) + self.current_info_widget.hide() + self.current_info_widget.deleteLater() + wtorrent = Torrent(torrent,self) + self.ui.info_content.layout().addWidget(wtorrent) + self.current_info_widget = wtorrent def closeEvent(self, ev): self.config.set('settings', 'backend', str(self.ui.backendEdit.itemData(self.ui.backendEdit.currentIndex()).toString())) diff --git a/weboob/applications/qcineoob/minitorrent.py b/weboob/applications/qcineoob/minitorrent.py new file mode 100644 index 00000000..f9ac1df5 --- /dev/null +++ b/weboob/applications/qcineoob/minitorrent.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2010-2011 Romain Bignon +# +# 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 . + +import urllib + +from PyQt4.QtGui import QFrame, QImage, QPixmap + +from weboob.tools.application.qt import QtDo +from weboob.applications.qcineoob.ui.minitorrent_ui import Ui_MiniTorrent +from weboob.capabilities.base import NotAvailable, NotLoaded + +class MiniTorrent(QFrame): + def __init__(self, weboob, backend, torrent, parent=None): + QFrame.__init__(self, parent) + self.parent = parent + self.ui = Ui_MiniTorrent() + self.ui.setupUi(self) + + self.weboob = weboob + self.backend = backend + self.torrent = torrent + self.ui.nameLabel.setText(torrent.name) + if torrent.seeders != NotAvailable and torrent.leechers != NotAvailable: + self.ui.seedLeechLabel.setText('%s/%s'%(torrent.seeders,torrent.leechers)) + self.ui.backendLabel.setText(backend.name) + + def enterEvent(self, event): + self.setFrameShadow(self.Sunken) + QFrame.enterEvent(self, event) + + def leaveEvent(self, event): + self.setFrameShadow(self.Raised) + QFrame.leaveEvent(self, event) + + def mousePressEvent(self, event): + QFrame.mousePressEvent(self, event) + + torrent = self.backend.get_torrent(self.torrent.id) + if torrent: + self.parent.doAction('Details of torrent "%s"'%torrent.name,self.parent.displayTorrent,[torrent]) diff --git a/weboob/applications/qcineoob/qcineoob.py b/weboob/applications/qcineoob/qcineoob.py index 1c540f0c..a1659c2b 100644 --- a/weboob/applications/qcineoob/qcineoob.py +++ b/weboob/applications/qcineoob/qcineoob.py @@ -19,6 +19,7 @@ from weboob.capabilities.cinema import ICapCinema +from weboob.capabilities.torrent import ICapTorrent from weboob.tools.application.qt import QtApplication from .main_window import MainWindow @@ -30,7 +31,7 @@ class QCineoob(QtApplication): COPYRIGHT = 'Copyright(C) 2010-2011 Romain Bignon' DESCRIPTION = "Qt application allowing to search movies etc..." SHORT_DESCRIPTION = "search movies" - CAPS = ICapCinema + CAPS = ICapCinema,ICapTorrent CONFIG = {'settings': {'nsfw': 1, 'sfw': 1, 'sortby': 0, @@ -38,7 +39,7 @@ class QCineoob(QtApplication): } } def main(self, argv): - self.load_backends(ICapCinema) + self.load_backends([ICapCinema,ICapTorrent]) self.load_config() self.main_window = MainWindow(self.config, self.weboob) diff --git a/weboob/applications/qcineoob/torrent.py b/weboob/applications/qcineoob/torrent.py new file mode 100644 index 00000000..5b120866 --- /dev/null +++ b/weboob/applications/qcineoob/torrent.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2010-2011 Romain Bignon +# +# 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 . + +import urllib + +from PyQt4.QtCore import QUrl,Qt,SIGNAL +from PyQt4.QtGui import QFrame, QImage, QPixmap + +from weboob.applications.qcineoob.ui.torrent_ui import Ui_Torrent +from weboob.capabilities.base import NotAvailable, NotLoaded + +class Torrent(QFrame): + def __init__(self, torrent, parent=None): + QFrame.__init__(self, parent) + self.parent = parent + self.ui = Ui_Torrent() + self.ui.setupUi(self) + + #self.connect(self.ui.downloadButton, SIGNAL("clicked()"), self.download) + + self.torrent = torrent + self.ui.nameLabel.setText(u'%s'%torrent.name) + + self.ui.verticalLayout.setAlignment(Qt.AlignTop) + + def download(self): + role = None + tosearch = self.ui.castingCombo.currentText() + role_desc = '' + if tosearch != 'all': + role = tosearch[:-1] + role_desc = ' as %s'%role + self.parent.doAction('Casting%s of movie "%s"'%(role_desc,self.movie.original_title), + self.parent.castingAction,[self.movie.id,role]) diff --git a/weboob/applications/qcineoob/ui/main_window.ui b/weboob/applications/qcineoob/ui/main_window.ui index 701181fb..7d579eb7 100644 --- a/weboob/applications/qcineoob/ui/main_window.ui +++ b/weboob/applications/qcineoob/ui/main_window.ui @@ -52,6 +52,11 @@ person + + + torrent + + @@ -91,14 +96,14 @@ - + true - + 0 @@ -113,20 +118,20 @@ - + true - + 0 0 - 96 - 26 + 660 + 292 @@ -135,50 +140,6 @@ - - - - - - true - - - - - 0 - 0 - 96 - 26 - - - - - - - - - - - - - - true - - - - - 0 - 0 - 96 - 26 - - - - - - - - diff --git a/weboob/applications/qcineoob/ui/minitorrent.ui b/weboob/applications/qcineoob/ui/minitorrent.ui new file mode 100644 index 00000000..c40330b7 --- /dev/null +++ b/weboob/applications/qcineoob/ui/minitorrent.ui @@ -0,0 +1,129 @@ + + + MiniTorrent + + + + 0 + 0 + 464 + 136 + + + + Form + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 9 + + + 5 + + + 5 + + + + + + 0 + 0 + + + + + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + + 75 + true + + + + Name + + + + + + + + 0 + 0 + + + + + 50 + true + false + + + + TextLabel + + + + + + + + 75 + true + + + + Seed/leech: + + + + + + + TextLabel + + + + + + + + 75 + true + + + + Where + + + + + + + TextLabel + + + + + + + + + + diff --git a/weboob/applications/qcineoob/ui/torrent.ui b/weboob/applications/qcineoob/ui/torrent.ui new file mode 100644 index 00000000..ad999ae4 --- /dev/null +++ b/weboob/applications/qcineoob/ui/torrent.ui @@ -0,0 +1,250 @@ + + + Torrent + + + + 0 + 0 + 629 + 552 + + + + + 0 + 0 + + + + + 2000 + 600 + + + + Frame + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 16777215 + 600 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Download + + + + + + + + 16777215 + 35 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Name: + + + + + + + + + + + + + + + + + + 16777215 + 35 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Seed/leech: + + + + + + + + + + + + + + + + + + 16777215 + 35 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Size: + + + + + + + + + + + + + + + + + + 16777215 + 200 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Description: + + + + + + + + + + + + + + 16777215 + 200 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Files: + + + + + + + + + + + + + + 16777215 + 40 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 3 + + + 3 + + + + + Url: + + + + + + + + + + + + + + + + +