Commit 5e247db7 authored by Julien Veyssier's avatar Julien Veyssier

[qcineoob] search by id

[qcookboob] undo previous modif on backends, exceptions  are handled by app
parent 95953d32
......@@ -43,5 +43,5 @@ class BtmonBrowser(BaseBrowser):
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()
......@@ -18,7 +18,7 @@
# 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
......@@ -43,11 +43,6 @@ class CuisineazBrowser(BaseBrowser):
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
......@@ -75,7 +75,7 @@ class ImdbBrowser(BaseBrowser):
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 @@ dict_hex = {'&#xE1;': u'á',
'&#xE0;': u'à',
'&#xC0;': u'À',
'&#xE2;': u'â',
'&#xC9;': u'É',
'&#xE7;': u'ç'
}
......
......@@ -46,5 +46,5 @@ class IsohuntBrowser(BaseBrowser):
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)
......@@ -18,7 +18,7 @@
# 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
......@@ -42,11 +42,6 @@ class MarmitonBrowser(BaseBrowser):
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
......@@ -49,9 +49,6 @@ class PiratebayBrowser(BaseBrowser):
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)
......@@ -28,6 +28,7 @@ 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.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 @@ class MainWindow(QtMainWindow):
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 @@ class MainWindow(QtMainWindow):
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()))
......
......@@ -179,7 +179,7 @@
<x>0</x>
<y>0</y>
<width>708</width>
<height>292</height>
<height>261</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2"/>
......@@ -212,6 +212,44 @@
</widget>
</widget>
</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>
</widget>
<widget class="QMenuBar" name="menubar">
......
......@@ -26,6 +26,7 @@ from PyQt4.QtGui import QApplication, QCompleter
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 @@ class MainWindow(QtMainWindow):
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):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment