1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

use 'v[0] == "c"' instead of 'v.startswith("c")'

This commit is contained in:
Mike Fährmann 2024-10-15 08:24:06 +02:00
parent d68bb78f44
commit 36883e458e
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
10 changed files with 24 additions and 20 deletions

View File

@ -63,7 +63,7 @@ def main():
browser, _, profile = args.cookies_from_browser.partition(":") browser, _, profile = args.cookies_from_browser.partition(":")
browser, _, keyring = browser.partition("+") browser, _, keyring = browser.partition("+")
browser, _, domain = browser.partition("/") browser, _, domain = browser.partition("/")
if profile.startswith(":"): if profile and profile[0] == ":":
container = profile[1:] container = profile[1:]
profile = None profile = None
else: else:

View File

@ -74,7 +74,8 @@ def load_cookies_firefox(profile=None, container=None, domain=None):
cookies = [ cookies = [
Cookie( Cookie(
0, name, value, None, False, 0, name, value, None, False,
domain, True if domain else False, domain.startswith("."), domain, True if domain else False,
domain[0] == "." if domain else False,
path, True if path else False, secure, expires, path, True if path else False, secure, expires,
False, None, None, {}, False, None, None, {},
) )
@ -158,7 +159,8 @@ def load_cookies_chromium(browser_name, profile=None,
cookies.append(Cookie( cookies.append(Cookie(
0, name, value, None, False, 0, name, value, None, False,
domain, True if domain else False, domain.startswith("."), domain, True if domain else False,
domain[0] == "." if domain else False,
path, True if path else False, secure, expires or None, path, True if path else False, secure, expires or None,
False, None, None, {}, False, None, None, {},
)) ))
@ -323,7 +325,8 @@ def _safari_parse_cookies_record(data, cookies, host=None):
cookies.append(Cookie( cookies.append(Cookie(
0, name, value, None, False, 0, name, value, None, False,
domain, True if domain else False, domain.startswith("."), domain, True if domain else False,
domain[0] == "." if domain else False,
path, True if path else False, is_secure, expiration_date, path, True if path else False, is_secure, expiration_date,
False, None, None, {}, False, None, None, {},
)) ))

View File

@ -401,7 +401,7 @@ class DeviantartExtractor(Extractor):
html = content["html"] html = content["html"]
markup = html["markup"] markup = html["markup"]
if not markup.startswith("{"): if not markup or markup[0] != "{":
return markup return markup
if html["type"] == "tiptap": if html["type"] == "tiptap":

View File

@ -260,9 +260,9 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor):
"torrentcount" : extr('>Torrent Download (', ')'), "torrentcount" : extr('>Torrent Download (', ')'),
} }
if data["uploader"].startswith("<"): uploader = data["uploader"]
data["uploader"] = text.unescape(text.extr( if uploader and uploader[0] == "<":
data["uploader"], ">", "<")) data["uploader"] = text.unescape(text.extr(uploader, ">", "<"))
f = data["favorites"][0] f = data["favorites"][0]
if f == "N": if f == "N":

View File

@ -37,7 +37,7 @@ class FoolfuukaExtractor(BaseExtractor):
if not url and "remote_media_link" in media: if not url and "remote_media_link" in media:
url = self.remote(media) url = self.remote(media)
if url.startswith("/"): if url and url[0] == "/":
url = self.root + url url = self.root + url
post["filename"], _, post["extension"] = \ post["filename"], _, post["extension"] = \

View File

@ -19,7 +19,7 @@ BASE_PATTERN = r"(?:https?://)?(?:ww[\dw]?\.)?mangakakalot\.tv"
class MangakakalotBase(): class MangakakalotBase():
"""Base class for mangakakalot extractors""" """Base class for mangakakalot extractors"""
category = "mangakakalot" category = "mangakakalot"
root = "https://ww6.mangakakalot.tv" root = "https://ww8.mangakakalot.tv"
class MangakakalotChapterExtractor(MangakakalotBase, ChapterExtractor): class MangakakalotChapterExtractor(MangakakalotBase, ChapterExtractor):
@ -40,7 +40,7 @@ class MangakakalotChapterExtractor(MangakakalotBase, ChapterExtractor):
match = re.match( match = re.match(
r"(?:[Vv]ol\. *(\d+) )?" r"(?:[Vv]ol\. *(\d+) )?"
r"[Cc]hapter *([^:]*)" r"[Cc]hapter *([^:]*)"
r"(?:: *(.+))?", info) r"(?:: *(.+))?", info or "")
volume, chapter, title = match.groups() if match else ("", "", info) volume, chapter, title = match.groups() if match else ("", "", info)
chapter, sep, minor = chapter.partition(".") chapter, sep, minor = chapter.partition(".")
@ -86,7 +86,7 @@ class MangakakalotMangaExtractor(MangakakalotBase, MangaExtractor):
data["chapter"] = text.parse_int(chapter) data["chapter"] = text.parse_int(chapter)
data["chapter_minor"] = sep + minor data["chapter_minor"] = sep + minor
if url.startswith("/"): if url[0] == "/":
url = self.root + url url = self.root + url
results.append((url, data.copy())) results.append((url, data.copy()))
return results return results

View File

@ -50,7 +50,7 @@ class PostmillExtractor(BaseExtractor):
forum = match.group(1) forum = match.group(1)
id = int(match.group(2)) id = int(match.group(2))
is_text_post = url.startswith("/") is_text_post = (url[0] == "/")
is_image_post = self._search_image_tag(page) is not None is_image_post = self._search_image_tag(page) is not None
data = { data = {
"title": title, "title": title,

View File

@ -49,7 +49,7 @@ class TelegraphGalleryExtractor(GalleryExtractor):
url, pos = text.extract(figure, 'src="', '"') url, pos = text.extract(figure, 'src="', '"')
if url.startswith("/embed/"): if url.startswith("/embed/"):
continue continue
elif url.startswith("/"): elif url[0] == "/":
url = self.root + url url = self.root + url
caption, pos = text.extract(figure, "<figcaption>", "<", pos) caption, pos = text.extract(figure, "<figcaption>", "<", pos)
num += 1 num += 1

View File

@ -148,8 +148,10 @@ class TsuminoSearchExtractor(TsuminoBase, Extractor):
data["PageNumber"] += 1 data["PageNumber"] += 1
def _parse(self, query): def _parse(self, query):
if not query:
return {}
try: try:
if query.startswith("?"): if query[0] == "?":
return self._parse_simple(query) return self._parse_simple(query)
return self._parse_jsurl(query) return self._parse_jsurl(query)
except Exception as exc: except Exception as exc:
@ -187,8 +189,6 @@ class TsuminoSearchExtractor(TsuminoBase, Extractor):
Example: ~(name~'John*20Doe~age~42~children~(~'Mary~'Bill)) Example: ~(name~'John*20Doe~age~42~children~(~'Mary~'Bill))
Ref: https://github.com/Sage/jsurl Ref: https://github.com/Sage/jsurl
""" """
if not data:
return {}
i = 0 i = 0
imax = len(data) imax = len(data)

View File

@ -432,7 +432,7 @@ def cookiestxt_load(fp):
None, False, None, False,
domain, domain,
domain_specified == "TRUE", domain_specified == "TRUE",
domain.startswith("."), domain[0] == "." if domain else False,
path, False, path, False,
secure == "TRUE", secure == "TRUE",
None if expires == "0" or not expires else expires, None if expires == "0" or not expires else expires,
@ -458,9 +458,10 @@ def cookiestxt_store(fp, cookies):
name = cookie.name name = cookie.name
value = cookie.value value = cookie.value
domain = cookie.domain
write("\t".join(( write("\t".join((
cookie.domain, domain,
"TRUE" if cookie.domain.startswith(".") else "FALSE", "TRUE" if domain and domain[0] == "." else "FALSE",
cookie.path, cookie.path,
"TRUE" if cookie.secure else "FALSE", "TRUE" if cookie.secure else "FALSE",
"0" if cookie.expires is None else str(cookie.expires), "0" if cookie.expires is None else str(cookie.expires),