1module Playlists.Matching exposing (match)
2
3import Playlists exposing (..)
4import Tracks exposing (IdentifiedTrack)
5
6
7
8-- 🔱
9
10
11match : Playlist -> List IdentifiedTrack -> ( List IdentifiedTrack, List IdentifiedPlaylistTrack )
12match playlist =
13 List.foldl
14 (\( i, t ) ( identifiedTracks, remainingPlaylistTracks ) ->
15 let
16 im =
17 { album = t.tags.album
18 , artist = t.tags.artist
19 , title = t.tags.title
20 }
21
22 ( matches, remainingPlaylistTracksWithoutMatches ) =
23 List.foldl
24 (\( pi, pt ) ->
25 if im.title == pt.title && im.album == pt.album && im.artist == pt.artist then
26 Tuple.mapBoth
27 ((::) ( playlistTrackIdentifiers i pi, t ))
28 identity
29
30 else
31 Tuple.mapBoth
32 identity
33 ((::) ( pi, pt ))
34 )
35 ( [], [] )
36 remainingPlaylistTracks
37 in
38 ( identifiedTracks ++ matches
39 , remainingPlaylistTracksWithoutMatches
40 )
41 )
42 ( []
43 , List.indexedMap (\idx -> Tuple.pair { index = idx }) playlist.tracks
44 )
45
46
47
48-- ㊙️
49
50
51playlistTrackIdentifiers : Tracks.Identifiers -> Playlists.Identifiers -> Tracks.Identifiers
52playlistTrackIdentifiers i pi =
53 { i | indexInPlaylist = Just pi.index }