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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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