Skip to content

Commit 1309144

Browse files
committed
Fix mismatches while merging Spotify image data into Deezer
1 parent 00c1bc5 commit 1309144

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

src/data_retriever/Program.fs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,34 @@ let parseInput (json: string) : Result<Inputs.Config, string> =
5252

5353

5454
let 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

6884
let mergeSpotifyImagesIntoDreiMetadatenStep (spotify: Outputs.Output) (otherOutput: Outputs.Output) : Result<Outputs.Output, string list> =
6985
let findMatchingSpotifyBooks (artist: Outputs.ArtistInfo) =

0 commit comments

Comments
 (0)