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.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576module UI.Services.State exposing (..)
import Browser.Navigation as Navimport Commonimport Httpimport LastFmimport Notificationsimport Return exposing (andThen, return)import String.Ext as Stringimport UI.Common.State exposing (showNotification)import UI.Types exposing (Manager, Msg(..))import UI.User.State.Export as Userimport Url
-- 🔱
connectLastFm : ManagerconnectLastFm model = model.url |> Common.urlOrigin |> String.addSuffix "?action=authenticate/lastfm" |> Url.percentEncode |> String.append "&cb=" |> String.append (String.append "http://www.last.fm/api/auth/?api_key=" LastFm.apiKey ) |> Nav.load |> return model
disconnectLastFm : ManagerdisconnectLastFm model = User.saveSettings { model | lastFm = LastFm.disconnect model.lastFm }
gotLastFmSession : Result Http.Error String -> ManagergotLastFmSession result model = case result of Err _ -> showNotification (Notifications.stickyError "Could not connect with Last.fm") { model | lastFm = LastFm.failedToAuthenticate model.lastFm }
Ok sessionKey -> { model | lastFm = LastFm.gotSessionKey sessionKey model.lastFm } |> showNotification (Notifications.success "Connected successfully with Last.fm") |> andThen User.saveSettings
scrobble : { duration : Int, timestamp : Int, trackId : String } -> Managerscrobble { duration, timestamp, trackId } model = case Maybe.map (.item >> .identifiedTrack) model.nowPlaying of Just ( _, track ) -> if trackId == track.id then ( model , LastFm.scrobble model.lastFm { duration = duration , msg = Bypass , timestamp = timestamp , track = track } )
else Return.singleton model
Nothing -> Return.singleton model