urlinfo:imdb: add support for "CreativeWork" resources
This commit is contained in:
parent
d84f82768d
commit
b7a683c11d
1 changed files with 21 additions and 12 deletions
|
|
@ -33,7 +33,7 @@ def thumbnail(url, width=182, height=268):
|
|||
The default settings are what IMDb currently uses for desktop display.
|
||||
"""
|
||||
resize = f"UY{height}" # there's also 'UX' to resize on width
|
||||
offset = "2,0" # by setting non-0 for the first value the image is fitted
|
||||
offset = "0,0"
|
||||
crop = f"CR{offset},{width},{height}"
|
||||
al = "AL" # not sure what this is, doesn't seem to do much but they use it.
|
||||
|
||||
|
|
@ -102,10 +102,10 @@ class Extracted:
|
|||
genres: List[str]
|
||||
description: str
|
||||
published: date
|
||||
duration_s: int
|
||||
rating_value: float
|
||||
rating_count: int
|
||||
creators: List[str]
|
||||
duration_s: Optional[int] = None
|
||||
rating_value: Optional[float] = None
|
||||
rating_count: Optional[int] = None
|
||||
|
||||
|
||||
async def extractor(info):
|
||||
|
|
@ -120,8 +120,10 @@ async def extractor(info):
|
|||
return
|
||||
|
||||
ld = json.loads(parser.value)
|
||||
assert ld["@context"] == "http://schema.org" and ld["@type"] == "Movie"
|
||||
assert ld["aggregateRating"]["@type"] == "AggregateRating"
|
||||
assert ld["@context"] == "http://schema.org" and ld["@type"] in (
|
||||
"Movie",
|
||||
"CreativeWork",
|
||||
)
|
||||
|
||||
creators = []
|
||||
for k in "director", "creator":
|
||||
|
|
@ -136,12 +138,17 @@ async def extractor(info):
|
|||
genres=ld["genre"],
|
||||
description=ld["description"],
|
||||
published=date.fromisoformat(ld["datePublished"]),
|
||||
duration_s=parse_period(ld["duration"]),
|
||||
rating_value=float(ld["aggregateRating"]["ratingValue"]),
|
||||
rating_count=ld["aggregateRating"]["ratingCount"],
|
||||
creators=creators,
|
||||
)
|
||||
|
||||
if "duration" in ld:
|
||||
info.extracted.duration_s = parse_period(ld["duration"])
|
||||
|
||||
if "aggregateRating" in ld:
|
||||
assert ld["aggregateRating"]["@type"] == "AggregateRating"
|
||||
info.extracted.rating_value = float(ld["aggregateRating"]["ratingValue"])
|
||||
info.extracted.rating_count = ld["aggregateRating"]["ratingCount"]
|
||||
|
||||
|
||||
async def handle(message, url, info):
|
||||
ex = clone(info.extracted)
|
||||
|
|
@ -165,10 +172,12 @@ async def handle(message, url, info):
|
|||
|
||||
details = [
|
||||
f"🖋 {' ∕ '.join(ex.creators[:2])}",
|
||||
f"⏱ {pretty_duration(ex.duration_s)}",
|
||||
f"⭐️ {ex.rating_value:_.01f} ⁄ 10 (👤 {ex.rating_count})",
|
||||
f"🏷 {' ∕ '.join(ex.genres)}",
|
||||
]
|
||||
if ex.duration_s:
|
||||
details.append(f"⏱ {pretty_duration(ex.duration_s)}")
|
||||
if ex.rating_count:
|
||||
details.append(f"⭐️ {ex.rating_value:_.01f} ⁄ 10 (👤 {ex.rating_count})")
|
||||
details.append(f"🏷 {' ∕ '.join(ex.genres[:3])}")
|
||||
lines = [
|
||||
f"<b>{ex.title}</b> (<b>{ex.published:%Y}</b>)",
|
||||
f"{', '.join(details)}",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue