use sets for ' in { ... }' checks

This commit is contained in:
Mike Fährmann
2026-02-11 22:55:01 +01:00
parent fc589e9ea4
commit 12f5e24ab5
17 changed files with 44 additions and 44 deletions

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2020-2025 Mike Fährmann # Copyright 2020-2026 Mike Fährmann
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as # it under the terms of the GNU General Public License version 2 as
@@ -156,11 +156,11 @@ class AryionExtractor(Extractor):
headers = response.headers headers = response.headers
# folder # folder
if headers["content-type"] in ( if headers["content-type"] in {
"application/x-folder", "application/x-folder",
"application/x-comic-folder", "application/x-comic-folder",
"application/x-comic-folder-nomerge", "application/x-comic-folder-nomerge",
): }:
return False return False
# get filename from 'Content-Disposition' header # get filename from 'Content-Disposition' header

View File

@@ -784,7 +784,7 @@ class Extractor():
with open(path + ".txt", 'wb') as fp: with open(path + ".txt", 'wb') as fp:
util.dump_response( util.dump_response(
response, fp, response, fp,
headers=(self._write_pages in ("all", "ALL")), headers=(self._write_pages in {"all", "ALL"}),
hide_auth=(self._write_pages != "ALL") hide_auth=(self._write_pages != "ALL")
) )
self.log.info("Writing '%s' response to '%s'", self.log.info("Writing '%s' response to '%s'",

View File

@@ -60,7 +60,7 @@ class DiscordExtractor(Extractor):
def extract_message(self, message): def extract_message(self, message):
# https://discord.com/developers/docs/resources/message#message-object-message-types # https://discord.com/developers/docs/resources/message#message-object-message-types
if message["type"] in (0, 19, 21): if message["type"] in {0, 19, 21}:
message_metadata = {} message_metadata = {}
message_metadata.update(self.server_metadata) message_metadata.update(self.server_metadata)
message_metadata.update( message_metadata.update(
@@ -92,7 +92,7 @@ class DiscordExtractor(Extractor):
message_snapshots = [message] message_snapshots = [message]
message_snapshots.extend( message_snapshots.extend(
msg["message"] for msg in message.get("message_snapshots", []) msg["message"] for msg in message.get("message_snapshots", [])
if msg["message"]["type"] in (0, 19, 21) if msg["message"]["type"] in {0, 19, 21}
) )
for snapshot in message_snapshots: for snapshot in message_snapshots:
@@ -153,15 +153,15 @@ class DiscordExtractor(Extractor):
) )
# https://discord.com/developers/docs/resources/channel#channel-object-channel-types # https://discord.com/developers/docs/resources/channel#channel-object-channel-types
if channel_type in (0, 5): if channel_type in {0, 5}:
yield from self.extract_channel_text(channel_id) yield from self.extract_channel_text(channel_id)
if self.enabled_threads: if self.enabled_threads:
yield from self.extract_channel_threads(channel_id) yield from self.extract_channel_threads(channel_id)
elif channel_type in (1, 3, 10, 11, 12): elif channel_type in {1, 3, 10, 11, 12}:
yield from self.extract_channel_text(channel_id) yield from self.extract_channel_text(channel_id)
elif channel_type in (15, 16): elif channel_type in {15, 16}:
yield from self.extract_channel_threads(channel_id) yield from self.extract_channel_threads(channel_id)
elif channel_type in (4,): elif channel_type == 4:
for channel in self.server_channels_metadata.copy().values(): for channel in self.server_channels_metadata.copy().values():
if channel["parent_id"] == channel_id: if channel["parent_id"] == channel_id:
yield from self.extract_channel( yield from self.extract_channel(
@@ -192,7 +192,7 @@ class DiscordExtractor(Extractor):
"parent_type": parent_metadata["channel_type"] "parent_type": parent_metadata["channel_type"]
}) })
if channel_metadata["channel_type"] in (1, 3): if channel_metadata["channel_type"] in {1, 3}:
channel_metadata.update({ channel_metadata.update({
"channel": "DMs", "channel": "DMs",
"recipients": ( "recipients": (
@@ -355,7 +355,7 @@ class DiscordServerExtractor(DiscordExtractor):
self.build_server_and_channels(server_id) self.build_server_and_channels(server_id)
for channel in self.server_channels_metadata.copy().values(): for channel in self.server_channels_metadata.copy().values():
if channel["channel_type"] in (0, 5, 15, 16): if channel["channel_type"] in {0, 5, 15, 16}:
yield from self.extract_channel( yield from self.extract_channel(
channel["channel_id"], safe=True) channel["channel_id"], safe=True)

View File

@@ -97,7 +97,7 @@ class FapelloPathExtractor(Extractor):
def items(self): def items(self):
num = 1 num = 1
if self.path in ("top-likes", "top-followers"): if self.path in {"top-likes", "top-followers"}:
data = {"_extractor": FapelloModelExtractor} data = {"_extractor": FapelloModelExtractor}
else: else:
data = {"_extractor": FapelloPostExtractor} data = {"_extractor": FapelloPostExtractor}

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2014-2025 Mike Fährmann # Copyright 2014-2026 Mike Fährmann
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as # it under the terms of the GNU General Public License version 2 as
@@ -217,7 +217,7 @@ class GelbooruFavoriteExtractor(GelbooruBase,
"a" if order > 0 else "de") "a" if order > 0 else "de")
order_favs = self.config("order-posts") order_favs = self.config("order-posts")
if order_favs and order_favs[0] in ("r", "a"): if order_favs and order_favs[0] in {"r", "a"}:
self.log.debug("Returning them in reverse") self.log.debug("Returning them in reverse")
order = -order order = -order

View File

@@ -160,9 +160,9 @@ class HotleakCategoryExtractor(HotleakExtractor):
def items(self): def items(self):
url = f"{self.root}/{self._category}" url = f"{self.root}/{self._category}"
if self._category in ("hot", "creators"): if self._category in {"hot", "creators"}:
data = {"_extractor": HotleakCreatorExtractor} data = {"_extractor": HotleakCreatorExtractor}
elif self._category in ("videos", "photos"): elif self._category in {"videos", "photos"}:
data = {"_extractor": HotleakPostExtractor} data = {"_extractor": HotleakPostExtractor}
for item in self._pagination(url, self.params): for item in self._pagination(url, self.params):

View File

@@ -54,7 +54,7 @@ class InstagramExtractor(Extractor):
self._warn_video = True if self.config("warn-videos", True) else False self._warn_video = True if self.config("warn-videos", True) else False
self._warn_image = ( self._warn_image = (
9 if not (wi := self.config("warn-images", True)) else 9 if not (wi := self.config("warn-images", True)) else
1 if wi in ("all", "both") else 1 if wi in {"all", "both"} else
0) 0)
def items(self): def items(self):
@@ -70,7 +70,7 @@ class InstagramExtractor(Extractor):
max_posts = self.config("max-posts") max_posts = self.config("max-posts")
order = self.config("order-files") order = self.config("order-files")
reverse = order[0] in ("r", "d") if order else False reverse = order[0] in {"r", "d"} if order else False
posts = self.posts() posts = self.posts()
if max_posts: if max_posts:
@@ -831,9 +831,9 @@ class InstagramRestAPI():
reel_ids = [hl["id"] for hl in self.highlights_tray(user_id)] reel_ids = [hl["id"] for hl in self.highlights_tray(user_id)]
if order := self.extractor.config("order-posts"): if order := self.extractor.config("order-posts"):
if order in ("desc", "reverse"): if order in {"desc", "reverse"}:
reel_ids.reverse() reel_ids.reverse()
elif order in ("id", "id_asc"): elif order in {"id", "id_asc"}:
reel_ids.sort(key=lambda r: int(r[10:])) reel_ids.sort(key=lambda r: int(r[10:]))
elif order == "id_desc": elif order == "id_desc":
reel_ids.sort(key=lambda r: int(r[10:]), reverse=True) reel_ids.sort(key=lambda r: int(r[10:]), reverse=True)

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2021-2025 Mike Fährmann # Copyright 2021-2026 Mike Fährmann
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as # it under the terms of the GNU General Public License version 2 as
@@ -42,7 +42,7 @@ class KemonoExtractor(Extractor):
if self.revisions: if self.revisions:
self.revisions_unique = (self.revisions == "unique") self.revisions_unique = (self.revisions == "unique")
order = self.config("order-revisions") order = self.config("order-revisions")
self.revisions_reverse = order[0] in ("r", "a") if order else False self.revisions_reverse = order[0] in {"r", "a"} if order else False
self._find_inline = text.re( self._find_inline = text.re(
r'src="(?:https?://(?:kemono\.cr|coomer\.st))?(/inline/[^"]+' r'src="(?:https?://(?:kemono\.cr|coomer\.st))?(/inline/[^"]+'
@@ -352,7 +352,7 @@ class KemonoUserExtractor(KemonoExtractor):
_, _, service, creator_id, query = self.groups _, _, service, creator_id, query = self.groups
params = text.parse_query(query) params = text.parse_query(query)
if self.config("endpoint") in ("posts+", "legacy+"): if self.config("endpoint") in {"posts+", "legacy+"}:
endpoint = self.api.creator_posts_expand endpoint = self.api.creator_posts_expand
else: else:
endpoint = self.api.creator_posts endpoint = self.api.creator_posts
@@ -439,7 +439,7 @@ class KemonoDiscordExtractor(KemonoExtractor):
archives = True if self.config("archives") else False archives = True if self.config("archives") else False
exts_archive = util.EXTS_ARCHIVE exts_archive = util.EXTS_ARCHIVE
if (order := self.config("order-posts")) and order[0] in ("r", "d"): if (order := self.config("order-posts")) and order[0] in {"r", "d"}:
posts = self.api.discord_channel(channel_id, channel["post_count"]) posts = self.api.discord_channel(channel_id, channel["post_count"])
else: else:
posts = self.api.discord_channel(channel_id) posts = self.api.discord_channel(channel_id)

View File

@@ -255,7 +255,7 @@ class MisskeyAPI():
date_min, date_max = extr._get_date_min_max() date_min, date_max = extr._get_date_min_max()
if (order := extr.config("order-posts")) and \ if (order := extr.config("order-posts")) and \
order[0] in ("a", "r"): order[0] in {"a", "r"}:
key = "sinceId" key = "sinceId"
data["sinceDate"] = 1 if date_min is None else date_min * 1000 data["sinceDate"] = 1 if date_min is None else date_min * 1000
date_stop = None if date_max is None else date_max date_stop = None if date_max is None else date_max

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2017-2025 Mike Fährmann # Copyright 2017-2026 Mike Fährmann
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as # it under the terms of the GNU General Public License version 2 as
@@ -454,7 +454,7 @@ class OAuthPixiv(OAuthBase):
if "error" in data: if "error" in data:
stdout_write(f"\n{data}\n") stdout_write(f"\n{data}\n")
if data["error"] in ("invalid_request", "invalid_grant"): if data["error"] in {"invalid_request", "invalid_grant"}:
stdout_write("'code' expired, try again\n\n") stdout_write("'code' expired, try again\n\n")
return return

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2014-2025 Mike Fährmann # Copyright 2014-2026 Mike Fährmann
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as # it under the terms of the GNU General Public License version 2 as
@@ -131,11 +131,11 @@ class PixivExtractor(Extractor):
self.log.debug("%s: %s", work_id, url) self.log.debug("%s: %s", work_id, url)
limit_type = url.rpartition("/")[2] limit_type = url.rpartition("/")[2]
if limit_type in ( if limit_type in {
"limit_", # for '_extend_sanity()' inserts "limit_", # for '_extend_sanity()' inserts
"limit_unviewable_360.png", "limit_unviewable_360.png",
"limit_sanity_level_360.png", "limit_sanity_level_360.png",
): }:
work["_ajax"] = True work["_ajax"] = True
self.log.warning("%s: 'limit_sanity_level' warning", work_id) self.log.warning("%s: 'limit_sanity_level' warning", work_id)
if self.sanity_workaround: if self.sanity_workaround:

View File

@@ -299,7 +299,7 @@ class TwitterExtractor(Extractor):
if domain in cbl or name + ":" + domain in cbl: if domain in cbl or name + ":" + domain in cbl:
return return
if name in ("summary", "summary_large_image"): if name in {"summary", "summary_large_image"}:
for prefix in ("photo_image_full_size_", for prefix in ("photo_image_full_size_",
"summary_photo_image_", "summary_photo_image_",
"thumbnail_image_"): "thumbnail_image_"):
@@ -1080,7 +1080,7 @@ class TwitterTweetExtractor(TwitterExtractor):
return self._tweets_conversation(self.tweet_id) return self._tweets_conversation(self.tweet_id)
endpoint = self.config("tweet-endpoint") endpoint = self.config("tweet-endpoint")
if endpoint == "detail" or endpoint in (None, "auto") and \ if endpoint == "detail" or endpoint in {None, "auto"} and \
self.api.headers["x-twitter-auth-type"]: self.api.headers["x-twitter-auth-type"]:
return self._tweets_detail(self.tweet_id) return self._tweets_detail(self.tweet_id)
@@ -1402,7 +1402,7 @@ class TwitterAPI():
if tweet.get("__typename") == "TweetUnavailable": if tweet.get("__typename") == "TweetUnavailable":
reason = tweet.get("reason") reason = tweet.get("reason")
if reason in ("NsfwViewerHasNoStatedAge", "NsfwLoggedOut"): if reason in {"NsfwViewerHasNoStatedAge", "NsfwLoggedOut"}:
raise exception.AuthRequired(message="NSFW Tweet") raise exception.AuthRequired(message="NSFW Tweet")
if reason == "Protected": if reason == "Protected":
raise exception.AuthRequired(message="Protected Tweet") raise exception.AuthRequired(message="Protected Tweet")
@@ -1545,7 +1545,7 @@ class TwitterAPI():
} }
pgn = cfg("search-pagination") pgn = cfg("search-pagination")
if pgn in ("max_id", "maxid", "id"): if pgn in {"max_id", "maxid", "id"}:
update_variables = self._update_variables_search_maxid update_variables = self._update_variables_search_maxid
elif pgn in {"until", "date", "datetime", "dt"}: elif pgn in {"until", "date", "datetime", "dt"}:
update_variables = self._update_variables_search_date update_variables = self._update_variables_search_date
@@ -1856,7 +1856,7 @@ class TwitterAPI():
if response.status_code < 400: if response.status_code < 400:
return data return data
elif response.status_code in (403, 404) and \ elif response.status_code in {403, 404} and \
not self.headers["x-twitter-auth-type"]: not self.headers["x-twitter-auth-type"]:
raise exception.AuthRequired( raise exception.AuthRequired(
"authenticated cookies", "timeline") "authenticated cookies", "timeline")

View File

@@ -66,7 +66,7 @@ def process_content(html, content):
html.append(level) html.append(level)
html.append(">") html.append(">")
elif type in ("listItem", "bulletList", "orderedList", "blockquote"): elif type in {"listItem", "bulletList", "orderedList", "blockquote"}:
c = type[1] c = type[1]
tag = ( tag = (
"li" if c == "i" else "li" if c == "i" else

View File

@@ -30,7 +30,7 @@ class WikimediaExtractor(BaseExtractor):
labels = self.root.split(".") labels = self.root.split(".")
self.lang = labels[-3][-2:] self.lang = labels[-3][-2:]
self.category = labels[-2] self.category = labels[-2]
elif self.category in ("fandom", "wikigg"): elif self.category in {"fandom", "wikigg"}:
self.lang = "en" self.lang = "en"
self.format = "original" self.format = "original"
self.basesubcategory = self.category self.basesubcategory = self.category

View File

@@ -126,7 +126,7 @@ class XenforoExtractor(BaseExtractor):
def items_media(self, path, pnum, callback=None): def items_media(self, path, pnum, callback=None):
if (order := self.config("order-posts")) and \ if (order := self.config("order-posts")) and \
order[0] in ("d", "r"): order[0] in {"d", "r"}:
pages = self._pagination_reverse(path, pnum, callback) pages = self._pagination_reverse(path, pnum, callback)
reverse = True reverse = True
else: else:
@@ -491,7 +491,7 @@ class XenforoThreadExtractor(XenforoExtractor):
pnum = self.groups[-1] pnum = self.groups[-1]
if (order := self.config("order-posts")) and \ if (order := self.config("order-posts")) and \
order[0] not in ("d", "r"): order[0] not in {"d", "r"}:
params = "?order=reaction_score" if order[0] == "s" else "" params = "?order=reaction_score" if order[0] == "s" else ""
pages = self._pagination(path, pnum, params=params) pages = self._pagination(path, pnum, params=params)
reverse = False reverse = False

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2021-2025 Mike Fährmann # Copyright 2021-2026 Mike Fährmann
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as # it under the terms of the GNU General Public License version 2 as
@@ -126,7 +126,7 @@ class YoutubeDLExtractor(Extractor):
if not entry: if not entry:
continue continue
if entry.get("_type") in ("url", "url_transparent"): if entry.get("_type") in {"url", "url_transparent"}:
try: try:
entry = ytdl_instance.extract_info( entry = ytdl_instance.extract_info(
entry["url"], False, entry["url"], False,

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2022-2025 Mike Fährmann # Copyright 2022-2026 Mike Fährmann
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as # it under the terms of the GNU General Public License version 2 as
@@ -294,7 +294,7 @@ class ZerochanImageExtractor(ZerochanExtractor):
try: try:
post = self._parse_entry_html(image_id) post = self._parse_entry_html(image_id)
except exception.HttpError as exc: except exception.HttpError as exc:
if exc.status in (404, 410): if exc.status in {404, 410}:
if msg := text.extr(exc.response.text, "<h2>", "<"): if msg := text.extr(exc.response.text, "<h2>", "<"):
self.log.warning(f"'{msg}'") self.log.warning(f"'{msg}'")
return () return ()