[qcineoob] search by id

[qcookboob] undo previous modif on backends, exceptions  are handled by app
This commit is contained in:
Julien Veyssier 2013-03-17 18:19:07 +01:00
commit 5e247db743
9 changed files with 90 additions and 31 deletions

View file

@ -43,5 +43,5 @@ class BtmonBrowser(BaseBrowser):
def get_torrent(self, id): def get_torrent(self, id):
self.location('http://www.btmon.com/%s.html' % id) self.location('http://www.btmon.com/%s.html' % id)
assert self.is_on_page(TorrentPage) if self.is_on_page(TorrentPage):
return self.page.get_torrent() return self.page.get_torrent()

View file

@ -18,7 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound from weboob.tools.browser import BaseBrowser
from .pages import RecipePage, ResultsPage from .pages import RecipePage, ResultsPage
@ -43,11 +43,6 @@ class CuisineazBrowser(BaseBrowser):
return self.page.iter_recipes() return self.page.iter_recipes()
def get_recipe(self, id): def get_recipe(self, id):
try: self.location('http://www.cuisineaz.com/recettes/%s.aspx' % id)
self.location('http://www.cuisineaz.com/recettes/%s.aspx' % id)
except BrowserHTTPNotFound:
return
if self.is_on_page(RecipePage): if self.is_on_page(RecipePage):
return self.page.get_recipe(id) return self.page.get_recipe(id)
else:
return

View file

@ -75,7 +75,7 @@ class ImdbBrowser(BaseBrowser):
for cat in ['name_popular', 'name_exact', 'name_approx']: for cat in ['name_popular', 'name_exact', 'name_approx']:
if cat in jres: if cat in jres:
for p in jres[cat]: for p in jres[cat]:
person = Person(p['id'], latin2unicode(p['name'])) person = Person(p['id'], latin2unicode(unicode(p['name'])))
person.real_name = NotLoaded person.real_name = NotLoaded
person.birth_place = NotLoaded person.birth_place = NotLoaded
person.birth_date = NotLoaded person.birth_date = NotLoaded
@ -218,6 +218,7 @@ dict_hex = {'&#xE1;': u'á',
'&#xE0;': u'à', '&#xE0;': u'à',
'&#xC0;': u'À', '&#xC0;': u'À',
'&#xE2;': u'â', '&#xE2;': u'â',
'&#xC9;': u'É',
'&#xE7;': u'ç' '&#xE7;': u'ç'
} }

View file

@ -46,5 +46,5 @@ class IsohuntBrowser(BaseBrowser):
def get_torrent(self, id): def get_torrent(self, id):
self.location('https://isohunt.com/torrent_details/%s/?tab=summary' % id) self.location('https://isohunt.com/torrent_details/%s/?tab=summary' % id)
assert self.is_on_page(TorrentPage) if self.is_on_page(TorrentPage):
return self.page.get_torrent(id) return self.page.get_torrent(id)

View file

@ -18,7 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound from weboob.tools.browser import BaseBrowser
from .pages import RecipePage, ResultsPage from .pages import RecipePage, ResultsPage
@ -42,11 +42,6 @@ class MarmitonBrowser(BaseBrowser):
return self.page.iter_recipes() return self.page.iter_recipes()
def get_recipe(self, id): def get_recipe(self, id):
try: self.location('http://www.marmiton.org/recettes/recette_%s.aspx' % id)
self.location('http://www.marmiton.org/recettes/recette_%s.aspx' % id)
except BrowserHTTPNotFound:
return
if self.is_on_page(RecipePage): if self.is_on_page(RecipePage):
return self.page.get_recipe(id) return self.page.get_recipe(id)
else:
return

View file

@ -49,9 +49,6 @@ class PiratebayBrowser(BaseBrowser):
return self.page.iter_torrents() return self.page.iter_torrents()
def get_torrent(self, id): def get_torrent(self, id):
try: self.location('https://thepiratebay.se/torrent/%s/' % id)
self.location('https://thepiratebay.se/torrent/%s/' % id)
except:
return None
assert self.is_on_page(TorrentPage) assert self.is_on_page(TorrentPage)
return self.page.get_torrent(id) return self.page.get_torrent(id)

View file

@ -28,6 +28,7 @@ from weboob.capabilities.torrent import ICapTorrent
from weboob.capabilities.subtitle import ICapSubtitle from weboob.capabilities.subtitle import ICapSubtitle
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.tools.browser import BrowserHTTPNotFound, BrokenPageError
from weboob.applications.suboob.suboob import LANGUAGE_CONV from weboob.applications.suboob.suboob import LANGUAGE_CONV
from weboob.applications.qcineoob.ui.main_window_ui import Ui_MainWindow from weboob.applications.qcineoob.ui.main_window_ui import Ui_MainWindow
@ -64,7 +65,7 @@ class MainWindow(QtMainWindow):
self.ui.backButton.hide() self.ui.backButton.hide()
self.connect(self.ui.searchEdit, SIGNAL("returnPressed()"), self.search) self.connect(self.ui.searchEdit, SIGNAL("returnPressed()"), self.search)
self.connect(self.ui.typeCombo, SIGNAL("returnPressed()"), self.search) self.connect(self.ui.idEdit, SIGNAL("returnPressed()"), self.searchId)
self.connect(self.ui.typeCombo, SIGNAL("currentIndexChanged(QString)"), self.typeComboChanged) self.connect(self.ui.typeCombo, SIGNAL("currentIndexChanged(QString)"), self.typeComboChanged)
self.connect(self.ui.actionBackends, SIGNAL("triggered()"), self.backendsConfig) self.connect(self.ui.actionBackends, SIGNAL("triggered()"), self.backendsConfig)
@ -384,6 +385,37 @@ class MainWindow(QtMainWindow):
self.ui.info_content.layout().addWidget(wsubtitle) self.ui.info_content.layout().addWidget(wsubtitle)
self.current_info_widget = wsubtitle self.current_info_widget = wsubtitle
def searchId(self):
QApplication.setOverrideCursor(Qt.WaitCursor)
stype = unicode(self.ui.idTypeCombo.currentText())
title_field = 'name'
if stype == 'movie':
cap = ICapCinema
title_field = 'original_title'
elif stype == 'person':
cap = ICapCinema
elif stype == 'torrent':
cap = ICapTorrent
elif stype == 'subtitle':
cap = ICapSubtitle
id = unicode(self.ui.idEdit.text())
if '@' in id:
backend_name = id.split('@')[1]
id = id.split('@')[0]
else:
backend_name = None
for backend in self.weboob.iter_backends():
if backend.has_caps(cap) and ((backend_name and backend.name == backend_name) or not backend_name):
try:
exec('object = backend.get_%s(id)' % (stype))
except (BrowserHTTPNotFound, BrokenPageError):
object = None
if object:
func_display = 'self.display' + stype[0].upper() + stype[1:]
exec("self.doAction('Details of %s \"%%s\"' %% object.%s, %s, [object, backend])" %
(stype, title_field, func_display))
QApplication.restoreOverrideCursor()
def closeEvent(self, ev): def closeEvent(self, ev):
self.config.set('settings', 'backend', str(self.ui.backendEdit.itemData( self.config.set('settings', 'backend', str(self.ui.backendEdit.itemData(
self.ui.backendEdit.currentIndex()).toString())) self.ui.backendEdit.currentIndex()).toString()))

View file

@ -179,7 +179,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>708</width> <width>708</width>
<height>292</height> <height>261</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"/> <layout class="QVBoxLayout" name="verticalLayout_2"/>
@ -212,6 +212,44 @@
</widget> </widget>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Search by id:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="idEdit"/>
</item>
<item>
<widget class="QComboBox" name="idTypeCombo">
<item>
<property name="text">
<string>movie</string>
</property>
</item>
<item>
<property name="text">
<string>person</string>
</property>
</item>
<item>
<property name="text">
<string>torrent</string>
</property>
</item>
<item>
<property name="text">
<string>subtitle</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QMenuBar" name="menubar"> <widget class="QMenuBar" name="menubar">

View file

@ -26,6 +26,7 @@ from PyQt4.QtGui import QApplication, QCompleter
from weboob.capabilities.recipe import ICapRecipe from weboob.capabilities.recipe import ICapRecipe
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.tools.browser import BrowserHTTPNotFound, BrokenPageError
from weboob.applications.qcookboob.ui.main_window_ui import Ui_MainWindow from weboob.applications.qcookboob.ui.main_window_ui import Ui_MainWindow
@ -199,14 +200,14 @@ class MainWindow(QtMainWindow):
id = id.split('@')[0] id = id.split('@')[0]
else: else:
backend_name = None backend_name = None
fail = True
for backend in self.weboob.iter_backends(): for backend in self.weboob.iter_backends():
if (backend_name != None and backend.name == backend_name) or backend_name == None: if (backend_name and backend.name == backend_name) or not backend_name:
recipe = backend.get_recipe(id) try:
recipe = backend.get_recipe(id)
except (BrowserHTTPNotFound, BrokenPageError):
recipe = None
if recipe: if recipe:
fail = False self.doAction('Details of recipe "%s"' % recipe.title, self.displayRecipe, [recipe, backend])
self.doAction('Details of recipe "%s"' %
recipe.title, self.displayRecipe, [recipe, backend])
QApplication.restoreOverrideCursor() QApplication.restoreOverrideCursor()
def closeEvent(self, ev): def closeEvent(self, ev):