@@ -52,18 +52,34 @@ let parseInput (json: string) : Result<Inputs.Config, string> =
5252
5353
5454let mergeSpotifyImages ( spotify : Outputs.Audiobook list ) otherProvider ( other : Outputs.Audiobook list ) : Result < Outputs.Audiobook list , string list > =
55- other
56- |> List.map ( fun book ->
55+
56+ let tryMatchRegular ( book : Outputs.Audiobook ) : Result < Outputs.Audiobook , string > =
5757 let s = spotify |> List.tryFind ( fun sb -> String.Equals( sb.Id, book.Id, StringComparison.InvariantCultureIgnoreCase))
5858 match s with
5959 | Some spotifyBook -> Ok { book with Images = spotifyBook.Images }
6060 | None ->
6161 // Use the fallback image given by DieDreiMetadaten (which is usually huge!)
6262 if book.Images.IsEmpty then
63- Error $" Could not find matching audiobook in Spotify data for %s {book.Name} (%s {book.Id}) (Provider: %s {otherProvider})"
64- else Ok book)
63+ Error $" Could not find matching regular audiobook in Spotify data for %s {book.Name} (%s {book.Id}) (Provider: %s {otherProvider})"
64+ else Ok book
65+
66+ let tryMatchSpecial ( book : Outputs.Audiobook ) : Result < Outputs.Audiobook , string > =
67+ let bookName = book.Name.ToLowerInvariant()
68+ match spotify |> List.tryFind _. Name.ToLowerInvariant() .Contains( bookName) with
69+ | Some spotifyBook -> Ok { book with Images = spotifyBook.Images }
70+ | None ->
71+ // Use the fallback image given by DieDreiMetadaten (which is usually huge!)
72+ if book.Images.IsEmpty then
73+ Error $" Could not find matching special audiobook in Spotify data for %s {book.Name} (%s {book.Id}) (Provider: %s {otherProvider})"
74+ else Ok book
75+
76+ other
77+ |> List.map ( fun book ->
78+ book
79+ |> tryMatchRegular
80+ |> Result.orElseWith ( fun _ -> book |> tryMatchSpecial))
6581 |> List.sequenceResultA
66-
82+
6783
6884let mergeSpotifyImagesIntoDreiMetadatenStep ( spotify : Outputs.Output ) ( otherOutput : Outputs.Output ) : Result < Outputs.Output , string list > =
6985 let findMatchingSpotifyBooks ( artist : Outputs.ArtistInfo ) =
0 commit comments