import performance in doufen
This commit is contained in:
parent
9550e73f65
commit
5033f15abc
4 changed files with 40 additions and 7 deletions
|
@ -2,6 +2,7 @@ from catalog.common import *
|
|||
from django.utils.translation import gettext_lazy as _
|
||||
from django.db import models
|
||||
from catalog.common.utils import DEFAULT_ITEM_COVER
|
||||
from functools import cached_property
|
||||
|
||||
|
||||
class Performance(Item):
|
||||
|
@ -114,6 +115,14 @@ class Performance(Item):
|
|||
"official_site",
|
||||
]
|
||||
|
||||
@cached_property
|
||||
def all_productions(self):
|
||||
return (
|
||||
self.productions.all()
|
||||
.order_by("title")
|
||||
.filter(is_deleted=False, merged_to_item=None)
|
||||
)
|
||||
|
||||
|
||||
class PerformanceProduction(Item):
|
||||
type = ItemType.PerformanceProduction
|
||||
|
@ -231,7 +240,7 @@ class PerformanceProduction(Item):
|
|||
@property
|
||||
def cover_image_url(self):
|
||||
return (
|
||||
self.cover_image_url
|
||||
self.cover.url
|
||||
if self.cover and self.cover != DEFAULT_ITEM_COVER
|
||||
else self.show.cover_image_url
|
||||
)
|
||||
|
|
|
@ -4,6 +4,7 @@ from .douban import DoubanDownloader
|
|||
import logging
|
||||
from lxml import html
|
||||
from django.core.cache import cache
|
||||
import re
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -23,12 +24,18 @@ class DoubanDramaVersion(AbstractSite):
|
|||
|
||||
SITE_NAME = SiteName.Douban
|
||||
ID_TYPE = IdType.DoubanDramaVersion
|
||||
URL_PATTERNS = [
|
||||
# the pattern is skipped to avoid user fetching the version without fetching the drama page
|
||||
]
|
||||
URL_PATTERNS = [r"\w+://www.douban.com/location/drama/(\d+)/#(\d+)$"]
|
||||
|
||||
WIKI_PROPERTY_ID = "?"
|
||||
DEFAULT_MODEL = PerformanceProduction
|
||||
|
||||
@classmethod
|
||||
def url_to_id(cls, url: str):
|
||||
m = re.match(cls.URL_PATTERNS[0], url)
|
||||
if not m:
|
||||
return None
|
||||
return m.group(1) + "-" + m.group(2)
|
||||
|
||||
@classmethod
|
||||
def id_to_url(cls, id_value):
|
||||
ids = id_value.split("-")
|
||||
|
@ -49,8 +56,11 @@ class DoubanDramaVersion(AbstractSite):
|
|||
p = "//div[@id='" + version_id + "']"
|
||||
q = p + "//dt[text()='{}:']/following-sibling::dd[1]/a/span/text()"
|
||||
q2 = p + "//dt[text()='{}:']/following-sibling::dd[1]/text()"
|
||||
title = " ".join(h.xpath(p + "//h3/text()")).strip()
|
||||
if not title:
|
||||
raise ParseError(self, "title")
|
||||
data = {
|
||||
"title": " ".join(h.xpath(p + "//h3/text()")).strip(),
|
||||
"title": title,
|
||||
"director": [x.strip() for x in h.xpath(q.format("导演"))],
|
||||
"playwright": [x.strip() for x in h.xpath(q.format("编剧"))],
|
||||
"performer": [x.strip() for x in h.xpath(q.format("主演"))],
|
||||
|
@ -60,6 +70,8 @@ class DoubanDramaVersion(AbstractSite):
|
|||
"troupe": [x.strip() for x in h.xpath(q.format("演出团体"))],
|
||||
"location": [x.strip() for x in h.xpath(q.format("演出剧院"))],
|
||||
}
|
||||
img_url_elem = h.xpath("//img[@itemprop='image']/@src")
|
||||
data["cover_image_url"] = img_url_elem[0].strip() if img_url_elem else None
|
||||
pd = ResourceContent(metadata=data)
|
||||
pd.metadata["required_resources"] = [
|
||||
{
|
||||
|
@ -70,6 +82,15 @@ class DoubanDramaVersion(AbstractSite):
|
|||
"url": show_url,
|
||||
}
|
||||
]
|
||||
if pd.metadata["cover_image_url"]:
|
||||
imgdl = BasicImageDownloader(pd.metadata["cover_image_url"], self.url)
|
||||
try:
|
||||
pd.cover_image = imgdl.download().content
|
||||
pd.cover_image_extention = imgdl.extention
|
||||
except Exception:
|
||||
_logger.debug(
|
||||
f'failed to download cover for {self.url} from {pd.metadata["cover_image_url"]}'
|
||||
)
|
||||
return pd
|
||||
|
||||
|
||||
|
@ -77,7 +98,7 @@ class DoubanDramaVersion(AbstractSite):
|
|||
class DoubanDrama(AbstractSite):
|
||||
SITE_NAME = SiteName.Douban
|
||||
ID_TYPE = IdType.DoubanDrama
|
||||
URL_PATTERNS = [r"\w+://www.douban.com/location/drama/(\d+)/"]
|
||||
URL_PATTERNS = [r"\w+://www.douban.com/location/drama/(\d+)/[^#]*$"]
|
||||
WIKI_PROPERTY_ID = "P6443"
|
||||
DEFAULT_MODEL = Performance
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
</div>
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
{% with item.productions.all as productions %}
|
||||
{% with item.all_productions as productions %}
|
||||
{% if productions %}
|
||||
<h5>{% trans '上演版本' %}</h5>
|
||||
<div>
|
||||
|
|
|
@ -120,11 +120,14 @@ class DoubanImporter:
|
|||
"想玩": [ShelfType.WISHLIST],
|
||||
"在玩": [ShelfType.PROGRESS],
|
||||
"玩过": [ShelfType.COMPLETE],
|
||||
"想看的舞台剧": [ShelfType.WISHLIST],
|
||||
"看过的舞台剧": [ShelfType.COMPLETE],
|
||||
}
|
||||
review_sheet_config = {
|
||||
"书评": [Edition],
|
||||
"影评": [Movie],
|
||||
"乐评": [Album],
|
||||
"剧评": [Performance],
|
||||
"游戏评论&攻略": [Game],
|
||||
}
|
||||
mark_data = {}
|
||||
|
|
Loading…
Add table
Reference in a new issue