[qcineoob] subtitles integrated

This commit is contained in:
Julien Veyssier 2013-03-13 00:07:58 +01:00
commit 93757f8409
8 changed files with 542 additions and 5 deletions

View file

@ -23,18 +23,21 @@ from PyQt4.QtGui import QApplication
from weboob.capabilities.cinema import ICapCinema
from weboob.capabilities.torrent import ICapTorrent
from weboob.capabilities.subtitle import ICapSubtitle
from weboob.tools.application.qt import QtMainWindow, QtDo
from weboob.tools.application.qt.backendcfg import BackendCfg
from weboob.applications.suboob.suboob import LANGUAGE_CONV
from weboob.applications.qcineoob.ui.main_window_ui import Ui_MainWindow
from .minimovie import MiniMovie
from .miniperson import MiniPerson
from .minitorrent import MiniTorrent
from .minisubtitle import MiniSubtitle
from .movie import Movie
from .person import Person
from .torrent import Torrent
from .subtitle import Subtitle
class MainWindow(QtMainWindow):
def __init__(self, config, weboob, parent=None):
@ -53,6 +56,7 @@ class MainWindow(QtMainWindow):
self.connect(self.ui.searchEdit, SIGNAL("returnPressed()"), self.search)
self.connect(self.ui.typeCombo, SIGNAL("returnPressed()"), self.search)
self.connect(self.ui.typeCombo, SIGNAL("currentIndexChanged(QString)"), self.typeComboChanged)
self.connect(self.ui.actionBackends, SIGNAL("triggered()"), self.backendsConfig)
@ -61,8 +65,14 @@ class MainWindow(QtMainWindow):
if self.ui.backendEdit.count() == 0:
self.backendsConfig()
langs = LANGUAGE_CONV.keys()
langs.sort()
for lang in langs:
self.ui.langCombo.addItem(lang)
self.ui.langCombo.hide()
def backendsConfig(self):
bckndcfg = BackendCfg(self.weboob, (ICapCinema,ICapTorrent,), self)
bckndcfg = BackendCfg(self.weboob, (ICapCinema,ICapTorrent,ICapSubtitle,), self)
if bckndcfg.run():
self.loadBackendsList()
@ -80,6 +90,12 @@ class MainWindow(QtMainWindow):
else:
self.ui.searchEdit.setEnabled(True)
def typeComboChanged(self,value):
if unicode(value) == 'subtitle':
self.ui.langCombo.show()
else:
self.ui.langCombo.hide()
def doAction(self, description, fun, args):
self.ui.currentActionLabel.setText(description)
if self.history['last_action'] != None:
@ -140,6 +156,8 @@ class MainWindow(QtMainWindow):
self.searchMovie()
elif tosearch == 'torrent':
self.searchTorrent()
elif tosearch == 'subtitle':
self.searchSubtitle()
def searchMovie(self):
pattern = unicode(self.ui.searchEdit.text())
@ -225,6 +243,7 @@ class MainWindow(QtMainWindow):
wperson = Person(person,self)
self.ui.info_content.layout().addWidget(wperson)
self.current_info_widget = wperson
QApplication.restoreOverrideCursor()
def searchTorrent(self):
pattern = unicode(self.ui.searchEdit.text())
@ -268,6 +287,49 @@ class MainWindow(QtMainWindow):
self.ui.info_content.layout().addWidget(wtorrent)
self.current_info_widget = wtorrent
def searchSubtitle(self):
pattern = unicode(self.ui.searchEdit.text())
lang = unicode(self.ui.langCombo.currentText())
if not pattern:
return
self.doAction(u'Search subtitle "%s"'%pattern,self.searchSubtitleAction,[lang,pattern])
def searchSubtitleAction(self, lang, 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.minis = []
self.ui.searchEdit.setEnabled(False)
QApplication.setOverrideCursor( Qt.WaitCursor )
backend_name = str(self.ui.backendEdit.itemData(self.ui.backendEdit.currentIndex()).toString())
self.process = QtDo(self.weboob, self.addSubtitle)
self.process.do('iter_subtitles', lang, pattern, backends=backend_name, caps=ICapSubtitle)
def addSubtitle(self, backend, subtitle):
if not backend:
self.ui.searchEdit.setEnabled(True)
QApplication.restoreOverrideCursor()
self.process = None
return
minisubtitle = MiniSubtitle(self.weboob, backend, subtitle, self)
self.ui.list_content.layout().addWidget(minisubtitle)
self.minis.append(minisubtitle)
def displaySubtitle(self, subtitle, backend):
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()
wsubtitle = Subtitle(subtitle, backend, self)
self.ui.info_content.layout().addWidget(wsubtitle)
self.current_info_widget = wsubtitle
def closeEvent(self, ev):
self.config.set('settings', 'backend', str(self.ui.backendEdit.itemData(self.ui.backendEdit.currentIndex()).toString()))
self.config.save()

View file

@ -19,7 +19,8 @@
import urllib
from PyQt4.QtGui import QFrame, QImage, QPixmap
from PyQt4.QtGui import QFrame, QImage, QPixmap, QApplication
from PyQt4.QtCore import Qt
from weboob.applications.qcineoob.ui.miniperson_ui import Ui_MiniPerson
from weboob.capabilities.base import NotAvailable
@ -61,6 +62,7 @@ class MiniPerson(QFrame):
def mousePressEvent(self, event):
QFrame.mousePressEvent(self, event)
QApplication.setOverrideCursor( Qt.WaitCursor )
person = self.backend.get_person(self.person.id)
if person:
self.parent.doAction(u'Details of person "%s"'%person.name,self.parent.displayPerson,[person])

View file

@ -0,0 +1,53 @@
# -*- 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 <http://www.gnu.org/licenses/>.
from PyQt4.QtGui import QFrame
from weboob.applications.qcineoob.ui.minisubtitle_ui import Ui_MiniSubtitle
from weboob.capabilities.base import NotAvailable
class MiniSubtitle(QFrame):
def __init__(self, weboob, backend, subtitle, parent=None):
QFrame.__init__(self, parent)
self.parent = parent
self.ui = Ui_MiniSubtitle()
self.ui.setupUi(self)
self.weboob = weboob
self.backend = backend
self.subtitle = subtitle
self.ui.nameLabel.setText(subtitle.name)
if subtitle.nb_cd != NotAvailable:
self.ui.nbcdLabel.setText(u'%s'%subtitle.nb_cd)
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)
subtitle = self.backend.get_subtitle(self.subtitle.id)
if subtitle:
self.parent.doAction('Details of subtitle "%s"'%subtitle.name,self.parent.displaySubtitle,[subtitle,self.backend])

View file

@ -20,6 +20,7 @@
from weboob.capabilities.cinema import ICapCinema
from weboob.capabilities.torrent import ICapTorrent
from weboob.capabilities.subtitle import ICapSubtitle
from weboob.tools.application.qt import QtApplication
from .main_window import MainWindow
@ -31,7 +32,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,ICapTorrent
CAPS = ICapCinema,ICapTorrent,ICapSubtitle
CONFIG = {'settings': {'nsfw': 1,
'sfw': 1,
'sortby': 0,
@ -39,7 +40,7 @@ class QCineoob(QtApplication):
}
}
def main(self, argv):
self.load_backends([ICapCinema,ICapTorrent])
self.load_backends([ICapCinema,ICapTorrent,ICapSubtitle])
self.load_config()
self.main_window = MainWindow(self.config, self.weboob)

View file

@ -0,0 +1,64 @@
# -*- 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 <http://www.gnu.org/licenses/>.
import sys
from PyQt4.QtCore import Qt,SIGNAL
from PyQt4.QtGui import QFrame, QFileDialog
from weboob.applications.qcineoob.ui.subtitle_ui import Ui_Subtitle
from weboob.capabilities.base import NotAvailable, NotLoaded
class Subtitle(QFrame):
def __init__(self, subtitle, backend, parent=None):
QFrame.__init__(self, parent)
self.parent = parent
self.backend = backend
self.ui = Ui_Subtitle()
self.ui.setupUi(self)
self.connect(self.ui.downloadButton, SIGNAL("clicked()"), self.download)
self.subtitle = subtitle
self.ui.nameLabel.setText(u'%s'%subtitle.name)
if subtitle.url != NotAvailable:
self.ui.urlEdit.setText(u'%s'%subtitle.url)
self.ui.verticalLayout.setAlignment(Qt.AlignTop)
def download(self):
fileDial = QFileDialog(self,'Save "%s" subtitle file'%self.subtitle.name,'%s'%self.subtitle.name,'all files (*)')
fileDial.setAcceptMode(QFileDialog.AcceptSave)
fileDial.setLabelText(QFileDialog.Accept,'Save subtitle file')
fileDial.setLabelText(QFileDialog.FileName,'Subtitle file name')
ok = (fileDial.exec_() == 1)
if not ok:
return
result = fileDial.selectedFiles()
if len(result) > 0:
dest = result[0]
data = self.backend.get_subtitle_file(self.subtitle.id)
try:
with open(dest, 'w') as f:
f.write(data)
except IOError, e:
print >>sys.stderr, 'Unable to write subtitle file in "%s": %s' % (dest, e)
return 1
return

View file

@ -57,8 +57,16 @@
<string>torrent</string>
</property>
</item>
<item>
<property name="text">
<string>subtitle</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QComboBox" name="langCombo"/>
</item>
<item>
<widget class="QComboBox" name="backendEdit"/>
</item>

View file

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MiniSubtitle</class>
<widget class="QFrame" name="MiniSubtitle">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>464</width>
<height>136</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="imageLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="nameLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>50</weight>
<italic>true</italic>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_8">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Nb CD</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="nbcdLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Where</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="backendLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -0,0 +1,218 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Subtitle</class>
<widget class="QFrame" name="Subtitle">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>629</width>
<height>552</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>2000</width>
<height>600</height>
</size>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QFrame" name="frame_3">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>600</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="downloadButton">
<property name="text">
<string>Download</string>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="frame_9">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>35</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="nameLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="frame_6">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>35</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Size:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="sizeLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="frame_8">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>200</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Description:</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="descriptionPlain"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="frame_5">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>200</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Files:</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="filesPlain"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="urlFrame">
<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_7">
<property name="topMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Url:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="urlEdit"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>