add jjwcx parser
This commit is contained in:
parent
f500037d63
commit
f1ad888de0
8 changed files with 77 additions and 2 deletions
|
@ -234,6 +234,7 @@ class Edition(Item):
|
||||||
IdType.Goodreads,
|
IdType.Goodreads,
|
||||||
IdType.GoogleBooks,
|
IdType.GoogleBooks,
|
||||||
IdType.Qidian,
|
IdType.Qidian,
|
||||||
|
IdType.JJWXC,
|
||||||
]
|
]
|
||||||
return [(i.value, i.label) for i in id_types]
|
return [(i.value, i.label) for i in id_types]
|
||||||
|
|
||||||
|
|
|
@ -423,6 +423,25 @@ class QidianTestCase(TestCase):
|
||||||
self.assertEqual(site.resource.item.author[0], "爱潜水的乌贼")
|
self.assertEqual(site.resource.item.author[0], "爱潜水的乌贼")
|
||||||
|
|
||||||
|
|
||||||
|
class JinJiangTestCase(TestCase):
|
||||||
|
databases = "__all__"
|
||||||
|
|
||||||
|
@use_local_response
|
||||||
|
def test_scrape(self):
|
||||||
|
t_url = "https://www.jjwxc.net/onebook.php?novelid=5833245"
|
||||||
|
site = SiteManager.get_site_by_url(t_url)
|
||||||
|
self.assertEqual(site.ready, False)
|
||||||
|
site.get_resource_ready()
|
||||||
|
self.assertEqual(site.ready, True)
|
||||||
|
self.assertEqual(site.resource.site_name, SiteName.JJWXC)
|
||||||
|
self.assertEqual(site.resource.id_type, IdType.JJWXC)
|
||||||
|
self.assertEqual(site.resource.id_value, "5833245")
|
||||||
|
self.assertEqual(
|
||||||
|
site.resource.item.display_title, "穿进赛博游戏后干掉BOSS成功上位"
|
||||||
|
)
|
||||||
|
self.assertEqual(site.resource.item.author[0], "桉柏")
|
||||||
|
|
||||||
|
|
||||||
class YpshuoTestCase(TestCase):
|
class YpshuoTestCase(TestCase):
|
||||||
databases = "__all__"
|
databases = "__all__"
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@ class SiteName(models.TextChoices):
|
||||||
Qidian = "qidian", _("Qidian") # type:ignore[reportCallIssue]
|
Qidian = "qidian", _("Qidian") # type:ignore[reportCallIssue]
|
||||||
Ypshuo = "ypshuo", _("Ypshuo") # type:ignore[reportCallIssue]
|
Ypshuo = "ypshuo", _("Ypshuo") # type:ignore[reportCallIssue]
|
||||||
AO3 = "ao3", _("Archive of Our Own") # type:ignore[reportCallIssue]
|
AO3 = "ao3", _("Archive of Our Own") # type:ignore[reportCallIssue]
|
||||||
|
JJWXC = "jjwxc", _("JinJiang") # type:ignore[reportCallIssue]
|
||||||
|
|
||||||
|
|
||||||
class IdType(models.TextChoices):
|
class IdType(models.TextChoices):
|
||||||
|
@ -117,6 +118,7 @@ class IdType(models.TextChoices):
|
||||||
Qidian = "qidian", _("Qidian") # type:ignore[reportCallIssue]
|
Qidian = "qidian", _("Qidian") # type:ignore[reportCallIssue]
|
||||||
Ypshuo = "ypshuo", _("Ypshuo") # type:ignore[reportCallIssue]
|
Ypshuo = "ypshuo", _("Ypshuo") # type:ignore[reportCallIssue]
|
||||||
AO3 = "ao3", _("Archive of Our Own") # type:ignore[reportCallIssue]
|
AO3 = "ao3", _("Archive of Our Own") # type:ignore[reportCallIssue]
|
||||||
|
JJWXC = "jjwxc", _("JinJiang") # type:ignore[reportCallIssue]
|
||||||
|
|
||||||
|
|
||||||
IdealIdTypes = [
|
IdealIdTypes = [
|
||||||
|
|
|
@ -16,6 +16,7 @@ from .goodreads import Goodreads
|
||||||
from .google_books import GoogleBooks
|
from .google_books import GoogleBooks
|
||||||
from .igdb import IGDB
|
from .igdb import IGDB
|
||||||
from .imdb import IMDB
|
from .imdb import IMDB
|
||||||
|
from .jjwxc import JJWXC
|
||||||
from .qidian import Qidian
|
from .qidian import Qidian
|
||||||
from .rss import RSS
|
from .rss import RSS
|
||||||
from .spotify import Spotify
|
from .spotify import Spotify
|
||||||
|
|
39
catalog/sites/jjwxc.py
Normal file
39
catalog/sites/jjwxc.py
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
import html
|
||||||
|
|
||||||
|
from catalog.common import *
|
||||||
|
from catalog.models import *
|
||||||
|
|
||||||
|
|
||||||
|
@SiteManager.register
|
||||||
|
class JJWXC(AbstractSite):
|
||||||
|
SITE_NAME = SiteName.JJWXC
|
||||||
|
ID_TYPE = IdType.JJWXC
|
||||||
|
URL_PATTERNS = [
|
||||||
|
r"https://www\.jjwxc\.net/onebook\.php\?novelid=(\d+)",
|
||||||
|
]
|
||||||
|
WIKI_PROPERTY_ID = ""
|
||||||
|
DEFAULT_MODEL = Edition
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def id_to_url(cls, id_value):
|
||||||
|
return f"https://www.jjwxc.net/onebook.php?novelid={id_value}"
|
||||||
|
|
||||||
|
def scrape(self):
|
||||||
|
api_url = (
|
||||||
|
f"https://app.jjwxc.net/androidapi/novelbasicinfo?novelId={self.id_value}"
|
||||||
|
)
|
||||||
|
o = BasicDownloader(api_url).download().json()
|
||||||
|
return ResourceContent(
|
||||||
|
metadata={
|
||||||
|
"localized_title": [{"lang": "zh-cn", "text": o["novelName"]}],
|
||||||
|
"author": [o["authorName"]],
|
||||||
|
"format": Edition.BookFormat.WEB,
|
||||||
|
"localized_description": [
|
||||||
|
{
|
||||||
|
"lang": "zh-cn",
|
||||||
|
"text": html.unescape(o["novelIntro"]).replace("<br/>", "\n"),
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cover_image_url": o["novelCover"],
|
||||||
|
},
|
||||||
|
)
|
|
@ -24,8 +24,14 @@ class Ypshuo(AbstractSite):
|
||||||
source = json.loads(o["data"]["source"])
|
source = json.loads(o["data"]["source"])
|
||||||
lookup_ids = {}
|
lookup_ids = {}
|
||||||
for site in source:
|
for site in source:
|
||||||
if site["siteName"] == "起点中文网":
|
match site["siteName"]:
|
||||||
|
case "起点中文网":
|
||||||
lookup_ids[IdType.Qidian] = site["bookId"]
|
lookup_ids[IdType.Qidian] = site["bookId"]
|
||||||
|
case "晋江文学城":
|
||||||
|
lookup_ids[IdType.JJWXC] = site["bookPage"].rsplit("=", maxsplit=1)[
|
||||||
|
-1
|
||||||
|
]
|
||||||
|
|
||||||
return ResourceContent(
|
return ResourceContent(
|
||||||
metadata={
|
metadata={
|
||||||
"localized_title": [{"lang": "zh-cn", "text": o["data"]["novel_name"]}],
|
"localized_title": [{"lang": "zh-cn", "text": o["data"]["novel_name"]}],
|
||||||
|
|
|
@ -30,6 +30,12 @@
|
||||||
background-color: #9e252b;
|
background-color: #9e252b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.jjwxc {
|
||||||
|
border: none;
|
||||||
|
color: white;
|
||||||
|
background-color: #3c812e;
|
||||||
|
}
|
||||||
|
|
||||||
.douban {
|
.douban {
|
||||||
border: none;
|
border: none;
|
||||||
color: white;
|
color: white;
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue