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 /> /// <inheritdoc />
public Guid Id { get; set; } = Guid.Empty; public Guid Id { get; set; }
/// <inheritdoc /> /// <inheritdoc />
[Computed] [Computed]

View File

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

View File

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

View File

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