Fix externalids error with null

This commit is contained in:
Zoe Roux 2023-12-05 22:24:12 +01:00
parent 7dab3fd094
commit 4f7c449ea7
4 changed files with 31 additions and 21 deletions

View File

@ -41,7 +41,7 @@ namespace Kyoo.Abstractions.Models
);
/// <inheritdoc />
public Guid Id { get; set; } = Guid.Empty;
public Guid Id { get; set; }
/// <inheritdoc />
[Computed]

View File

@ -20,18 +20,22 @@
import { z } from "zod";
export const MetadataP = z.record(
z.object({
/*
* The ID of the resource on the external provider.
*/
dataId: z.string(),
export const MetadataP = z.preprocess(
(x) =>
typeof x === "object" && x ? Object.fromEntries(Object.entries(x).filter(([_, v]) => v)) : x,
z.record(
z.object({
/*
* The ID of the resource on the external provider.
*/
dataId: z.string(),
/*
* The URL of the resource on the external provider.
*/
link: z.string().nullable(),
}),
/*
* The URL of the resource on the external provider.
*/
link: z.string().nullable(),
}),
),
);
export type Metadata = z.infer<typeof MetadataP>;

View File

@ -257,16 +257,22 @@ class TheMovieDatabase(Provider):
self.name: MetadataID(
show["id"], f"https://www.themoviedb.org/tv/{show['id']}"
),
"imdb": MetadataID(
show["external_ids"]["imdb_id"],
f"https://www.imdb.com/title/{show['external_ids']['imdb_id']}",
)
}
| (
{
"imdb": MetadataID(
show["external_ids"]["imdb_id"],
f"https://www.imdb.com/title/{show['external_ids']['imdb_id']}",
)
}
if show["external_ids"]["imdb_id"]
else None,
"tvdb": MetadataID(show["external_ids"]["tvdb_id"], link=None)
else {}
)
| (
{"tvdb": MetadataID(show["external_ids"]["tvdb_id"], link=None)}
if show["external_ids"]["tvdb_id"]
else None,
},
else {}
),
seasons=[
self.to_season(x, language=lng, show_id=show["id"])
for x in show["seasons"]

View File

@ -43,7 +43,7 @@ class Show:
seasons: list[Season]
# TODO: handle staff
# staff: list[Staff]
external_id: dict[str, MetadataID | None]
external_id: dict[str, MetadataID]
translations: dict[str, ShowTranslation] = field(default_factory=dict)