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