odmobile

package
v3.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package odmobile is the OpenDeezer engine exposed for gomobile (gobind), so a native Android (or iOS) app can drive the same login/decrypt/decode/playback pipeline the desktop GUIs use. Build it with:

gomobile bind -target=android -androidapi 24 -o gui/android/app/libs/odmobile.aar ./mobile

Every browse/list call returns a JSON string (the wire shape the GUIs already use); mutations return bool/string. The caller polls FinishedCount to drive auto-advance, mirroring the C-archive frontends.

Index

Constants

View Source
const Version = version.Number

Version is the engine/app version (single source: internal/version).

Variables

This section is empty.

Functions

func Account

func Account() string

func AddFavorite

func AddFavorite(id string) bool

func AddToPlaylist

func AddToPlaylist(playlistID, trackID string) bool

func AdsDisabled

func AdsDisabled() bool

AdsDisabled reports whether the free-tier ads/play-reporting opt-out is on.

func AlbumTracks

func AlbumTracks(id string) string

func ArtistMixJSON

func ArtistMixJSON(id string) string

ArtistMixJSON returns an "artist radio" mix seeded from an artist: {tracks:[...]} in the shared wire shape, mirroring Flow.

func ArtistProfile

func ArtistProfile(id string) string

func ArtistTop

func ArtistTop(id string) string

func CancelSleepTimer

func CancelSleepTimer()

CancelSleepTimer disarms the sleep timer.

func Charts

func Charts() string

func CheckUpdate

func CheckUpdate() string

CheckUpdate checks GitHub for a newer release; returns JSON {current, latest, hasUpdate, url, notes}.

func ClearPreload

func ClearPreload()

ClearPreload discards a preloaded next track. Call when the upcoming track is no longer determined (shuffle/repeat toggled, queue edited after a preload was armed) so a stale preload can't be gaplessly swapped in.

func ConnectDevice

func ConnectDevice(addr string) bool

ConnectDevice routes playback to the device at addr (host:port). Stops local playback (audio moves to the device). Returns true on success.

func ConnectHostInfo

func ConnectHostInfo() string

ConnectHostInfo returns a JSON string: {"enabled":bool,"addr":"<lanip>:<port>","port":<int>,"name":"<account>"}. addr/name are empty when the Connect host is disabled.

func ConnectHostSetEnabled

func ConnectHostSetEnabled(on int)

ConnectHostSetEnabled makes this device a discoverable OpenDeezer Connect target on the LAN (on!=0), so other devices signed into the same Deezer account can find it in their device picker and drive its playback; or stops advertising it (on==0). The control server runs on a LAN address with same-account auth. Idempotent.

func ConnectedDevice

func ConnectedDevice() string

ConnectedDevice returns the connected device address ("" if local).

func CreatePlaylist

func CreatePlaylist(title string) string

func CrossfadeMS

func CrossfadeMS() int

func DeletePlaylist

func DeletePlaylist(id string) bool

func DisconnectDevice

func DisconnectDevice()

DisconnectDevice returns control to local playback. Stops the remote device (so it doesn't keep playing unattended) before clearing the connection.

func DiscoverDevices

func DiscoverDevices(timeoutMS int) string

DiscoverDevices returns LAN + configured Connect devices as a JSON array.

func DownloadAlbum

func DownloadAlbum(id string) string

DownloadAlbum downloads every track of albumID to the shared download folder (DownloadDir) and returns the batch summary {"saved":N,"failed":N,"dir":"...","error":""}. Blocking and premium-only, the same gate + folder DownloadTrack uses — call it off the UI thread. On a partial download "failed" counts the per-track failures and "error" carries the batch message; a free account yields saved:0,failed:0 with the premium error.

func DownloadDir

func DownloadDir() string

DownloadDir returns the current download folder (env/config/default).

func DownloadForOffline

func DownloadForOffline(id string) string

DownloadForOffline fetches the raw ciphertext for id into the media cache (if not already present) and ensures the plan meta is stored via PutMeta so subsequent plays can use PrepareStreamCached with zero network (cache-only plan). Returns JSON status {"status":"...","key":"...","trackID":"..."} or {"error":"..."}. When plan.CDNURL=="" (meta hit) it checks for the body and short-circuits cleanly without network if present; otherwise forces a resolve to obtain a URL for the body fetch. Call off the UI thread. Requires cache enabled (MediaCacheMB>0) at startup.

func DownloadPlaylist

func DownloadPlaylist(id string) string

DownloadPlaylist downloads every track of playlistID to the shared download folder and returns the same batch summary as DownloadAlbum.

func DownloadTrack

func DownloadTrack(trackID, destDir string) string

DownloadTrack downloads trackID to a file in destDir and returns JSON {"path":"..."} on success or {"error":"..."} on failure. Pass "" for destDir to use the shared default folder (DownloadDir). Blocking — call it off the UI thread. Downloads are premium-only; a free account gets an error.

func DurationMS

func DurationMS() int64

func EQJSON

func EQJSON() string

EQJSON returns the equalizer state: {enabled,mono,preampDb,gainsDb:[10],preset,bands:[10],presets:[...]}. Same wire shape as corelib's DZEQJSON so every client renders the same UI.

func FavoriteIDsJSON

func FavoriteIDsJSON() string

FavoriteIDsJSON returns the account's liked (favorite) track ids as a JSON array of strings, e.g. ["123","456"]. It reuses the same c.Favorites() the library view fetches, so the app can render truthful "liked" hearts across lists without a per-track lookup. Returns "[]" when not logged in or on a fetch error.

func Favorites

func Favorites() string

func Fetch

func Fetch(url string) []byte

Fetch downloads raw bytes (e.g. cover art) using a browser User-Agent.

func FinishedCount

func FinishedCount() int

func Flow

func Flow() string

func Format

func Format() string

func Gapless

func Gapless() bool

func GetRepeat

func GetRepeat() string

GetRepeat returns the current repeat mode ("off"|"all"|"one"). When routed to a Connect device it returns the remote host's mode (the routed snapshot), so the app renders the host's real mode while casting; otherwise it returns the engine queue's mode.

func GetShuffle

func GetShuffle() bool

GetShuffle reports whether shuffle is on. When routed to a Connect device it returns the remote host's flag (the routed snapshot), so the app renders the host's real mode while casting; otherwise the engine queue's flag.

func HistoryRecentJSON

func HistoryRecentJSON(n int) string

HistoryRecentJSON returns the newest n entries of the machine-local listening history as a JSON array (newest first, the same stable shape the control API's /history/recent serves); n <= 0 returns all. Empty/unavailable history yields "[]".

Each entry is {trackId,title,artist,album?,kind?,startedAt,durationPlayedSec}. "kind" is omitted or "track" for a song and "episode" for a podcast episode — an app routes replay on it: episode -> PlayEpisodeMS(trackId), else PlayTrackMS.

func HistoryStatsJSON

func HistoryStatsJSON(sinceDays int) string

HistoryStatsJSON returns local listening stats over the last sinceDays (sinceDays <= 0 = all history) as {topTracks:[{trackId,title,artist,plays,totalSec}],

topArtists:[{artist,plays,totalSec}], totalSeconds:N}. Empty/unavailable

history yields the same shape with empty arrays and totalSeconds:0. topTracks and topArtists are music-only (podcast episodes excluded); totalSeconds counts all listening time.

func Home

func Home() string

Home aggregates the Home-screen sections (charts top tracks/albums + the user's playlists) in one call, mirroring corelib DZHomeJSON. Best-effort.

func Init

func Init(arl string) bool

Init logs in with the ARL and starts the engine. Returns true on success.

func IsPreview

func IsPreview() bool

IsPreview reports whether the current track is Deezer's 30-second preview (the free-account fallback) rather than the full stream.

func LoggedIn

func LoggedIn() bool

LoggedIn reports whether Init succeeded.

func LoginErrorKind

func LoginErrorKind() int

LoginErrorKind returns why the most recent Init failed so the UI shows a No-Internet retry screen instead of forcing re-auth: 0 = ok, 1 = ARL expired or invalid, 2 = no internet, 3 = other.

func Logout

func Logout()

Logout tears the engine session down: stops playback, closes the control server (dropping web-remote pairing sessions and the old account's same-account auth), stops Connect-host advertising, and forgets the Deezer client. A later Init starts services fresh for the new account.

func Lyrics

func Lyrics(id string) string

func MediaCacheMB

func MediaCacheMB() int

MediaCacheMB returns the on-disk raw-stream cache budget in megabytes (media.json; 0 = cache disabled, the default).

func NowPlaying

func NowPlaying() string

NowPlaying returns the track actually playing (remote when routed, else local).

func Pause

func Pause()

func Play

func Play(trackID string, durationMS int64) bool

Play resolves + plays a track. When routed to a Connect device, it plays there.

func PlayEpisode

func PlayEpisode(id string) bool

PlayEpisode resolves + plays a podcast episode (plain stream) with an unknown duration. Prefer PlayEpisodeMS when the caller knows the duration.

func PlayEpisodeMS

func PlayEpisodeMS(id string, durationMS int64) bool

PlayEpisodeMS resolves + plays a podcast episode (plain stream). Sets the episode as the current track immediately (id + duration, mirroring corelib DZPlayEpisode — the player never derives duration from the stream), then asynchronously enriches title / podcast name / artwork via REST /episode.

func PlaylistTracks

func PlaylistTracks(id string) string

func Playlists

func Playlists() string

func PodcastEpisodes

func PodcastEpisodes(id string) string

func PositionMS

func PositionMS() int64

func Preload

func Preload(id string) error

Preload resolves trackID's stream (exactly like Play does) and arms the player's preload, so the transition after the current track ends is gapless / crossfaded instead of a full network re-resolve at track end. No-op when both gapless and crossfade are off, or when routed to a Connect device. Blocking (network round-trip) — call it off the UI thread. The track duration is taken from the synced queue (SetQueueJSON) when present, else fetched best-effort.

func Quality

func Quality() int

func QueueIndex

func QueueIndex() int

QueueIndex returns the engine queue's cursor (-1 when empty/unsynced), so the app can resync its own cursor after an engine-driven advance (remote /next|/prev, gapless promote).

func QueueInsertNext

func QueueInsertNext(trackJSON string)

QueueInsertNext inserts the track described by trackJSON (wire shape, same as SetQueueJSON payload; accepts either a single object or a 1-element array) immediately after the current row (or at start if empty). Bumps version.

func QueueJSON

func QueueJSON() string

QueueJSON returns the engine queue as {"version":N,"index":I,"tracks":[..]} (tracks in the shared wire shape), so the app can adopt remote queue edits.

func QueueMove

func QueueMove(from, to int)

QueueMove reorders the engine queue (from -> to). Cursor/history follow. from==to and out-of-range are no-ops.

func QueueRemove

func QueueRemove(index int)

QueueRemove removes the track at index from the engine queue (if valid and not the playing row). It is the direct export for mobile queue UIs to mutate engineQ (bumping version) so remote controllers see consistent state.

func QueueVersion

func QueueVersion() int64

QueueVersion returns a counter bumped on every engine-queue CONTENT change (SetQueueJSON, remote /queue/add|remove|move, /play/album, /play/mix/{track,artist}) — cursor moves don't bump it. The app polls this cheaply and pulls QueueJSON only when a remote controller actually edited the queue.

func RemoveFavorite

func RemoveFavorite(id string) bool

func RemoveFromPlaylist

func RemoveFromPlaylist(playlistID, trackID string) bool

func RenamePlaylist

func RenamePlaylist(id, title string) bool

func ReplayGain

func ReplayGain() bool

func Resume

func Resume()
func Search(q string) string

func SearchPodcasts

func SearchPodcasts(q string) string

func Seek

func Seek(ms int64)

func SetAdsDisabled

func SetAdsDisabled(disabled bool) bool

SetAdsDisabled turns Deezer Free's play-reporting/ads off/on and persists it. FREE accounts only: reporting plays (log.listen) credits artists and drives the ad schedule; disabling it is ad-free but stops reporting — the user's at-own-risk choice. Paid accounts are unaffected.

func SetClientInfo

func SetClientInfo(clientName, device string)

SetClientInfo overrides the advertised client id + device label (before Init).

func SetCrossfadeMS

func SetCrossfadeMS(ms int)

func SetDownloadDir

func SetDownloadDir(path string) bool

SetDownloadDir persists the download folder ("" resets to the default).

func SetEQJSON

func SetEQJSON(js string) bool

SetEQJSON applies a partial EQ update. Recognized keys (all optional): enabled (bool), mono (bool), preampDb (number), gainsDb ([10]number), preset (string), band ({"index":N,"gainDb":X}). Returns false if any present key failed to apply.

func SetGapless

func SetGapless(on bool)

func SetMediaCacheMB

func SetMediaCacheMB(mb int) bool

SetMediaCacheMB persists the raw-stream cache budget in megabytes (0 or a negative value disables the cache). The cache is attached to the player once at startup, before any playback, so a change takes effect at the next launch.

func SetOutputSuspended

func SetOutputSuspended(on bool)

SetOutputSuspended suspends (true) or resumes (false) the local OS audio device without touching playback state — for audio-focus/route handling on mobile. Local-only: it never routes to a Connect device.

func SetQuality

func SetQuality(level int)

func SetQueueIndex

func SetQueueIndex(i int)

SetQueueIndex aligns the engine queue's cursor to i (clamped; no-op when the queue is empty). Call it whenever the app changes the playing row so the engine queue tracks what is audible. It uses AlignIndex, not SetIndex, so this pure synchronisation records no navigation history (a synthetic entry would make a later remote Prev jump to a never-played track). Genuine remote jumps go through engineQueueSelect (SetIndex), which does record history.

func SetQueueJSON

func SetQueueJSON(js string) error

SetQueueJSON replaces the engine-side playback queue with the app's queue so remote controllers see it on /status and /next + /prev walk it. js is a JSON array of tracks in the same wire shape every list call returns ({id,name,durationMs,artistLine,artistId,artists,albumName,artworkUrl, explicit}); only id is required, but durationMs should be set so controllers' end-of-track detection works. The cursor resets to 0 — follow with SetQueueIndex to point it at the playing row. Pass "[]" to clear. Apps that never call this keep today's behavior exactly (app-owned queue via FinishedCount). Returns an error on a parse failure.

func SetRepeat

func SetRepeat(mode int)

SetRepeat sets the repeat mode (mode: 0=off, 1=all, 2=one). The mode is recorded on the engine-side queue — /status reports it and the engine queue honors it when it advances. It is NOT forwarded to a connected remote device (B2): while casting, the controller keeps repeat local so the host's single- track queue never loops the current track. Read the host's own mode with GetRepeat.

func SetReplayGain

func SetReplayGain(on bool)

func SetShuffle

func SetShuffle(on int)

SetShuffle sets shuffle on (non-zero) or off (0). The flag is always recorded on the engine-side queue — /status reports it and the engine queue honors it when it advances — and it is forwarded to the connected remote device when one is selected.

func SetSleepTimer

func SetSleepTimer(minutes int, endOfTrack int)

SetSleepTimer arms the sleep timer: pause after `minutes` (with a fade-out), or when the current track ends if endOfTrack != 0 (minutes ignored). minutes <= 0 with endOfTrack == 0 cancels it.

func SetVolume

func SetVolume(v float64)

func SleepActive

func SleepActive() int

SleepActive reports whether a sleep timer is armed (1) or not (0).

func SleepEndOfTrack

func SleepEndOfTrack() int

SleepEndOfTrack reports whether the armed timer is end-of-track mode (1/0).

func SleepRemainingMS

func SleepRemainingMS() int64

SleepRemainingMS returns milliseconds until the timer fires (0 if none).

func State

func State() int

func Stop

func Stop()

func TogglePause

func TogglePause()

func TrackMixJSON

func TrackMixJSON(id string) string

TrackMixJSON returns a "song radio" mix seeded from a track (the seed kept as the first entry): {tracks:[...]} in the shared wire shape, mirroring Flow.

func UserID

func UserID() string

func Volume

func Volume() float64

func WebRemoteInfo

func WebRemoteInfo() string

WebRemoteInfo returns a JSON string: {"enabled":bool,"code":"123456","url":"http://<lanip>:<port>/remote","port":<int>}. code and url are empty when the remote is disabled.

func WebRemoteQRPNG

func WebRemoteQRPNG() []byte

WebRemoteQRPNG returns a PNG-encoded QR code for the web remote URL, or nil when the remote is disabled. Free-able by the caller (Go GC manages it).

func WebRemoteSetEnabled

func WebRemoteSetEnabled(on int)

WebRemoteSetEnabled enables (on!=0) or disables (on==0) the web remote. When enabling, the control server is started on a LAN-reachable address if it is not already, and pairing is activated so a phone can scan the QR and connect.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL