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://hentai2read.com/"""
from .common import MangaExtractor
from .. import text
from .. import text, util
from . import hentaicdn
import re
import json
@@ -37,7 +37,7 @@ class Hentai2readMangaExtractor(MangaExtractor):
page, '<span itemprop="itemreviewed">', '</span>')
mtype, pos = text.extract(
page, '<small class="text-danger">[', ']</small>', pos)
manga_id = int(text.extract(page, 'data-mid="', '"', pos)[0])
manga_id = util.safe_int(text.extract(page, 'data-mid="', '"', pos)[0])
page, pos = text.extract(
page, '<ul class="nav-chapters remove-margin-b">', '</ul>\n</div>')
@@ -51,7 +51,8 @@ class Hentai2readMangaExtractor(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",
}))