deezer

package
v1.8.3 Latest Latest
Warning

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

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

Documentation

Overview

Package deezer is the OpenDeezer SDK's Deezer API layer: account login via ARL, browse (favorites, playlists, albums, search, charts, Flow, artists, lyrics, podcasts), library write operations (like/unlike, playlist CRUD), stream resolution, and Blowfish BF_CBC_STRIPE decryption.

Authenticate

client := deezer.New(os.Getenv("DEEZER_ARL"))
if err := client.Login(); err != nil {
    log.Fatal(err) // errors.Is(err, deezer.ErrARLExpired) → re-auth needed
}

Browse

tracks, _ := client.Favorites()
results, _ := client.Search("Radiohead")
charts, _  := client.Charts("0")   // "0" = global chart

Download / decrypt a track

plan, _ := client.PrepareStream(trackID)
f, _    := os.Create("track." + strings.ToLower(plan.Format))
defer f.Close()
deezer.DownloadTrack(plan, f)

Decrypt an in-memory buffer

plainBytes, err := deezer.DecryptBytes(trackID, encryptedBytes)

Index

Constants

View Source
const (
	// QualityNormal selects MP3 at 128 kbps.
	QualityNormal = internaldeezer.QualityNormal
	// QualityHigh selects MP3 at 320 kbps (requires a Premium account).
	QualityHigh = internaldeezer.QualityHigh
	// QualityLossless selects FLAC (requires a HiFi account); falls back to
	// MP3 320 → 128 when the account or track is not entitled.
	QualityLossless = internaldeezer.QualityLossless
)

Variables

ErrARLExpired is returned by Login when the ARL cookie is missing, expired or otherwise rejected. Use errors.Is to detect it and prompt the user to re-authenticate.

ErrNoNetwork wraps any transport-level failure reaching Deezer (DNS, refused, unreachable, timeout). Use errors.Is to detect it and show a "No Internet" retry screen instead of mistaking an outage for an expired ARL.

Functions

func BlowfishKey

func BlowfishKey(trackID string) []byte

BlowfishKey derives the per-track Blowfish key used for BF_CBC_STRIPE decryption. The key is a 16-byte XOR of the MD5 hex of trackID and a fixed secret. Most callers should use DownloadTrack or DecryptBytes instead.

func DecryptBytes

func DecryptBytes(trackID string, data []byte) ([]byte, error)

DecryptBytes decrypts a complete in-memory BF_CBC_STRIPE buffer for the given track id. Use DownloadTrack for streaming decryption to a writer.

func DownloadTrack

func DownloadTrack(plan *StreamPlan, w io.Writer) error

DownloadTrack fetches and decrypts a Deezer track to w. plan must come from Client.PrepareStream (for tracks) or Client.PodcastEpisodeStream (for podcast episodes, which are not encrypted).

The bytes written form a valid MP3 or FLAC file and can be piped directly to a decoder or saved to disk.

plan, err := client.PrepareStream("3135556")
if err != nil { log.Fatal(err) }
f, _ := os.Create("track." + strings.ToLower(plan.Format))
defer f.Close()
if err := deezer.DownloadTrack(plan, f); err != nil { log.Fatal(err) }

DownloadTrack cannot be cancelled once started; use DownloadTrackContext to abort a download or bound its total duration.

func DownloadTrackContext added in v1.7.0

func DownloadTrackContext(ctx context.Context, plan *StreamPlan, w io.Writer) error

DownloadTrackContext is DownloadTrack with cancellation. Cancelling ctx aborts the in-flight CDN read and unblocks the copy, so callers can implement a "cancel download" action or a per-download deadline.

func FormatLabel

func FormatLabel(raw string) string

FormatLabel converts a raw Deezer format string (e.g. "MP3_320") to a human label (e.g. "MP3 · 320 kbps").

func TrackIDOf

func TrackIDOf(uri string) string

TrackIDOf extracts the numeric Deezer track id from a URI ("deezer:track:123"), a URL, or a bare numeric string. Any query string or fragment is ignored, so share links carrying utm_* params (including utm_content=track-<id>, whose digits would otherwise be concatenated onto the id) resolve correctly. Trailing slashes are tolerated, and negative ids (user-upload SNG_IDs) are preserved. Returns "" when no valid id is present.

func Unwrap

func Unwrap(cl *Client) *internaldeezer.Client

Unwrap returns the underlying internal Deezer client. This is used by the sdk/control and sdk/player packages, which live in the same module and can import internal/deezer directly. External callers should not depend on this.

Types

type Account

type Account = internaldeezer.Account

Account summarises the logged-in user's plan and entitlements.

type Album

type Album = internaldeezer.Album

Album is a search/browse result.

type Artist

type Artist = internaldeezer.Artist

Artist is a track/album credit.

type ArtistInfo

type ArtistInfo = internaldeezer.ArtistInfo

ArtistInfo is an artist profile returned by search or browse.

type ArtistPage

type ArtistPage = internaldeezer.ArtistPage

ArtistPage bundles an artist's profile with their top tracks, albums and related artists.

type Chart

type Chart = internaldeezer.Chart

Chart is the global or genre top lists.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client holds an authenticated Deezer session. Create one with New and call Client.Login before issuing any browse or stream request.

Client is safe for concurrent use.

func New

func New(arl string) *Client

New creates a Client for the given ARL (Audio Reference Link). The ARL is the long-lived Deezer authentication cookie; obtain it from your browser's cookie store at deezer.com. Login is not called yet.

func (*Client) Account

func (cl *Client) Account() Account

Account returns the logged-in user's plan and streaming entitlements.

func (*Client) AddFavoriteTrack

func (cl *Client) AddFavoriteTrack(trackID string) error

AddFavoriteTrack likes a track (adds it to Liked Songs). Requires login and a Premium account.

func (*Client) AddToPlaylist

func (cl *Client) AddToPlaylist(playlistID, trackID string) error

AddToPlaylist appends a track to a playlist the logged-in user can edit.

func (*Client) AlbumTracks

func (cl *Client) AlbumTracks(id string) ([]Track, error)

AlbumTracks lists an album's tracks by id (public, no login required).

func (*Client) ArtistProfile

func (cl *Client) ArtistProfile(id string) (*ArtistPage, error)

ArtistProfile fetches an artist's full profile: biography, top tracks, albums, and related artists (public).

func (*Client) ArtistTop

func (cl *Client) ArtistTop(id string) ([]Track, error)

ArtistTop lists an artist's most popular tracks (public).

func (*Client) Charts

func (cl *Client) Charts(genreID string) (*Chart, error)

Charts fetches the global or genre top lists. Pass genreID "0" for the global chart (public, no login required).

func (*Client) CreatePlaylist

func (cl *Client) CreatePlaylist(title string, trackIDs []string) (string, error)

CreatePlaylist creates a new playlist (optionally seeded with tracks) and returns its id.

func (*Client) DeletePlaylist

func (cl *Client) DeletePlaylist(playlistID string) error

DeletePlaylist deletes a playlist the user owns.

func (*Client) EpisodeMeta

func (cl *Client) EpisodeMeta(id string) (Episode, error)

EpisodeMeta fetches a single episode's metadata by id (public).

func (*Client) Favorites

func (cl *Client) Favorites() ([]Track, error)

Favorites lists the user's liked songs (requires login).

func (*Client) Flow

func (cl *Client) Flow() ([]Track, error)

Flow returns Deezer's personalised radio (requires login and a Premium account).

func (*Client) LoggedIn

func (cl *Client) LoggedIn() bool

LoggedIn reports whether Login has completed successfully.

func (*Client) Login

func (cl *Client) Login() error

Login authenticates the session and fetches the api_token, license_token, and user identity. It must be called before any browse or stream method. Returns ErrARLExpired when the ARL is rejected by Deezer.

func (*Client) Lyrics

func (cl *Client) Lyrics(trackID string) (*Lyrics, error)

Lyrics fetches a track's plain-text lyrics and, when Deezer provides them, time-synced lines (requires login).

func (*Client) PlaylistTracks

func (cl *Client) PlaylistTracks(id string) ([]Track, error)

PlaylistTracks lists the tracks in a playlist by id. Works for private playlists the logged-in user owns (requires login).

func (*Client) Playlists

func (cl *Client) Playlists() ([]Playlist, error)

Playlists lists the user's own playlists (requires login).

func (*Client) PodcastEpisodeStream

func (cl *Client) PodcastEpisodeStream(episodeID string) (*StreamPlan, error)

PodcastEpisodeStream resolves a podcast episode to an unencrypted StreamPlan (StreamPlan.Encrypted == false). Episodes are plain MP3; no decryption needed.

func (*Client) PodcastEpisodes

func (cl *Client) PodcastEpisodes(podcastID string) ([]Episode, error)

PodcastEpisodes lists a show's episodes by podcast id (public).

func (*Client) PrepareStream

func (cl *Client) PrepareStream(trackID string) (*StreamPlan, error)

PrepareStream resolves a track id to a StreamPlan containing the CDN URL, format, ReplayGain, and an Encrypted flag. Pass the plan to DownloadTrack or sdk/player.Player.Play.

Requires login and a Premium account. Quality falls back automatically when the account is not entitled to the preferred level.

func (*Client) Quality

func (cl *Client) Quality() int

Quality returns the current quality preference (0–2).

func (*Client) RemoveFavoriteTrack

func (cl *Client) RemoveFavoriteTrack(trackID string) error

RemoveFavoriteTrack unlikes a track. Requires login.

func (*Client) RemoveFromPlaylist

func (cl *Client) RemoveFromPlaylist(playlistID, trackID string) error

RemoveFromPlaylist removes a track from a playlist the user owns.

func (*Client) RenamePlaylist

func (cl *Client) RenamePlaylist(playlistID, title string) error

RenamePlaylist changes a playlist's title.

func (*Client) Search

func (cl *Client) Search(query string) (*SearchResults, error)

Search queries tracks, albums, artists and playlists. At least some results are returned for each category. No login required for public search.

func (*Client) SearchPodcasts

func (cl *Client) SearchPodcasts(query string) ([]Podcast, error)

SearchPodcasts finds shows by keyword (public).

func (*Client) SetQuality

func (cl *Client) SetQuality(q int)

SetQuality selects the preferred stream quality: QualityNormal, QualityHigh, or QualityLossless. Deezer falls back to the highest quality the account and track are entitled to.

func (*Client) Track

func (cl *Client) Track(id string) (Track, error)

Track fetches a single track's metadata by id (requires login).

func (*Client) UserID

func (cl *Client) UserID() string

UserID returns the numeric Deezer user id (available after Login).

type Episode

type Episode = internaldeezer.Episode

Episode is one podcast episode. Episodes stream as unencrypted MP3.

type LyricLine

type LyricLine = internaldeezer.LyricLine

LyricLine is one time-synced lyric line.

type Lyrics

type Lyrics = internaldeezer.Lyrics

Lyrics holds a track's plain text plus optional time-synced lines.

type Playlist

type Playlist = internaldeezer.Playlist

Playlist is a search/browse result.

type Podcast

type Podcast = internaldeezer.Podcast

Podcast is a show returned by search.

type SearchResults

type SearchResults = internaldeezer.SearchResults

SearchResults groups tracks, albums, artists and playlists from a query.

type StreamPlan

type StreamPlan = internaldeezer.StreamPlan

StreamPlan is the resolved CDN URL + metadata needed to download and decrypt a track or episode. Obtain one via Client.PrepareStream or Client.PodcastEpisodeStream, then pass it to DownloadTrack or sdk/player.Player.Play.

type StripeDecryptor

type StripeDecryptor = internaldeezer.StripeDecryptor

StripeDecryptor streams Deezer's BF_CBC_STRIPE plaintext from arbitrary input chunks. Use NewStripeDecryptor to obtain one.

func NewStripeDecryptor

func NewStripeDecryptor(trackID string) (*StripeDecryptor, error)

NewStripeDecryptor builds a streaming BF_CBC_STRIPE decryptor keyed for trackID. Feed it arbitrary-sized chunks via StripeDecryptor.Feed; flush the final partial chunk with StripeDecryptor.Finish.

type Track

type Track = internaldeezer.Track

Track is a Deezer track (metadata only).

Jump to

Keyboard shortcuts

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