From 5e247db743f648f4b81207689b56bf9e16a9e41d Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Sun, 17 Mar 2013 18:19:07 +0100 Subject: [PATCH] [qcineoob] search by id [qcookboob] undo previous modif on backends, exceptions are handled by app --- modules/btmon/browser.py | 4 +- modules/cuisineaz/browser.py | 9 +---- modules/imdb/browser.py | 3 +- modules/isohunt/browser.py | 4 +- modules/marmiton/browser.py | 9 +---- modules/piratebay/browser.py | 5 +-- weboob/applications/qcineoob/main_window.py | 34 +++++++++++++++- .../applications/qcineoob/ui/main_window.ui | 40 ++++++++++++++++++- weboob/applications/qcookboob/main_window.py | 13 +++--- 9 files changed, 90 insertions(+), 31 deletions(-) diff --git a/modules/btmon/browser.py b/modules/btmon/browser.py index f1504aa690..af987ce9cc 100644 --- a/modules/btmon/browser.py +++ b/modules/btmon/browser.py @@ -43,5 +43,5 @@ def iter_torrents(self, pattern): def get_torrent(self, id): self.location('http://www.btmon.com/%s.html' % id) - assert self.is_on_page(TorrentPage) - return self.page.get_torrent() + if self.is_on_page(TorrentPage): + return self.page.get_torrent() diff --git a/modules/cuisineaz/browser.py b/modules/cuisineaz/browser.py index fb33b907a4..929429c1ae 100644 --- a/modules/cuisineaz/browser.py +++ b/modules/cuisineaz/browser.py @@ -18,7 +18,7 @@ # along with weboob. If not, see . -from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound +from weboob.tools.browser import BaseBrowser from .pages import RecipePage, ResultsPage @@ -43,11 +43,6 @@ def iter_recipes(self, pattern): return self.page.iter_recipes() def get_recipe(self, id): - try: - self.location('http://www.cuisineaz.com/recettes/%s.aspx' % id) - except BrowserHTTPNotFound: - return + self.location('http://www.cuisineaz.com/recettes/%s.aspx' % id) if self.is_on_page(RecipePage): return self.page.get_recipe(id) - else: - return diff --git a/modules/imdb/browser.py b/modules/imdb/browser.py index 41175aa326..02905cbd9e 100644 --- a/modules/imdb/browser.py +++ b/modules/imdb/browser.py @@ -75,7 +75,7 @@ def iter_persons(self, pattern): for cat in ['name_popular', 'name_exact', 'name_approx']: if cat in jres: 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.birth_place = NotLoaded person.birth_date = NotLoaded @@ -218,6 +218,7 @@ def get_movie_releases(self, id, country): 'à': u'à', 'À': u'À', 'â': u'â', + 'É': u'É', 'ç': u'ç' } diff --git a/modules/isohunt/browser.py b/modules/isohunt/browser.py index 292a23e823..1ab235d04d 100644 --- a/modules/isohunt/browser.py +++ b/modules/isohunt/browser.py @@ -46,5 +46,5 @@ def iter_torrents(self, pattern): def get_torrent(self, id): self.location('https://isohunt.com/torrent_details/%s/?tab=summary' % id) - assert self.is_on_page(TorrentPage) - return self.page.get_torrent(id) + if self.is_on_page(TorrentPage): + return self.page.get_torrent(id) diff --git a/modules/marmiton/browser.py b/modules/marmiton/browser.py index d39b9c60fe..ba2346766a 100644 --- a/modules/marmiton/browser.py +++ b/modules/marmiton/browser.py @@ -18,7 +18,7 @@ # along with weboob. If not, see . -from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound +from weboob.tools.browser import BaseBrowser from .pages import RecipePage, ResultsPage @@ -42,11 +42,6 @@ def iter_recipes(self, pattern): return self.page.iter_recipes() def get_recipe(self, id): - try: - self.location('http://www.marmiton.org/recettes/recette_%s.aspx' % id) - except BrowserHTTPNotFound: - return + self.location('http://www.marmiton.org/recettes/recette_%s.aspx' % id) if self.is_on_page(RecipePage): return self.page.get_recipe(id) - else: - return diff --git a/modules/piratebay/browser.py b/modules/piratebay/browser.py index 8914f99212..e621c9a021 100644 --- a/modules/piratebay/browser.py +++ b/modules/piratebay/browser.py @@ -49,9 +49,6 @@ def iter_torrents(self, pattern): return self.page.iter_torrents() def get_torrent(self, id): - try: - self.location('https://thepiratebay.se/torrent/%s/' % id) - except: - return None + self.location('https://thepiratebay.se/torrent/%s/' % id) assert self.is_on_page(TorrentPage) return self.page.get_torrent(id) diff --git a/weboob/applications/qcineoob/main_window.py b/weboob/applications/qcineoob/main_window.py index bc311923e1..ae94e0ac00 100644 --- a/weboob/applications/qcineoob/main_window.py +++ b/weboob/applications/qcineoob/main_window.py @@ -28,6 +28,7 @@ from weboob.capabilities.subtitle import ICapSubtitle from weboob.tools.application.qt import QtMainWindow, QtDo 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.qcineoob.ui.main_window_ui import Ui_MainWindow @@ -64,7 +65,7 @@ def __init__(self, config, weboob, parent=None): self.ui.backButton.hide() 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.actionBackends, SIGNAL("triggered()"), self.backendsConfig) @@ -384,6 +385,37 @@ def displaySubtitle(self, subtitle, backend): self.ui.info_content.layout().addWidget(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): self.config.set('settings', 'backend', str(self.ui.backendEdit.itemData( self.ui.backendEdit.currentIndex()).toString())) diff --git a/weboob/applications/qcineoob/ui/main_window.ui b/weboob/applications/qcineoob/ui/main_window.ui index dcf213df07..18d4375ae1 100644 --- a/weboob/applications/qcineoob/ui/main_window.ui +++ b/weboob/applications/qcineoob/ui/main_window.ui @@ -179,7 +179,7 @@ 0 0 708 - 292 + 261 @@ -212,6 +212,44 @@ + + + + + + Search by id: + + + + + + + + + + + movie + + + + + person + + + + + torrent + + + + + subtitle + + + + + + diff --git a/weboob/applications/qcookboob/main_window.py b/weboob/applications/qcookboob/main_window.py index 96a92b0c2d..85d96e1ed8 100644 --- a/weboob/applications/qcookboob/main_window.py +++ b/weboob/applications/qcookboob/main_window.py @@ -26,6 +26,7 @@ from weboob.capabilities.recipe import ICapRecipe from weboob.tools.application.qt import QtMainWindow, QtDo 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 @@ -199,14 +200,14 @@ def searchId(self): id = id.split('@')[0] else: backend_name = None - fail = True for backend in self.weboob.iter_backends(): - if (backend_name != None and backend.name == backend_name) or backend_name == None: - recipe = backend.get_recipe(id) + if (backend_name and backend.name == backend_name) or not backend_name: + try: + recipe = backend.get_recipe(id) + except (BrowserHTTPNotFound, BrokenPageError): + recipe = None 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() def closeEvent(self, ev): -- GitLab