finaly handle BrowserHTTPNotFound in backend browsers

This commit is contained in:
Julien Veyssier 2013-03-17 21:54:08 +01:00
commit 8d49950813
15 changed files with 78 additions and 50 deletions

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 from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound
from .pages import RecipePage, ResultsPage from .pages import RecipePage, ResultsPage
@ -42,6 +42,9 @@ class SevenFiftyGramsBrowser(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.750g.com/fiche_de_cuisine_complete.htm?recettes_id=%s' % id) self.location('http://www.750g.com/fiche_de_cuisine_complete.htm?recettes_id=%s' % 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)

View file

@ -48,5 +48,5 @@ class AttilasubBrowser(BaseBrowser):
self.location('http://davidbillemont3.free.fr/%s' % url_end) self.location('http://davidbillemont3.free.fr/%s' % url_end)
except BrowserHTTPNotFound: except BrowserHTTPNotFound:
return return
assert self.is_on_page(SubtitlesPage) if self.is_on_page(SubtitlesPage):
return self.page.get_subtitle(id) return self.page.get_subtitle(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 from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound
from .pages import TorrentsPage, TorrentPage from .pages import TorrentsPage, TorrentPage
@ -42,6 +42,9 @@ class BtmonBrowser(BaseBrowser):
return self.page.iter_torrents() return self.page.iter_torrents()
def get_torrent(self, id): def get_torrent(self, id):
try:
self.location('http://www.btmon.com/%s.html' % id) self.location('http://www.btmon.com/%s.html' % id)
except BrowserHTTPNotFound:
return
if 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 from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound
from .pages import RecipePage, ResultsPage from .pages import RecipePage, ResultsPage
@ -43,6 +43,9 @@ 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)

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 from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound
from .pages.torrents import TorrentsPage, TorrentPage from .pages.torrents import TorrentsPage, TorrentPage
@ -45,6 +45,9 @@ class IsohuntBrowser(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://isohunt.com/torrent_details/%s/?tab=summary' % id) self.location('https://isohunt.com/torrent_details/%s/?tab=summary' % id)
except BrowserHTTPNotFound:
return
if 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 from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound
from .pages import TorrentsPage, TorrentPage from .pages import TorrentsPage, TorrentPage
@ -45,6 +45,9 @@ class KickassBrowser(BaseBrowser):
return self.page.iter_torrents() return self.page.iter_torrents()
def get_torrent(self, id): def get_torrent(self, id):
try:
self.location('http://kat.ph/%s.html' % id) self.location('http://kat.ph/%s.html' % id)
assert self.is_on_page(TorrentPage) except BrowserHTTPNotFound:
return
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 from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound
from .pages import RecipePage, ResultsPage from .pages import RecipePage, ResultsPage
@ -42,6 +42,9 @@ 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)

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 from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound
from weboob.applications.suboob.suboob import LANGUAGE_CONV from weboob.applications.suboob.suboob import LANGUAGE_CONV
from .pages import SubtitlesPage, SearchPage, SubtitlePage from .pages import SubtitlesPage, SearchPage, SubtitlePage
@ -47,6 +47,9 @@ class OpensubtitlesBrowser(BaseBrowser):
return self.page.iter_subtitles() return self.page.iter_subtitles()
def get_subtitle(self, id): def get_subtitle(self, id):
try:
self.location('http://www.opensubtitles.org/subtitles/%s' % id) self.location('http://www.opensubtitles.org/subtitles/%s' % id)
assert self.is_on_page(SubtitlePage) except BrowserHTTPNotFound:
return
if self.is_on_page(SubtitlePage):
return self.page.get_subtitle() return self.page.get_subtitle()

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 from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound
from .pages import SongResultsPage, SonglyricsPage, ArtistResultsPage, ArtistSongsPage from .pages import SongResultsPage, SonglyricsPage, ArtistResultsPage, ArtistSongsPage
@ -50,6 +50,9 @@ class ParolesmaniaBrowser(BaseBrowser):
def get_lyrics(self, id): def get_lyrics(self, id):
ids = id.split('|') ids = id.split('|')
try:
self.location('http://www.parolesmania.com/paroles_%s/paroles_%s.html' % (ids[0], ids[1])) self.location('http://www.parolesmania.com/paroles_%s/paroles_%s.html' % (ids[0], ids[1]))
assert self.is_on_page(SonglyricsPage) except BrowserHTTPNotFound:
return
if self.is_on_page(SonglyricsPage):
return self.page.get_lyrics(id) return self.page.get_lyrics(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 from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound
from .pages import SongResultsPage, SonglyricsPage, ArtistResultsPage, ArtistSongsPage, HomePage from .pages import SongResultsPage, SonglyricsPage, ArtistResultsPage, ArtistSongsPage, HomePage
@ -45,6 +45,9 @@ class ParolesmusiqueBrowser(BaseBrowser):
return self.page.iter_lyrics(criteria, pattern) return self.page.iter_lyrics(criteria, pattern)
def get_lyrics(self, id): def get_lyrics(self, id):
try:
self.location('http://www.paroles-musique.com/paroles-%s' % id) self.location('http://www.paroles-musique.com/paroles-%s' % id)
assert self.is_on_page(SonglyricsPage) except BrowserHTTPNotFound:
return
if self.is_on_page(SonglyricsPage):
return self.page.get_lyrics(id) return self.page.get_lyrics(id)

View file

@ -20,7 +20,7 @@
import urllib import urllib
from weboob.tools.browser import BaseBrowser from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound
from .pages.index import IndexPage from .pages.index import IndexPage
from .pages.torrents import TorrentsPage, TorrentPage from .pages.torrents import TorrentsPage, TorrentPage
@ -49,6 +49,9 @@ 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)
assert self.is_on_page(TorrentPage) except BrowserHTTPNotFound:
return
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 from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound
from .pages import SongResultsPage, SonglyricsPage, ArtistResultsPage, ArtistSongsPage from .pages import SongResultsPage, SonglyricsPage, ArtistResultsPage, ArtistSongsPage
@ -48,6 +48,9 @@ class SeeklyricsBrowser(BaseBrowser):
return self.page.iter_lyrics() return self.page.iter_lyrics()
def get_lyrics(self, id): def get_lyrics(self, id):
try:
self.location('http://www.seeklyrics.com/lyrics/%s.html' % id) self.location('http://www.seeklyrics.com/lyrics/%s.html' % id)
assert self.is_on_page(SonglyricsPage) except BrowserHTTPNotFound:
return
if self.is_on_page(SonglyricsPage):
return self.page.get_lyrics(id) return self.page.get_lyrics(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 from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound
from .pages import SeriePage, SearchPage, SeasonPage, HomePage from .pages import SeriePage, SearchPage, SeasonPage, HomePage
@ -48,6 +48,9 @@ class TvsubtitlesBrowser(BaseBrowser):
return self.page.iter_subtitles(language, pattern) return self.page.iter_subtitles(language, pattern)
def get_subtitle(self, id): def get_subtitle(self, id):
try:
self.location('http://www.tvsubtitles.net/subtitle-%s.html' % id) self.location('http://www.tvsubtitles.net/subtitle-%s.html' % id)
assert self.is_on_page(SeasonPage) except BrowserHTTPNotFound:
return
if self.is_on_page(SeasonPage):
return self.page.get_subtitle() return self.page.get_subtitle()

View file

@ -28,7 +28,6 @@ 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
@ -406,10 +405,7 @@ class MainWindow(QtMainWindow):
backend_name = None backend_name = None
for backend in self.weboob.iter_backends(): for backend in self.weboob.iter_backends():
if backend.has_caps(cap) and ((backend_name and backend.name == backend_name) or not backend_name): 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)) exec('object = backend.get_%s(id)' % (stype))
except (BrowserHTTPNotFound, BrokenPageError):
object = None
if object: if object:
func_display = 'self.display' + stype[0].upper() + stype[1:] func_display = 'self.display' + stype[0].upper() + stype[1:]
exec("self.doAction('Details of %s \"%%s\"' %% object.%s, %s, [object, backend])" % exec("self.doAction('Details of %s \"%%s\"' %% object.%s, %s, [object, backend])" %

View file

@ -26,7 +26,6 @@ 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
@ -202,10 +201,7 @@ class MainWindow(QtMainWindow):
backend_name = None backend_name = None
for backend in self.weboob.iter_backends(): for backend in self.weboob.iter_backends():
if (backend_name and backend.name == backend_name) or not backend_name: if (backend_name and backend.name == backend_name) or not backend_name:
try:
recipe = backend.get_recipe(id) recipe = backend.get_recipe(id)
except (BrowserHTTPNotFound, BrokenPageError):
recipe = None
if recipe: if recipe:
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()