Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nana] add nana extractor #2967

Merged
merged 4 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,17 @@ Description
Also emit metadata for text-only posts without media content.


extractor.nana.favkey
---------------------
Type
``string``
Default
``null``
Description
Your `Nana Favorite Key <https://nana.my.id/tutorial>`__,
used to access your favorite archives.


extractor.newgrounds.flash
--------------------------
Type
Expand Down
4 changes: 4 additions & 0 deletions docs/gallery-dl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@
"format": "original",
"include": "art"
},
"nana":
{
"favkey": null
},
"nijie":
{
"username": null,
Expand Down
6 changes: 6 additions & 0 deletions docs/supportedsites.md
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,12 @@ Consider all sites to be NSFW unless otherwise known.
<td>Galleries</td>
<td></td>
</tr>
<tr>
<td>Nana</td>
<td>https://nana.my.id/</td>
<td>Galleries, Favorites, Search Results</td>
<td></td>
</tr>
<tr>
<td>Naver</td>
<td>https://blog.naver.com/</td>
Expand Down
1 change: 1 addition & 0 deletions gallery_dl/extractor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"mememuseum",
"myhentaigallery",
"myportfolio",
"nana",
"naver",
"naverwebtoon",
"newgrounds",
Expand Down
115 changes: 115 additions & 0 deletions gallery_dl/extractor/nana.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# -*- coding: utf-8 -*-

# 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
# published by the Free Software Foundation.

"""Extractors for https://nana.my.id/"""

from .common import GalleryExtractor, Extractor, Message
from .. import text, exception
import json


class NanaGalleryExtractor(GalleryExtractor):
"""Extractor for image galleries from nana.my.id"""
category = "nana"
directory_fmt = ("{category}", "{title}")
pattern = r"(?:https?://)?nana\.my\.id/reader/([^/?#]+)"
test = (
(("https://nana.my.id/reader/"
"059f7de55a4297413bfbd432ce7d6e724dd42bae"), {
"pattern": r"https://nana\.my\.id/reader/"
r"\w+/image/page\?path=.*\.\w+",
"title" : "Everybody Loves Shion",
"artist" : "fuzui",
"tags" : list,
"count" : 29,
}),
(("https://nana.my.id/reader/"
"77c8712b67013e427923573379f5bafcc0c72e46"), {
"pattern": r"https://nana\.my\.id/reader/"
r"\w+/image/page\?path=.*\.\w+",
"title" : "Lovey-Dovey With an Otaku-Friendly Gyaru",
"artist" : "Sueyuu",
"tags" : ["Sueyuu"],
"count" : 58,
}),
)

def __init__(self, match):
self.gallery_id = match.group(1)
url = "https://nana.my.id/reader/" + self.gallery_id
GalleryExtractor.__init__(self, match, url)

def metadata(self, page):
title = text.unescape(
text.extract(page, '</a>&nbsp; ', '</div>')[0])
artist = text.unescape(text.extract(
page, '<title>', '</title>')[0])[len(title):-10]
tags = text.extract(page, 'Reader.tags = "', '"')[0]

return {
"gallery_id": self.gallery_id,
"title" : title,
"artist" : artist[4:] if artist.startswith(" by ") else "",
"tags" : tags.split(", ") if tags else (),
"lang" : "en",
"language" : "English",
}

def images(self, page):
data = json.loads(text.extract(page, "Reader.pages = ", ".pages")[0])
return [
("https://nana.my.id" + image, None)
for image in data["pages"]
]


class NanaSearchExtractor(Extractor):
"""Extractor for nana search results"""
category = "nana"
subcategory = "search"
pattern = r"(?:https?://)?nana\.my\.id(?:/?\?([^#]+))"
test = (
('https://nana.my.id/?q=+"elf"&sort=desc', {
"pattern": NanaGalleryExtractor.pattern,
"range": "1-100",
"count": 100,
}),
("https://nana.my.id/?q=favorites%3A", {
"pattern": NanaGalleryExtractor.pattern,
"count": ">= 2",
}),
)

def __init__(self, match):
Extractor.__init__(self, match)
self.params = text.parse_query(match.group(1))
self.params["p"] = text.parse_int(self.params.get("p"), 1)
self.params["q"] = self.params.get("q") or ""

def items(self):
if "favorites:" in self.params["q"]:
favkey = self.config("favkey")
if not favkey:
raise exception.AuthenticationError(
"'Favorite key' not provided. "
"Please see 'https://nana.my.id/tutorial'")
self.session.cookies.set("favkey", favkey, domain="nana.my.id")

data = {"_extractor": NanaGalleryExtractor}
while True:
try:
page = self.request(
"https://nana.my.id", params=self.params).text
except exception.HttpError:
return

for gallery in text.extract_iter(
page, '<div class="id3">', '</div>'):
url = "https://nana.my.id" + text.extract(
gallery, '<a href="', '"')[0]
yield Message.Queue, url, data

self.params["p"] += 1
3 changes: 3 additions & 0 deletions scripts/supportedsites.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@
"mangadex": {
"feed" : "Followed Feed",
},
"nana": {
"search": "Favorites, Search Results",
},
"nijie": {
"nuita" : "Nuita History",
},
Expand Down
4 changes: 4 additions & 0 deletions test/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ def setup_test_config():
config.set(("extractor", "mastodon.social"), "access-token",
"Blf9gVqG7GytDTfVMiyYQjwVMQaNACgf3Ds3IxxVDUQ")

config.set(("extractor", "nana"), "favkey",
"9237ddb82019558ea7d179e805100805"
"ea6aa1c53ca6885cd4c179f9fb22ead2")

config.set(("extractor", "deviantart"), "client-id", "7777")
config.set(("extractor", "deviantart"), "client-secret",
"ff14994c744d9208e5caeec7aab4a026")
Expand Down