Skip to content

Commit

Permalink
use 'str.partition()'
Browse files Browse the repository at this point in the history
The (r)partition method is always faster then split() or any other
method that has been replaced in this commit.
  • Loading branch information
mikf committed Aug 21, 2017
1 parent 017a72f commit c457703
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 13 deletions.
4 changes: 1 addition & 3 deletions gallery_dl/extractor/foolslide.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,9 @@ def get_metadata(self, page):
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
Expand Down
2 changes: 1 addition & 1 deletion gallery_dl/extractor/gfycat.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _select_format(self, gfycat):
key = fmt + "Url"
if key in gfycat:
url = gfycat[key]
gfycat["extension"] = url[url.rfind(".")+1:]
gfycat["extension"] = url.rpartition(".")[2]
return url

@staticmethod
Expand Down
6 changes: 3 additions & 3 deletions gallery_dl/extractor/imgbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def items(self):
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):
Expand Down
2 changes: 1 addition & 1 deletion gallery_dl/extractor/mangafox.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def get_metadata(self, page):
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):
Expand Down
5 changes: 2 additions & 3 deletions gallery_dl/extractor/mangapark.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,9 @@ def get_job_metadata(self, page):
(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
Expand Down
2 changes: 1 addition & 1 deletion gallery_dl/extractor/pinterest.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def _parse(response):
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)
Expand Down
2 changes: 1 addition & 1 deletion gallery_dl/extractor/pixiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def prepare_work(self, work):
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):
Expand Down

0 comments on commit c457703

Please sign in to comment.