implement and use 'util.safe_int()'

same as Python's 'int()', except it doesn't raise any exceptions and
accepts a default value
This commit is contained in:
Mike Fährmann
2017-09-24 15:59:25 +02:00
parent 8a97bd0433
commit 9fc1d0c901
19 changed files with 149 additions and 113 deletions

View File

@@ -9,7 +9,7 @@
"""Extract hentai-manga from https://hentaihere.com/"""
from .common import MangaExtractor
from .. import text
from .. import text, util
from . import hentaicdn
import re
@@ -32,7 +32,8 @@ class HentaihereMangaExtractor(MangaExtractor):
def chapters(self, page):
results = []
manga_id = int(self.url.rstrip("/").rpartition("/")[2][1:])
manga_id = util.safe_int(
self.url.rstrip("/").rpartition("/")[2][1:])
manga, pos = text.extract(
page, '<span itemprop="name">', '</span>')
mtype, pos = text.extract(
@@ -48,7 +49,8 @@ class HentaihereMangaExtractor(MangaExtractor):
chapter, _, title = text.unescape(chapter).strip().partition(" - ")
results.append((url, {
"manga_id": manga_id, "manga": manga, "type": mtype,
"chapter_id": int(chapter_id), "chapter": int(chapter),
"chapter_id": util.safe_int(chapter_id),
"chapter": util.safe_int(chapter),
"title": title, "lang": "en", "language": "English",
}))