do not use 'append = list.append'

This commit is contained in:
Mike Fährmann
2025-06-30 11:42:44 +02:00
parent 9dec26108e
commit 3810555bbd
8 changed files with 36 additions and 47 deletions

View File

@@ -145,9 +145,7 @@ class BehanceGalleryExtractor(BehanceExtractor):
raise exception.AuthorizationError()
return ()
result = []
append = result.append
results = []
for module in data["modules"]:
mtype = module["__typename"][:-6].lower()
@@ -165,7 +163,7 @@ class BehanceGalleryExtractor(BehanceExtractor):
sizes.get("fs") or
sizes.get("hd") or
sizes.get("disp"))
append((size["url"], module))
results.append((size["url"], module))
elif mtype == "video":
try:
@@ -177,7 +175,7 @@ class BehanceGalleryExtractor(BehanceExtractor):
url = "ytdl:" + url
module["_ytdl_manifest"] = "hls"
module["extension"] = "mp4"
append((url, module))
results.append((url, module))
continue
except Exception as exc:
self.log.debug("%s: %s", exc.__class__.__name__, exc)
@@ -198,7 +196,7 @@ class BehanceGalleryExtractor(BehanceExtractor):
self.log.debug("%s: %s", exc.__class__.__name__, exc)
url = "ytdl:" + renditions[-1]["url"]
append((url, module))
results.append((url, module))
elif mtype == "mediacollection":
for component in module["components"]:
@@ -206,7 +204,7 @@ class BehanceGalleryExtractor(BehanceExtractor):
if size:
parts = size["url"].split("/")
parts[4] = "source"
append(("/".join(parts), module))
results.append(("/".join(parts), module))
break
elif mtype == "embed":
@@ -214,13 +212,13 @@ class BehanceGalleryExtractor(BehanceExtractor):
if embed:
embed = text.unescape(text.extr(embed, 'src="', '"'))
module["extension"] = "mp4"
append(("ytdl:" + embed, module))
results.append(("ytdl:" + embed, module))
elif mtype == "text":
module["extension"] = "txt"
append(("text:" + module["text"], module))
results.append(("text:" + module["text"], module))
return result
return results
class BehanceUserExtractor(BehanceExtractor):

View File

@@ -109,12 +109,11 @@ class E621PoolExtractor(E621Extractor, danbooru.DanbooruPoolExtractor):
}
posts = []
append = posts.append
for num, pid in enumerate(self.post_ids, 1):
if pid in id_to_post:
post = id_to_post[pid]
post["num"] = num
append(post)
posts.append(post)
else:
self.log.warning("Post %s is unavailable", pid)
return posts

View File

@@ -428,15 +428,14 @@ class KemonoDiscordExtractor(KemonoExtractor):
for post in posts:
files = []
append = files.append
for attachment in post["attachments"]:
match = find_hash(attachment["path"])
attachment["hash"] = match[1] if match else ""
attachment["type"] = "attachment"
append(attachment)
files.append(attachment)
for path in find_inline(post["content"] or ""):
append({"path": "https://cdn.discordapp.com" + path,
"name": path, "type": "inline", "hash": ""})
files.append({"path": "https://cdn.discordapp.com" + path,
"name": path, "type": "inline", "hash": ""})
post.update(data)
post["date"] = self._parse_datetime(post["published"])

View File

@@ -45,8 +45,6 @@ class NitterExtractor(BaseExtractor):
attachments = tweet.pop("_attach", "")
if attachments:
files = []
append = files.append
for url in text.extract_iter(
attachments, 'href="', '"'):
@@ -66,12 +64,12 @@ class NitterExtractor(BaseExtractor):
file = {"url": url, "_http_retry": _retry_on_404}
file["filename"], _, file["extension"] = \
name.rpartition(".")
append(file)
files.append(file)
if videos and not files:
if ytdl:
url = f"ytdl:{self.root}/i/status/{tweet['tweet_id']}"
append({"url": url, "extension": "mp4"})
files.append({"url": url, "extension": "mp4"})
else:
for url in text.extract_iter(
attachments, 'data-url="', '"'):
@@ -84,7 +82,7 @@ class NitterExtractor(BaseExtractor):
if url[0] == "/":
url = self.root + url
append({
files.append({
"url" : "ytdl:" + url,
"filename" : name.rpartition(".")[0],
"extension": "mp4",
@@ -94,7 +92,8 @@ class NitterExtractor(BaseExtractor):
attachments, '<source src="', '"'):
if url[0] == "/":
url = self.root + url
append(text.nameext_from_url(url, {"url": url}))
files.append(
text.nameext_from_url(url, {"url": url}))
else:
files = ()

View File

@@ -63,14 +63,12 @@ class SzurubooruExtractor(booru.BooruExtractor):
post["creationTime"], "%Y-%m-%dT%H:%M:%S.%fZ")
tags = []
append = tags.append
tags_categories = collections.defaultdict(list)
for tag in post["tags"]:
tag_type = tag["category"].rpartition("_")[2]
tag_name = tag["names"][0]
tags_categories[tag_type].append(tag_name)
append(tag_name)
tags.append(tag_name)
post["tags"] = tags
for category, tags in tags_categories.items():

View File

@@ -98,16 +98,15 @@ class WeiboExtractor(Extractor):
yield Message.Url, file["url"], file
def _extract_status(self, status, files):
append = files.append
if "mix_media_info" in status:
for item in status["mix_media_info"]["items"]:
type = item.get("type")
if type == "video":
if self.videos:
append(self._extract_video(item["data"]["media_info"]))
files.append(self._extract_video(
item["data"]["media_info"]))
elif type == "pic":
append(item["data"]["largest"].copy())
files.append(item["data"]["largest"].copy())
else:
self.log.warning("Unknown media type '%s'", type)
return
@@ -121,22 +120,22 @@ class WeiboExtractor(Extractor):
if pic_type == "gif" and self.gifs:
if self.gifs_video:
append({"url": pic["video"]})
files.append({"url": pic["video"]})
else:
append(pic["largest"].copy())
files.append(pic["largest"].copy())
elif pic_type == "livephoto" and self.livephoto:
append(pic["largest"].copy())
append({"url": pic["video"]})
files.append(pic["largest"].copy())
files.append({"url": pic["video"]})
else:
append(pic["largest"].copy())
files.append(pic["largest"].copy())
if "page_info" in status:
info = status["page_info"]
if "media_info" in info and self.videos:
if info.get("type") != "5" or self.movies:
append(self._extract_video(info["media_info"]))
files.append(self._extract_video(info["media_info"]))
else:
self.log.debug("%s: Ignoring 'movie' video", status["id"])

View File

@@ -280,7 +280,6 @@ class PathFormat():
def build_directory(self, kwdict):
"""Apply 'kwdict' to directory format strings"""
segments = []
append = segments.append
strip = self.strip
try:
@@ -290,14 +289,13 @@ class PathFormat():
# remove trailing dots and spaces (#647)
segment = segment.rstrip(strip)
if segment:
append(self.clean_segment(segment))
segments.append(self.clean_segment(segment))
return segments
except Exception as exc:
raise exception.DirectoryFormatError(exc)
def build_directory_conditional(self, kwdict):
segments = []
append = segments.append
strip = self.strip
try:
@@ -311,7 +309,7 @@ class PathFormat():
if strip and segment != "..":
segment = segment.rstrip(strip)
if segment:
append(self.clean_segment(segment))
segments.append(self.clean_segment(segment))
return segments
except Exception as exc:
raise exception.DirectoryFormatError(exc)

View File

@@ -378,13 +378,13 @@ class UgoiraPP(PostProcessor):
def _write_ffmpeg_concat(self, tempdir):
content = ["ffconcat version 1.0"]
append = content.append
for frame in self._frames:
append(f"file '{frame['file']}'\nduration {frame['delay'] / 1000}")
content.append(f"file '{frame['file']}'\n"
f"duration {frame['delay'] / 1000}")
if self.repeat:
append(f"file '{frame['file']}'")
append("")
content.append(f"file '{frame['file']}'")
content.append("")
ffconcat = tempdir + "/ffconcat.txt"
with open(ffconcat, "w") as fp:
@@ -393,14 +393,13 @@ class UgoiraPP(PostProcessor):
def _write_mkvmerge_timecodes(self, tempdir):
content = ["# timecode format v2"]
append = content.append
delay_sum = 0
for frame in self._frames:
append(str(delay_sum))
content.append(str(delay_sum))
delay_sum += frame["delay"]
append(str(delay_sum))
append("")
content.append(str(delay_sum))
content.append("")
timecodes = tempdir + "/timecodes.tc"
with open(timecodes, "w") as fp: