Something went wrong. Try again.
A music player that connects to your cloud/distributed storage. forked from tokono.ma/diffuse
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149module Tracks.Collection.Internal.Harvest exposing (harvest)
import Dictimport List.Extra as Listimport Maybe.Extra as Maybeimport Tracks exposing (..)
-- 🍯
harvest : Parcel -> Parcelharvest ( deps, collection ) = let harvested = case deps.searchResults of Just [] -> []
Just trackIds -> collection.arranged |> List.foldl harvester ( [], trackIds ) |> Tuple.first
Nothing -> collection.arranged
filters = [ -- Favourites / Missing ----------------------- if deps.favouritesOnly then Tuple.first >> .isFavourite >> (==) True
else if Maybe.map .autoGenerated deps.selectedPlaylist == Just Nothing then always True
else Tuple.first >> .isMissing >> (==) False
-- Playlist ----------- , case deps.selectedPlaylist of Just playlist -> case playlist.autoGenerated of Just _ -> \( _, t ) -> Tracks.matchesAutoGeneratedPlaylist playlist t
Nothing -> \( i, _ ) -> Maybe.isJust i.indexInPlaylist
Nothing -> always True
-- Cached --------- , if deps.cachedOnly then \( _, t ) -> List.member t.id deps.cached
else always True ]
theFilter x = List.foldl (\filter bool -> if True == bool then filter x
else bool ) True filters in harvested |> List.foldl (\( i, t ) ( dict, ( idx, prevIdentifiers ), acc ) -> let -- Identifier used to distinguish duplicates s = case t.tags.artist of Just artist -> String.toLower (artist ++ t.tags.title)
Nothing -> String.toLower t.tags.title in if theFilter ( i, t ) == False then ( dict, ( idx, prevIdentifiers ), acc )
else if deps.hideDuplicates && Dict.member s dict then ( dict, ( idx, prevIdentifiers ), acc )
else let prevGroup = Maybe.unwrap "" .name prevIdentifiers.group
newIdentifiers = { i | group = Maybe.map (\g -> { g | firstInGroup = prevGroup /= g.name }) i.group , indexInList = idx } in ( if deps.hideDuplicates then Dict.insert s () dict
else dict -- , ( idx + 1, newIdentifiers ) , ( newIdentifiers, t ) :: acc ) ) ( Dict.empty, ( 0, Tracks.emptyIdentifiers ), [] ) |> (\( _, _, c ) -> c) |> (\h -> { collection | harvested = List.reverse h }) |> (\c -> ( deps, c ))
-- 🛠
harvester : IdentifiedTrack -> ( List IdentifiedTrack, List String ) -> ( List IdentifiedTrack, List String )harvester ( i, t ) ( acc, trackIds ) = case List.findIndex ((==) t.id) trackIds of Just idx -> ( acc ++ [ ( i, t ) ] , List.removeAt idx trackIds )
Nothing -> ( acc , trackIds )