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
- Variables
- func BlowfishKey(trackID string) []byte
- func DecryptBytes(trackID string, data []byte) ([]byte, error)
- func DownloadTrack(plan *StreamPlan, w io.Writer) error
- func DownloadTrackContext(ctx context.Context, plan *StreamPlan, w io.Writer) error
- func FormatLabel(raw string) string
- func TrackIDOf(uri string) string
- func Unwrap(cl *Client) *internaldeezer.Client
- type Account
- type Album
- type Artist
- type ArtistInfo
- type ArtistPage
- type Chart
- type Client
- func (cl *Client) Account() Account
- func (cl *Client) AddFavoriteTrack(trackID string) error
- func (cl *Client) AddToPlaylist(playlistID, trackID string) error
- func (cl *Client) AlbumTracks(id string) ([]Track, error)
- func (cl *Client) ArtistProfile(id string) (*ArtistPage, error)
- func (cl *Client) ArtistTop(id string) ([]Track, error)
- func (cl *Client) Charts(genreID string) (*Chart, error)
- func (cl *Client) CreatePlaylist(title string, trackIDs []string) (string, error)
- func (cl *Client) DeletePlaylist(playlistID string) error
- func (cl *Client) EpisodeMeta(id string) (Episode, error)
- func (cl *Client) Favorites() ([]Track, error)
- func (cl *Client) Flow() ([]Track, error)
- func (cl *Client) LoggedIn() bool
- func (cl *Client) Login() error
- func (cl *Client) Lyrics(trackID string) (*Lyrics, error)
- func (cl *Client) PlaylistTracks(id string) ([]Track, error)
- func (cl *Client) Playlists() ([]Playlist, error)
- func (cl *Client) PodcastEpisodeStream(episodeID string) (*StreamPlan, error)
- func (cl *Client) PodcastEpisodes(podcastID string) ([]Episode, error)
- func (cl *Client) PrepareStream(trackID string) (*StreamPlan, error)
- func (cl *Client) Quality() int
- func (cl *Client) RemoveFavoriteTrack(trackID string) error
- func (cl *Client) RemoveFromPlaylist(playlistID, trackID string) error
- func (cl *Client) RenamePlaylist(playlistID, title string) error
- func (cl *Client) Search(query string) (*SearchResults, error)
- func (cl *Client) SearchPodcasts(query string) ([]Podcast, error)
- func (cl *Client) SetQuality(q int)
- func (cl *Client) Track(id string) (Track, error)
- func (cl *Client) UserID() string
- type Episode
- type LyricLine
- type Lyrics
- type Playlist
- type Podcast
- type SearchResults
- type StreamPlan
- type StripeDecryptor
- type Track
Constants ¶
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 ¶
var ErrARLExpired = internaldeezer.ErrARLExpired
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.
var ErrNoNetwork = internaldeezer.ErrNoNetwork
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 ¶
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 ¶
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
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 ¶
FormatLabel converts a raw Deezer format string (e.g. "MP3_320") to a human label (e.g. "MP3 · 320 kbps").
func TrackIDOf ¶
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 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 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 ¶
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) AddFavoriteTrack ¶
AddFavoriteTrack likes a track (adds it to Liked Songs). Requires login and a Premium account.
func (*Client) AddToPlaylist ¶
AddToPlaylist appends a track to a playlist the logged-in user can edit.
func (*Client) AlbumTracks ¶
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) Charts ¶
Charts fetches the global or genre top lists. Pass genreID "0" for the global chart (public, no login required).
func (*Client) CreatePlaylist ¶
CreatePlaylist creates a new playlist (optionally seeded with tracks) and returns its id.
func (*Client) DeletePlaylist ¶
DeletePlaylist deletes a playlist the user owns.
func (*Client) EpisodeMeta ¶
EpisodeMeta fetches a single episode's metadata by id (public).
func (*Client) Flow ¶
Flow returns Deezer's personalised radio (requires login and a Premium account).
func (*Client) Login ¶
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 ¶
Lyrics fetches a track's plain-text lyrics and, when Deezer provides them, time-synced lines (requires login).
func (*Client) PlaylistTracks ¶
PlaylistTracks lists the tracks in a playlist by id. Works for private playlists the logged-in user owns (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 ¶
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) RemoveFavoriteTrack ¶
RemoveFavoriteTrack unlikes a track. Requires login.
func (*Client) RemoveFromPlaylist ¶
RemoveFromPlaylist removes a track from a playlist the user owns.
func (*Client) RenamePlaylist ¶
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 ¶
SearchPodcasts finds shows by keyword (public).
func (*Client) SetQuality ¶
SetQuality selects the preferred stream quality: QualityNormal, QualityHigh, or QualityLossless. Deezer falls back to the highest quality the account and track are entitled to.
type Episode ¶
type Episode = internaldeezer.Episode
Episode is one podcast episode. Episodes stream as unencrypted MP3.
type Lyrics ¶
type Lyrics = internaldeezer.Lyrics
Lyrics holds a track's plain text plus optional time-synced lines.
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.