Skip to content

Commit

Permalink
[nozomi] support '/index-N.html' URLs (closes #1365)
Browse files Browse the repository at this point in the history
and '/index-Popular-N.html'
  • Loading branch information
mikf committed Mar 11, 2021
1 parent 780bac4 commit 4be27ff
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/supportedsites.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Ngomik http://ngomik.in/ Chapters
nhentai https://nhentai.net/ Galleries, Search Results
Niconico Seiga https://seiga.nicovideo.jp/ individual Images, User Profiles Required
nijie https://nijie.info/ |nijie-C| Required
Nozomi.la https://nozomi.la/ Posts, Search Results, Tag Searches
Nozomi.la https://nozomi.la/ Site Index, Posts, Search Results, Tag Searches
NSFWalbum.com https://nsfwalbum.com/ Albums
Nyafuu Archive https://archive.nyafuu.org/ Boards, Search Results, Threads
Patreon https://www.patreon.com/ Creators, Posts, User Profiles `Cookies <https://github.com/mikf/gallery-dl#cookies>`__
Expand Down
54 changes: 35 additions & 19 deletions gallery_dl/extractor/nozomi.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,23 @@ def items(self):
post["dataid"] = post["filename"]
yield Message.Url, url, post

def posts(self):
url = "https://n.nozomi.la" + self.nozomi
offset = (text.parse_int(self.pnum, 1) - 1) * 256

while True:
headers = {"Range": "bytes={}-{}".format(offset, offset+255)}
response = self.request(url, headers=headers)
yield from decode_nozomi(response.content)

offset += 256
cr = response.headers.get("Content-Range", "").rpartition("/")[2]
if text.parse_int(cr, offset) <= offset:
return

def metadata(self):
return {}

def posts(self):
return ()

@staticmethod
def _list(src):
return [x["tagname_display"] for x in src] if src else ()
Expand Down Expand Up @@ -126,12 +137,29 @@ def posts(self):
return (self.post_id,)


class NozomiIndexExtractor(NozomiExtractor):
"""Extractor for the nozomi.la index"""
subcategory = "index"
pattern = (r"(?:https?://)?nozomi\.la/"
r"(?:(index(?:-Popular)?)-(\d+)\.html)?(?:$|#|\?)")
test = (
("https://nozomi.la/"),
("https://nozomi.la/index-2.html"),
("https://nozomi.la/index-Popular-33.html"),
)

def __init__(self, match):
NozomiExtractor.__init__(self, match)
index, self.pnum = match.groups()
self.nozomi = "/{}.nozomi".format(index or "index")


class NozomiTagExtractor(NozomiExtractor):
"""Extractor for posts from tag searches on nozomi.la"""
subcategory = "tag"
directory_fmt = ("{category}", "{search_tags}")
archive_fmt = "t_{search_tags}_{postid}"
pattern = r"(?:https?://)?nozomi\.la/tag/([^/?#]+)-\d+\."
pattern = r"(?:https?://)?nozomi\.la/tag/([^/?#]+)-(\d+)\."
test = ("https://nozomi.la/tag/3:1_aspect_ratio-1.html", {
"pattern": r"^https://i.nozomi.la/\w/\w\w/\w+\.\w+$",
"count": ">= 25",
Expand All @@ -140,25 +168,13 @@ class NozomiTagExtractor(NozomiExtractor):

def __init__(self, match):
NozomiExtractor.__init__(self, match)
self.tags = text.unquote(match.group(1)).lower()
tags, self.pnum = match.groups()
self.tags = text.unquote(tags).lower()
self.nozomi = "/nozomi/{}.nozomi".format(self.tags)

def metadata(self):
return {"search_tags": self.tags}

def posts(self):
url = "https://n.nozomi.la/nozomi/{}.nozomi".format(self.tags)
i = 0

while True:
headers = {"Range": "bytes={}-{}".format(i, i+255)}
response = self.request(url, headers=headers)
yield from decode_nozomi(response.content)

i += 256
cr = response.headers.get("Content-Range", "").rpartition("/")[2]
if text.parse_int(cr, i) <= i:
return


class NozomiSearchExtractor(NozomiExtractor):
"""Extractor for search results on nozomi.la"""
Expand Down
1 change: 1 addition & 0 deletions scripts/supportedsites.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"doujin" : "Doujin",
"gallery": "Galleries",
"image" : "individual Images",
"index" : "Site Index",
"issue" : "Comic Issues",
"manga" : "Manga",
"popular": "Popular Images",
Expand Down

0 comments on commit 4be27ff

Please sign in to comment.