[qcineoob] download torrent operational

This commit is contained in:
Julien Veyssier 2013-03-12 22:23:24 +01:00
commit 23dde42186
8 changed files with 89 additions and 36 deletions

View file

@ -25,6 +25,7 @@ from weboob.capabilities.torrent import ICapTorrent
from weboob.tools.application.qt import QtMainWindow, QtDo from weboob.tools.application.qt import QtMainWindow, QtDo
from weboob.tools.application.qt.backendcfg import BackendCfg from weboob.tools.application.qt.backendcfg import BackendCfg
from weboob.applications.qcineoob.ui.main_window_ui import Ui_MainWindow from weboob.applications.qcineoob.ui.main_window_ui import Ui_MainWindow
from .minimovie import MiniMovie from .minimovie import MiniMovie
@ -247,13 +248,13 @@ class MainWindow(QtMainWindow):
self.ui.list_content.layout().addWidget(minitorrent) self.ui.list_content.layout().addWidget(minitorrent)
self.minis.append(minitorrent) self.minis.append(minitorrent)
def displayTorrent(self, torrent): def displayTorrent(self, torrent, backend):
self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) self.ui.stackedWidget.setCurrentWidget(self.ui.info_page)
if self.current_info_widget != None: if self.current_info_widget != None:
self.ui.info_content.layout().removeWidget(self.current_info_widget) self.ui.info_content.layout().removeWidget(self.current_info_widget)
self.current_info_widget.hide() self.current_info_widget.hide()
self.current_info_widget.deleteLater() self.current_info_widget.deleteLater()
wtorrent = Torrent(torrent,self) wtorrent = Torrent(torrent, backend, self)
self.ui.info_content.layout().addWidget(wtorrent) self.ui.info_content.layout().addWidget(wtorrent)
self.current_info_widget = wtorrent self.current_info_widget = wtorrent

View file

@ -21,9 +21,8 @@ import urllib
from PyQt4.QtGui import QFrame, QImage, QPixmap from PyQt4.QtGui import QFrame, QImage, QPixmap
from weboob.tools.application.qt import QtDo
from weboob.applications.qcineoob.ui.minimovie_ui import Ui_MiniMovie from weboob.applications.qcineoob.ui.minimovie_ui import Ui_MiniMovie
from weboob.capabilities.base import NotAvailable, NotLoaded from weboob.capabilities.base import NotAvailable
class MiniMovie(QFrame): class MiniMovie(QFrame):
def __init__(self, weboob, backend, movie, parent=None): def __init__(self, weboob, backend, movie, parent=None):
@ -39,9 +38,6 @@ class MiniMovie(QFrame):
self.ui.shortDescLabel.setText(movie.short_description) self.ui.shortDescLabel.setText(movie.short_description)
self.ui.backendLabel.setText(backend.name) self.ui.backendLabel.setText(backend.name)
#self.process_thumbnail = QtDo(self.weboob, self.gotThumbnail)
#self.process_thumbnail.do('fillobj', self.movie, ['thumbnail_url'], backends=backend)
def gotThumbnail(self, backend, movie): def gotThumbnail(self, backend, movie):
if self.movie.thumbnail_url != NotAvailable: if self.movie.thumbnail_url != NotAvailable:
data = urllib.urlopen(self.movie.thumbnail_url).read() data = urllib.urlopen(self.movie.thumbnail_url).read()

View file

@ -21,9 +21,8 @@ import urllib
from PyQt4.QtGui import QFrame, QImage, QPixmap from PyQt4.QtGui import QFrame, QImage, QPixmap
from weboob.tools.application.qt import QtDo
from weboob.applications.qcineoob.ui.miniperson_ui import Ui_MiniPerson from weboob.applications.qcineoob.ui.miniperson_ui import Ui_MiniPerson
from weboob.capabilities.base import NotAvailable, NotLoaded from weboob.capabilities.base import NotAvailable
class MiniPerson(QFrame): class MiniPerson(QFrame):
def __init__(self, weboob, backend, person, parent=None): def __init__(self, weboob, backend, person, parent=None):
@ -39,9 +38,6 @@ class MiniPerson(QFrame):
self.ui.shortDescLabel.setText('%s'%person.short_description) self.ui.shortDescLabel.setText('%s'%person.short_description)
self.ui.backendLabel.setText(backend.name) self.ui.backendLabel.setText(backend.name)
#self.process_thumbnail = QtDo(self.weboob, self.gotThumbnail)
#self.process_thumbnail.do('fillobj', self.person, ['thumbnail_url'], backends=backend)
def gotThumbnail(self, backend, person): def gotThumbnail(self, backend, person):
if self.person.thumbnail_url != NotAvailable: if self.person.thumbnail_url != NotAvailable:
data = urllib.urlopen(self.person.thumbnail_url).read() data = urllib.urlopen(self.person.thumbnail_url).read()

View file

@ -17,13 +17,10 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
import urllib from PyQt4.QtGui import QFrame
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.applications.qcineoob.ui.minitorrent_ui import Ui_MiniTorrent
from weboob.capabilities.base import NotAvailable, NotLoaded from weboob.capabilities.base import NotAvailable
class MiniTorrent(QFrame): class MiniTorrent(QFrame):
def __init__(self, weboob, backend, torrent, parent=None): def __init__(self, weboob, backend, torrent, parent=None):
@ -53,4 +50,4 @@ class MiniTorrent(QFrame):
torrent = self.backend.get_torrent(self.torrent.id) torrent = self.backend.get_torrent(self.torrent.id)
if torrent: if torrent:
self.parent.doAction('Details of torrent "%s"'%torrent.name,self.parent.displayTorrent,[torrent]) self.parent.doAction('Details of torrent "%s"'%torrent.name,self.parent.displayTorrent,[torrent,self.backend])

View file

@ -19,11 +19,11 @@
import urllib import urllib
from PyQt4.QtCore import QUrl,Qt,SIGNAL from PyQt4.QtCore import Qt,SIGNAL
from PyQt4.QtGui import QFrame, QImage, QPixmap from PyQt4.QtGui import QFrame, QImage, QPixmap
from weboob.applications.qcineoob.ui.movie_ui import Ui_Movie from weboob.applications.qcineoob.ui.movie_ui import Ui_Movie
from weboob.capabilities.base import NotAvailable, NotLoaded from weboob.capabilities.base import NotAvailable
from weboob.applications.suboob.suboob import LANGUAGE_CONV from weboob.applications.suboob.suboob import LANGUAGE_CONV
class Movie(QFrame): class Movie(QFrame):
@ -39,6 +39,7 @@ class Movie(QFrame):
self.connect(self.ui.castingButton, SIGNAL("clicked()"), self.casting) self.connect(self.ui.castingButton, SIGNAL("clicked()"), self.casting)
self.connect(self.ui.torrentButton, SIGNAL("clicked()"), self.searchTorrent) self.connect(self.ui.torrentButton, SIGNAL("clicked()"), self.searchTorrent)
self.connect(self.ui.subtitleButton, SIGNAL("clicked()"), self.searchSubtitle)
self.movie = movie self.movie = movie
self.ui.titleLabel.setText(movie.original_title) self.ui.titleLabel.setText(movie.original_title)
@ -62,6 +63,12 @@ class Movie(QFrame):
img = QImage.fromData(data) img = QImage.fromData(data)
self.ui.imageLabel.setPixmap(QPixmap.fromImage(img)) self.ui.imageLabel.setPixmap(QPixmap.fromImage(img))
def searchSubtitle(self):
tosearch = self.movie.original_title
lang = unicode(self.ui.langCombo.currentText())
desc = 'Search subtitles for "%s" (lang:%s)'%(tosearch,lang)
self.parent.doAction(desc, self.parent.searchSubtitleAction,[lang,tosearch])
def searchTorrent(self): def searchTorrent(self):
tosearch = self.movie.original_title tosearch = self.movie.original_title
if self.movie.release_date != NotAvailable: if self.movie.release_date != NotAvailable:

View file

@ -19,11 +19,11 @@
import urllib import urllib
from PyQt4.QtCore import QUrl,Qt,SIGNAL from PyQt4.QtCore import SIGNAL
from PyQt4.QtGui import QFrame, QImage, QPixmap from PyQt4.QtGui import QFrame, QImage, QPixmap
from weboob.applications.qcineoob.ui.person_ui import Ui_Person from weboob.applications.qcineoob.ui.person_ui import Ui_Person
from weboob.capabilities.base import NotAvailable, NotLoaded from weboob.capabilities.base import NotAvailable
class Person(QFrame): class Person(QFrame):
def __init__(self, person, parent=None): def __init__(self, person, parent=None):

View file

@ -17,34 +17,56 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
import urllib import sys
from PyQt4.QtCore import QUrl,Qt,SIGNAL from PyQt4.QtCore import Qt,SIGNAL
from PyQt4.QtGui import QFrame, QImage, QPixmap from PyQt4.QtGui import QFrame, QFileDialog
from weboob.applications.qcineoob.ui.torrent_ui import Ui_Torrent from weboob.applications.qcineoob.ui.torrent_ui import Ui_Torrent
from weboob.capabilities.base import NotAvailable, NotLoaded from weboob.capabilities.base import NotAvailable, NotLoaded
class Torrent(QFrame): class Torrent(QFrame):
def __init__(self, torrent, parent=None): def __init__(self, torrent, backend, parent=None):
QFrame.__init__(self, parent) QFrame.__init__(self, parent)
self.parent = parent self.parent = parent
self.backend = backend
self.ui = Ui_Torrent() self.ui = Ui_Torrent()
self.ui.setupUi(self) self.ui.setupUi(self)
#self.connect(self.ui.downloadButton, SIGNAL("clicked()"), self.download) self.connect(self.ui.downloadButton, SIGNAL("clicked()"), self.download)
self.torrent = torrent self.torrent = torrent
self.ui.nameLabel.setText(u'%s'%torrent.name) self.ui.nameLabel.setText(u'%s'%torrent.name)
if torrent.url != NotAvailable:
self.ui.urlEdit.setText(u'%s'%torrent.url)
else:
self.ui.urlFrame.hide()
self.ui.downloadButton.setDisabled(True)
self.ui.downloadButton.setToolTip('Use the magnet link')
if torrent.magnet != NotAvailable and torrent.magnet != NotLoaded:
self.ui.magnetEdit.setText(u'%s'%torrent.magnet)
else:
self.ui.magnetFrame.hide()
self.ui.verticalLayout.setAlignment(Qt.AlignTop) self.ui.verticalLayout.setAlignment(Qt.AlignTop)
def download(self): def download(self):
role = None fileDial = QFileDialog(self,'Save "%s" torrent file'%self.torrent.name,'%s.torrent'%self.torrent.name,'Torrent file (*.torrent);;all files (*)')
tosearch = self.ui.castingCombo.currentText() fileDial.setAcceptMode(QFileDialog.AcceptSave)
role_desc = '' fileDial.setLabelText(QFileDialog.Accept,'Save torrent file')
if tosearch != 'all': fileDial.setLabelText(QFileDialog.FileName,'Torrent file name')
role = tosearch[:-1] ok = (fileDial.exec_() == 1)
role_desc = ' as %s'%role if not ok:
self.parent.doAction('Casting%s of movie "%s"'%(role_desc,self.movie.original_title), return
self.parent.castingAction,[self.movie.id,role]) result = fileDial.selectedFiles()
if len(result) > 0:
dest = result[0]
data = self.backend.get_torrent_file(self.torrent.id)
try:
with open(dest, 'w') as f:
f.write(data)
except IOError, e:
print >>sys.stderr, 'Unable to write .torrent in "%s": %s' % (dest, e)
return 1
return

View file

@ -207,7 +207,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QFrame" name="frame_7"> <widget class="QFrame" name="urlFrame">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>16777215</width> <width>16777215</width>
@ -240,6 +240,40 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QFrame" name="magnetFrame">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>40</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<property name="topMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>Magnet:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="magnetEdit"/>
</item>
</layout>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>