use 'str.partition()'
The (r)partition method is always faster then split() or any other method that has been replaced in this commit.
This commit is contained in:
@@ -76,11 +76,9 @@ class FoolslideChapterExtractor(Extractor):
|
||||
chapter, pos = text.extract(page, 'title="', '"', pos)
|
||||
|
||||
chapter = text.unescape(chapter)
|
||||
parts = chapter.split(":", maxsplit=1)
|
||||
title = parts[1].strip() if len(parts) > 1 else ""
|
||||
|
||||
self.data["manga"] = text.unescape(manga).strip()
|
||||
self.data["title"] = title
|
||||
self.data["title"] = chapter.partition(":")[2].strip()
|
||||
self.data["language"] = util.code_to_language(self.data["lang"])
|
||||
self.data["chapter_string"] = chapter
|
||||
return self.data
|
||||
|
||||
@@ -26,7 +26,7 @@ class GfycatExtractor(Extractor):
|
||||
key = fmt + "Url"
|
||||
if key in gfycat:
|
||||
url = gfycat[key]
|
||||
gfycat["extension"] = url[url.rfind(".")+1:]
|
||||
gfycat["extension"] = url.rpartition(".")[2]
|
||||
return url
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -54,11 +54,11 @@ class ImgboxGalleryExtractor(AsynchronousExtractor):
|
||||
def get_job_metadata(self, page):
|
||||
"""Collect metadata for extractor-job"""
|
||||
title = text.extract(page, "<h1>", "</h1>")[0]
|
||||
parts = title.rsplit(" - ", maxsplit=1)
|
||||
title, _, count = title.rpartition(" - ")
|
||||
return {
|
||||
"gallery-key": self.key,
|
||||
"title": text.unescape(parts[0]),
|
||||
"count": parts[1][:-7],
|
||||
"title": text.unescape(title),
|
||||
"count": count[:-7],
|
||||
}
|
||||
|
||||
def get_file_metadata(self, page):
|
||||
|
||||
@@ -60,7 +60,7 @@ class MangafoxChapterExtractor(AsynchronousExtractor):
|
||||
data["volume"] = match.group(2) or ""
|
||||
data["chapter"] = match.group(3)
|
||||
data["chapter-minor"] = match.group(4) or ""
|
||||
data["manga"] = data["manga"].rsplit(maxsplit=1)[0]
|
||||
data["manga"] = data["manga"].rpartition(" ")[0]
|
||||
return data
|
||||
|
||||
def get_image_urls(self, page):
|
||||
|
||||
@@ -89,10 +89,9 @@ class MangaparkChapterExtractor(Extractor):
|
||||
(None , 'target="_blank" href="', ''),
|
||||
("count" , 'page 1">1 / ', '<'),
|
||||
), values=data)[0]
|
||||
data["manga"], data["type"] = data["manga"].rsplit(" ", maxsplit=1)
|
||||
data["manga"], _, data["type"] = data["manga"].rpartition(" ")
|
||||
data["manga"] = text.unescape(data["manga"])
|
||||
pos = data["title"].find(": ")
|
||||
data["title"] = data["title"][pos+2:] if pos != -1 else ""
|
||||
data["title"] = data["title"].partition(": ")[2]
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -178,7 +178,7 @@ class PinterestAPI():
|
||||
data = response.json()
|
||||
if "data" not in data or data["data"] is None:
|
||||
try:
|
||||
msg = data["message"].split(maxsplit=1)[0].lower()
|
||||
msg = data["message"].partition(" ")[0].lower()
|
||||
except KeyError:
|
||||
msg = ""
|
||||
raise exception.NotFoundError(msg)
|
||||
|
||||
@@ -82,7 +82,7 @@ class PixivExtractor(Extractor):
|
||||
url = work["image_urls"]["large"]
|
||||
work["num"] = ""
|
||||
work["url"] = url
|
||||
work["extension"] = url[url.rfind(".")+1:]
|
||||
work["extension"] = url.rpartition(".")[2]
|
||||
return work
|
||||
|
||||
def parse_ugoira(self, data):
|
||||
|
||||
Reference in New Issue
Block a user