├── README.md ├── chart_test.go ├── track_test.go ├── comment.go ├── error.go ├── genre_test.go ├── album_test.go ├── playlist_test.go ├── deezer.go ├── LICENSE ├── genre.go ├── chart.go ├── editorial.go ├── search_test.go ├── artist_test.go ├── radio.go ├── user_test.go ├── playlist.go ├── track.go ├── artist.go ├── search.go ├── album.go └── user.go /README.md: -------------------------------------------------------------------------------- 1 | Deezer 2 | ===== 3 | 4 | > Deezer API for GO 5 | -------------------------------------------------------------------------------- /chart_test.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "testing" 7 | ) 8 | 9 | func TestGetCharts(t *testing.T) { 10 | result, err := GetCharts(0, 0) 11 | if err != nil { 12 | t.Fatal(err) 13 | } 14 | json, _ := json.Marshal(result) 15 | fmt.Println(string(json)) 16 | } 17 | -------------------------------------------------------------------------------- /track_test.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "testing" 7 | ) 8 | 9 | func TestGetTrack(t *testing.T) { 10 | result, err := GetArtist(34796791) 11 | if err != nil { 12 | t.Fatal(err) 13 | } 14 | json, _ := json.Marshal(result) 15 | fmt.Println(string(json)) 16 | } 17 | -------------------------------------------------------------------------------- /comment.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import "fmt" 4 | 5 | type Comment struct { 6 | ID int `json:"id,omitempty"` 7 | Text string `json:"text,omitempty"` 8 | Date int `json:"date,omitempty"` 9 | Object Playlist `json:"object,omitempty"` 10 | Author User `json:"author,omitempty"` 11 | } 12 | 13 | type CommentList struct { 14 | Data []Comment `json:"data,omitempty"` 15 | Total int `json:"total,omitempty"` 16 | Next string `json:"next,omitempty"` 17 | } 18 | 19 | func GetComment(id int) (Comment, error) { 20 | path := fmt.Sprintf("comment/%d", id) 21 | result := Comment{} 22 | err := get(path, nil, &result) 23 | return result, err 24 | } 25 | -------------------------------------------------------------------------------- /error.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import "fmt" 4 | 5 | const ( 6 | ERR_QUOTA = 4 7 | ERR_PERMISSION = 200 8 | ERR_TOKEN_INVALID = 300 9 | ERR_PARAMETER = 500 10 | ERR_PARAMETER_MISSING = 501 11 | ERR_QUERY_INVALID = 600 12 | ERR_SERVICE_BUSY = 700 13 | ERR_DATA_NOT_FOUND = 800 14 | ) 15 | 16 | type Error struct { 17 | Type string `json:"type,omitempty"` 18 | Message string `json:"message,omitempty"` 19 | Code int `json:"code,omitempty"` 20 | } 21 | 22 | type ErrorResponse struct { 23 | Error Error `json:"error,omitempty"` 24 | } 25 | 26 | func (e Error) String() string { 27 | return fmt.Sprintf( 28 | "%d: %s - %s", 29 | e.Code, e.Type, e.Message, 30 | ) 31 | } 32 | -------------------------------------------------------------------------------- /genre_test.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "testing" 7 | ) 8 | 9 | func TestGetGenres(t *testing.T) { 10 | result, err := GetGenres() 11 | if err != nil { 12 | t.Fatal(err) 13 | } 14 | json, _ := json.Marshal(result) 15 | fmt.Println(string(json)) 16 | } 17 | 18 | func TestGetGenre(t *testing.T) { 19 | result, err := GetGenre(85) 20 | if err != nil { 21 | t.Fatal(err) 22 | } 23 | json, _ := json.Marshal(result) 24 | fmt.Println(string(json)) 25 | } 26 | 27 | func TestGetGenreArtists(t *testing.T) { 28 | result, err := GetGenreArtists(85) 29 | if err != nil { 30 | t.Fatal(err) 31 | } 32 | json, _ := json.Marshal(result) 33 | fmt.Println(string(json)) 34 | } 35 | 36 | func TestGetGenreRadios(t *testing.T) { 37 | result, err := GetGenreRadios(85) 38 | if err != nil { 39 | t.Fatal(err) 40 | } 41 | json, _ := json.Marshal(result) 42 | fmt.Println(string(json)) 43 | } 44 | -------------------------------------------------------------------------------- /album_test.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "testing" 7 | ) 8 | 9 | func TestGetAlbumGet(t *testing.T) { 10 | result, err := GetAlbum(6575789) 11 | if err != nil { 12 | t.Fatal(err) 13 | } 14 | json, _ := json.Marshal(result) 15 | fmt.Println(string(json)) 16 | } 17 | 18 | func TestGetAlbumTracks(t *testing.T) { 19 | result, err := GetAlbumTracks(6575789, 0, 0) 20 | if err != nil { 21 | t.Fatal(err) 22 | } 23 | json, _ := json.Marshal(result) 24 | fmt.Println(string(json)) 25 | } 26 | 27 | func TestGetAlbumComments(t *testing.T) { 28 | result, err := GetAlbumComments(6575789, 0, 0) 29 | if err != nil { 30 | t.Fatal(err) 31 | } 32 | json, _ := json.Marshal(result) 33 | fmt.Println(string(json)) 34 | } 35 | 36 | func TestGetAlbumFans(t *testing.T) { 37 | result, err := GetAlbumFans(6575789, 0, 0) 38 | if err != nil { 39 | t.Fatal(err) 40 | } 41 | json, _ := json.Marshal(result) 42 | fmt.Println(string(json)) 43 | } 44 | -------------------------------------------------------------------------------- /playlist_test.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "testing" 7 | ) 8 | 9 | func TestGetPlaylist(t *testing.T) { 10 | result, err := GetPlaylist(785141981) 11 | if err != nil { 12 | t.Fatal(err) 13 | } 14 | json, _ := json.Marshal(result) 15 | fmt.Println(string(json)) 16 | } 17 | 18 | func TestGetPlaylistComments(t *testing.T) { 19 | result, err := GetPlaylistComments(785141981, 0, 0) 20 | if err != nil { 21 | t.Fatal(err) 22 | } 23 | json, _ := json.Marshal(result) 24 | fmt.Println(string(json)) 25 | } 26 | 27 | func TestGetPlaylistFans(t *testing.T) { 28 | result, err := GetPlaylistFans(785141981, 0, 0) 29 | if err != nil { 30 | t.Fatal(err) 31 | } 32 | json, _ := json.Marshal(result) 33 | fmt.Println(string(json)) 34 | } 35 | 36 | func TestGetPlaylistTracks(t *testing.T) { 37 | result, err := GetPlaylistTracks(785141981, 0, 0) 38 | if err != nil { 39 | t.Fatal(err) 40 | } 41 | json, _ := json.Marshal(result) 42 | fmt.Println(string(json)) 43 | } 44 | -------------------------------------------------------------------------------- /deezer.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import ( 4 | "errors" 5 | "net/url" 6 | "strconv" 7 | 8 | "github.com/jmcvetta/napping" 9 | ) 10 | 11 | var BaseUrl = "http://api.deezer.com" 12 | 13 | func listParams(index, limit int) *url.Values { 14 | v := &url.Values{} 15 | v.Set("index", strconv.Itoa(index)) 16 | v.Set("limit", strconv.Itoa(limit)) 17 | return v 18 | } 19 | 20 | func get(path string, params *url.Values, result interface{}) error { 21 | url := BaseUrl + path 22 | errMsg := ErrorResponse{} 23 | _, err := napping.Get(url, params, result, &errMsg) 24 | if err != nil { 25 | return err 26 | } 27 | if errMsg.Error.Code != 0 { 28 | return errors.New(errMsg.Error.String()) 29 | } 30 | return nil 31 | } 32 | 33 | func Get(url string, result interface{}) error { 34 | errMsg := ErrorResponse{} 35 | _, err := napping.Get(url, nil, result, &errMsg) 36 | if err != nil { 37 | return err 38 | } 39 | if errMsg.Error.Code != 0 { 40 | return errors.New(errMsg.Error.String()) 41 | } 42 | return nil 43 | } 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017 George Czabania. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /genre.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | ) 7 | 8 | type Genre struct { 9 | ID int `json:"id,omitempty"` 10 | Name string `json:"name,omitempty"` 11 | } 12 | 13 | type ExtendedGenreList struct { 14 | Data []Genre `json:"data,omitempty"` 15 | } 16 | 17 | type GenreList []Genre 18 | 19 | func (g *GenreList) UnmarshalJSON(data []byte) error { 20 | extendedGenreList := ExtendedGenreList{} 21 | if err := json.Unmarshal(data, &extendedGenreList); err != nil { 22 | return err 23 | } 24 | 25 | *g = extendedGenreList.Data 26 | 27 | return nil 28 | } 29 | 30 | func GetGenres() (GenreList, error) { 31 | path := "/genre" 32 | result := GenreList{} 33 | err := get(path, nil, &result) 34 | return result, err 35 | } 36 | 37 | func GetGenre(id int) (Genre, error) { 38 | path := fmt.Sprintf("/genre/%d", id) // Genre 39 | result := Genre{} 40 | err := get(path, nil, &result) 41 | return result, err 42 | } 43 | 44 | func GetGenreArtists(id int) (ArtistList, error) { 45 | path := fmt.Sprintf("/genre/%d/artists", id) 46 | result := ArtistList{} 47 | err := get(path, nil, &result) 48 | return result, err 49 | } 50 | 51 | func GetGenreRadios(id int) (RadioList, error) { 52 | path := fmt.Sprintf("/genre/%d/radios", id) 53 | result := RadioList{} 54 | err := get(path, nil, &result) 55 | return result, err 56 | } 57 | -------------------------------------------------------------------------------- /chart.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import "fmt" 4 | 5 | type Chart struct { 6 | Tracks TrackList `json:"tracks,omitempty"` 7 | Albums AlbumList `json:"albums,omitempty"` 8 | Artists ArtistList `json:"artists,omitempty"` 9 | Playlists PlaylistList `json:"playlists,omitempty"` 10 | } 11 | 12 | func GetCharts(index, limit int) (Chart, error) { 13 | path := "/chart" 14 | result := Chart{} 15 | err := get(path, listParams(index, limit), &result) 16 | return result, err 17 | } 18 | 19 | func GetChartTracks(id, index, limit int) (TrackList, error) { 20 | path := fmt.Sprintf("/chart/%d/tracks", id) 21 | result := TrackList{} 22 | err := get(path, listParams(index, limit), &result) 23 | return result, err 24 | } 25 | 26 | func GetChartAlbums(id, index, limit int) (AlbumList, error) { 27 | path := fmt.Sprintf("/chart/%d/albums", id) 28 | result := AlbumList{} 29 | err := get(path, listParams(index, limit), &result) 30 | return result, err 31 | } 32 | 33 | func GetChartArtists(id, index, limit int) (ArtistList, error) { 34 | path := fmt.Sprintf("/chart/%d/artists", id) 35 | result := ArtistList{} 36 | err := get(path, listParams(index, limit), &result) 37 | return result, err 38 | } 39 | 40 | func GetChartPlaylists(id, index, limit int) (PlaylistList, error) { 41 | path := fmt.Sprintf("/chart/%d/playlists", id) 42 | result := PlaylistList{} 43 | err := get(path, listParams(index, limit), &result) 44 | return result, err 45 | } 46 | -------------------------------------------------------------------------------- /editorial.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import "fmt" 4 | 5 | type Editorial struct { 6 | ID int `json:"id,omitempty"` // The editorial's Deezer id 7 | Name string `json:"name,omitempty"` // The editorial's name 8 | } 9 | 10 | type EditorialList struct { 11 | Data []Editorial `json:"data,omitempty"` 12 | Total int `json:"total,omitempty"` 13 | Next string `json:"next,omitempty"` 14 | } 15 | 16 | func GetEditorials() (EditorialList, error) { 17 | path := "/editorial" 18 | result := EditorialList{} 19 | err := get(path, nil, &result) 20 | return result, err 21 | } 22 | 23 | func GetEditorial(id int) (Editorial, error) { 24 | path := fmt.Sprintf("editorial/%d", id) 25 | result := Editorial{} 26 | err := get(path, nil, &result) 27 | return result, err 28 | } 29 | 30 | func GetEditorialSelection(id int, date string, index, limit int) (AlbumList, error) { 31 | path := fmt.Sprintf("editorial/%d/selection", id) 32 | result := AlbumList{} 33 | err := get(path, listParams(index, limit), &result) 34 | return result, err 35 | } 36 | 37 | func GetEditorialCharts(id, index, limit int) (Chart, error) { 38 | path := fmt.Sprintf("editorial/%d/charts", id) 39 | result := Chart{} 40 | err := get(path, listParams(index, limit), &result) 41 | return result, err 42 | } 43 | 44 | func GetEditorialReleases(id, index, limit int) (AlbumList, error) { 45 | path := fmt.Sprintf("editorial/%d/releases", id) 46 | result := AlbumList{} 47 | err := get(path, listParams(index, limit), &result) 48 | return result, err 49 | } 50 | -------------------------------------------------------------------------------- /search_test.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "testing" 7 | ) 8 | 9 | func TestSearchTrack(t *testing.T) { 10 | result, err := SearchTrack("Stornoway Zorbing", false, RANKING, 0, 0) 11 | if err != nil { 12 | t.Fatal(err) 13 | } 14 | json, _ := json.Marshal(result) 15 | fmt.Println(string(json)) 16 | } 17 | 18 | func TestSearchArtist(t *testing.T) { 19 | result, err := SearchArtist("Squirrel Nut Zippers", false, RANKING, 0, 0) 20 | if err != nil { 21 | t.Fatal(err) 22 | } 23 | json, _ := json.Marshal(result) 24 | fmt.Println(string(json)) 25 | } 26 | 27 | func TestSearchAlbum(t *testing.T) { 28 | result, err := SearchAlbum("Fleetwood Mac Rumours", false, RANKING, 0, 0) 29 | if err != nil { 30 | t.Fatal(err) 31 | } 32 | json, _ := json.Marshal(result) 33 | fmt.Println(string(json)) 34 | } 35 | 36 | func TestSearchUser(t *testing.T) { 37 | result, err := SearchUser("stayrad", false, RANKING, 0, 0) 38 | if err != nil { 39 | t.Fatal(err) 40 | } 41 | json, _ := json.Marshal(result) 42 | fmt.Println(string(json)) 43 | } 44 | 45 | func TestSearchPlaylist(t *testing.T) { 46 | result, err := SearchPlaylist("Super Hits", false, RANKING, 0, 0) 47 | if err != nil { 48 | t.Fatal(err) 49 | } 50 | json, _ := json.Marshal(result) 51 | fmt.Println(string(json)) 52 | } 53 | 54 | func TestAdvancedSearch(t *testing.T) { 55 | query := AdvancedSearch{ 56 | Artist: "stornoway", 57 | Album: "bonxie", 58 | Track: "zorbing", 59 | }.String() 60 | 61 | if query != "artist:\"stornoway\" album:\"bonxie\" track:\"zorbing\" " { 62 | t.Fatal() 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /artist_test.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "testing" 7 | ) 8 | 9 | func TestGetArtist(t *testing.T) { 10 | result, err := GetArtist(27) 11 | if err != nil { 12 | t.Fatal(err) 13 | } 14 | json, _ := json.Marshal(result) 15 | fmt.Println(string(json)) 16 | } 17 | 18 | func TestGetArtistTop(t *testing.T) { 19 | result, err := GetArtistTop(27, 0, 0) 20 | if err != nil { 21 | t.Fatal(err) 22 | } 23 | json, _ := json.Marshal(result) 24 | fmt.Println(string(json)) 25 | } 26 | 27 | func TestGetArtistAlbums(t *testing.T) { 28 | result, err := GetArtistAlbums(27, 0, 0) 29 | if err != nil { 30 | t.Fatal(err) 31 | } 32 | json, _ := json.Marshal(result) 33 | fmt.Println(string(json)) 34 | } 35 | 36 | func TestGetArtistComments(t *testing.T) { 37 | result, err := GetArtistComments(27, 0, 0) 38 | if err != nil { 39 | t.Fatal(err) 40 | } 41 | json, _ := json.Marshal(result) 42 | fmt.Println(string(json)) 43 | } 44 | 45 | func TestGetArtistFans(t *testing.T) { 46 | result, err := GetArtistFans(27, 0, 0) 47 | if err != nil { 48 | t.Fatal(err) 49 | } 50 | json, _ := json.Marshal(result) 51 | fmt.Println(string(json)) 52 | } 53 | 54 | func TestGetArtistRelated(t *testing.T) { 55 | result, err := GetArtistRelated(27, 0, 0) 56 | if err != nil { 57 | t.Fatal(err) 58 | } 59 | json, _ := json.Marshal(result) 60 | fmt.Println(string(json)) 61 | } 62 | 63 | func TestGetArtistRadio(t *testing.T) { 64 | result, err := GetArtistRadio(27, 0, 0) 65 | if err != nil { 66 | t.Fatal(err) 67 | } 68 | json, _ := json.Marshal(result) 69 | fmt.Println(string(json)) 70 | } 71 | -------------------------------------------------------------------------------- /radio.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import "fmt" 4 | 5 | type Radio struct { 6 | ID int `json:"id,omitempty"` // The radio deezeid 7 | Title string `json:"title,omitempty"` // The radio title 8 | Description string `json:"description,omitempty"` // The radio title 9 | Share string `json:"share,omitempty"` // The share link of the radio on Deezer 10 | Picture string `json:"picture,omitempty"` // The url of the radio picture. 11 | Tracklist string `json:"tracklist,omitempty"` // API Link to the tracklist of this radio 12 | } 13 | 14 | type RadioList struct { 15 | Data []Radio `json:"data,omitempty"` 16 | } 17 | 18 | type GenreRadio struct { 19 | ID int `json:"id,omitempty"` 20 | Title string `json:"title,omitempty"` 21 | Radios []Radio `json:"radios,omitempty"` 22 | } 23 | 24 | type GenreRadioList struct { 25 | Data []GenreRadio `json:"data,omitempty"` 26 | } 27 | 28 | func GetRadios() (RadioList, error) { 29 | path := "/radio" 30 | result := RadioList{} 31 | err := get(path, nil, &result) 32 | return result, err 33 | } 34 | 35 | func GetRadio(id int) (Radio, error) { 36 | path := fmt.Sprintf("/radio/%d", id) 37 | result := Radio{} 38 | err := get(path, nil, &result) 39 | return result, err 40 | } 41 | 42 | func GetRadioGenres() (GenreRadioList, error) { 43 | path := "/radio/genres" 44 | result := GenreRadioList{} 45 | err := get(path, nil, &result) 46 | return result, err 47 | } 48 | 49 | func GetRadioTop() (RadioList, error) { 50 | path := "/radio/top" 51 | result := RadioList{} 52 | err := get(path, nil, &result) 53 | return result, err 54 | } 55 | 56 | func GetRadioTracks(id, index, limit int) (TrackList, error) { 57 | path := fmt.Sprintf("/radio/%d/tracks", id) 58 | result := TrackList{} 59 | err := get(path, listParams(index, limit), &result) 60 | return result, err 61 | } 62 | -------------------------------------------------------------------------------- /user_test.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "testing" 7 | ) 8 | 9 | func TestGetUser(t *testing.T) { 10 | result, err := GetUser(374224155) 11 | if err != nil { 12 | t.Fatal(err) 13 | } 14 | json, _ := json.Marshal(result) 15 | fmt.Println(string(json)) 16 | } 17 | 18 | func TestGetUserAlbums(t *testing.T) { 19 | result, err := GetUserAlbums(374224155, 0, 0) 20 | if err != nil { 21 | t.Fatal(err) 22 | } 23 | json, _ := json.Marshal(result) 24 | fmt.Println(string(json)) 25 | } 26 | 27 | func TestGetUserArtists(t *testing.T) { 28 | result, err := GetUserArtists(374224155, 0, 0) 29 | if err != nil { 30 | t.Fatal(err) 31 | } 32 | json, _ := json.Marshal(result) 33 | fmt.Println(string(json)) 34 | } 35 | 36 | func TestGetUserCharts(t *testing.T) { 37 | result, err := GetUserCharts(374224155, 0, 0) 38 | if err != nil { 39 | t.Fatal(err) 40 | } 41 | json, _ := json.Marshal(result) 42 | fmt.Println(string(json)) 43 | } 44 | 45 | func TestGetUserFlow(t *testing.T) { 46 | result, err := GetUserFlow(374224155, 0, 0) 47 | if err != nil { 48 | t.Fatal(err) 49 | } 50 | json, _ := json.Marshal(result) 51 | fmt.Println(string(json)) 52 | } 53 | 54 | func TestGetUserFollowings(t *testing.T) { 55 | result, err := GetUserFollowings(374224155, 0, 0) 56 | if err != nil { 57 | t.Fatal(err) 58 | } 59 | json, _ := json.Marshal(result) 60 | fmt.Println(string(json)) 61 | } 62 | 63 | func TestGetUserPlaylists(t *testing.T) { 64 | result, err := GetUserPlaylists(374224155, 0, 0) 65 | if err != nil { 66 | t.Fatal(err) 67 | } 68 | json, _ := json.Marshal(result) 69 | fmt.Println(string(json)) 70 | } 71 | 72 | func TestGetUserRadios(t *testing.T) { 73 | result, err := GetUserRadios(374224155, 0, 0) 74 | if err != nil { 75 | t.Fatal(err) 76 | } 77 | json, _ := json.Marshal(result) 78 | fmt.Println(string(json)) 79 | } 80 | 81 | func TestGetUserTracks(t *testing.T) { 82 | result, err := GetUserTracks(374224155, 0, 0) 83 | if err != nil { 84 | t.Fatal(err) 85 | } 86 | json, _ := json.Marshal(result) 87 | fmt.Println(string(json)) 88 | } 89 | -------------------------------------------------------------------------------- /playlist.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | ) 7 | 8 | type Playlist struct { 9 | ID int `json:"id,omitempty"` // The playlist's Deezer id 10 | Title string `json:"title,omitempty"` // The playlist's title 11 | Description string `json:"description,omitempty"` // The playlist description 12 | Duration int `json:"duration,omitempty"` // The playlist's duration (seconds) 13 | Public bool `json:"public,omitempty"` // If the playlist is public or not 14 | IsLovedTrack bool `json:"is_loved_track,omitempty"` // If the playlist is the love tracks playlist 15 | Collaborative bool `json:"collaborative,omitempty"` // If the playlist is collaborative or not 16 | Rating int `json:"rating,omitempty"` // The playlist's rate 17 | Fans int `json:"fans,omitempty"` // The number of playlist's fans 18 | Link string `json:"link,omitempty"` // The url of the playlist on Deezer 19 | Share string `json:"share,omitempty"` // The share link of the playlist on Deezer 20 | Picture string `json:"picture,omitempty"` // The url of the playlist's cover. 21 | Checksum string `json:"hecksum,omitempty"` // The checksum for the track list 22 | Creator *User `json:"creator,omitempty"` // User object containing : id, name 23 | Tracks TrackList `json:"tracks,omitempty"` // List of tracks 24 | } 25 | 26 | type ExtendedPlaylistList struct { 27 | Data []Playlist `json:"data,omitempty"` 28 | Total int `json:"total,omitempty"` 29 | Next string `json:"next,omitempty"` 30 | } 31 | 32 | type PlaylistList []Playlist 33 | 34 | func (p *PlaylistList) UnmarshalJSON(data []byte) error { 35 | extendedPlaylistList := ExtendedPlaylistList{} 36 | if err := json.Unmarshal(data, &extendedPlaylistList); err != nil { 37 | return err 38 | } 39 | 40 | *p = extendedPlaylistList.Data 41 | 42 | return nil 43 | } 44 | 45 | func GetPlaylist(id int) (Playlist, error) { 46 | path := fmt.Sprintf("/playlist/%d", id) 47 | result := Playlist{} 48 | err := get(path, nil, &result) 49 | return result, err 50 | } 51 | 52 | func GetPlaylistComments(id, index, limit int) (CommentList, error) { 53 | path := fmt.Sprintf("/playlist/%d/comments", id) 54 | result := CommentList{} 55 | err := get(path, listParams(index, limit), &result) 56 | return result, err 57 | } 58 | 59 | func GetPlaylistFans(id, index, limit int) (UserList, error) { 60 | path := fmt.Sprintf("/playlist/%d/fans", id) 61 | result := UserList{} 62 | err := get(path, listParams(index, limit), &result) 63 | return result, err 64 | } 65 | 66 | func GetPlaylistTracks(id, index, limit int) (TrackList, error) { 67 | path := fmt.Sprintf("/playlist/%d/tracks", id) 68 | result := TrackList{} 69 | err := get(path, listParams(index, limit), &result) 70 | return result, err 71 | } 72 | -------------------------------------------------------------------------------- /track.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | ) 7 | 8 | type Track struct { 9 | ID int `json:"id,omitempty"` // The track's Deezer id 10 | Readable bool `json:"readable,omitempty"` // true if the track is readable in the player for the current user 11 | Title string `json:"title,omitempty"` // The track's title 12 | Isrc string `json:"isrc,omitempty"` // The track isrc 13 | Link string `json:"link,omitempty"` // The url of the track on Deezer 14 | Share string `json:"share,omitempty"` // The share link of the track on Deezer 15 | Duration int `json:"duration,omitempty"` // The track's duration in seconds 16 | TrackPosition int `json:"track_position,omitempty"` // The position of the track in its album 17 | DiskNumber int `json:"disk_number,omitempty"` // The track's album's disk number 18 | Rank int `json:"rank,omitempty"` // The track's Deezer rank 19 | ReleaseDate string `json:"release_date,omitempty"` // The track's release date 20 | ExplicitLyrics bool `json:"explicit_lyrics,omitempty"` // Whether the track contains explicit lyrics 21 | Preview string `json:"preview,omitempty"` // The url of track's preview file. This file contains the first 30 seconds of the track 22 | Bpm float64 `json:"bpm,omitempty"` // Beats per minute 23 | Gain float64 `json:"gain,omitempty"` // Signal strength 24 | AvailableCountries []string `json:"available_countries,omitempty"` // List of countries where the track is available 25 | // Alternative Track `json:"alternative,omitempty"` // Return an alternative readable track if the current track is not readable 26 | Contributors []Artist `json:"contributors,omitempty"` // Return a list of contributors on the track 27 | Artist *Artist `json:"artist,omitempty"` // artist object containing : id, name, link, share, picture, nb_album, nb_fan, radio, tracklist, role 28 | Album *Album `json:"album,omitempty"` // album object containing : id, title, link, cover, release_date 29 | } 30 | 31 | type ExtendedTrackList struct { 32 | Data []Track `json:"data"` 33 | Total int `json:"total"` 34 | Next string `json:"next"` 35 | } 36 | 37 | type TrackList []Track 38 | 39 | func (t *TrackList) UnmarshalJSON(data []byte) error { 40 | extendedTrackList := ExtendedTrackList{} 41 | if err := json.Unmarshal(data, &extendedTrackList); err != nil { 42 | return err 43 | } 44 | 45 | *t = extendedTrackList.Data 46 | 47 | return nil 48 | } 49 | 50 | func GetTrack(id int) (Track, error) { 51 | path := fmt.Sprintf("/track/%d", id) 52 | result := Track{} 53 | err := get(path, nil, &result) 54 | return result, err 55 | } 56 | -------------------------------------------------------------------------------- /artist.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | ) 7 | 8 | type Artist struct { 9 | ID int `json:"id,omitempty"` // The artist's Deezer id 10 | Name string `json:"name,omitempty"` // name The artist's name 11 | Link string `json:"link,omitempty"` // The url of the artist on Deezer 12 | Share string `json:"share,omitempty"` // The share link of the artist on Deezer 13 | Picture string `json:"picture,omitempty"` // The url of the artist picture. 14 | NbAlbum int `json:"nb_album,omitempty"` // The number of artist's albums 15 | NbFan int `json:"nb_fan,omitempty"` // The number of artist's fans 16 | Radio bool `json:"radio,omitempty"` // true if the artist has a smartradio 17 | Tracklist string `json:"tracklist,omitempty"` // API Link to the top of this artist 18 | Role string `json:"role,omitempty"` // The artist's role in a track or album 19 | Albums AlbumList `json:"albums,omitempty"` 20 | Tracks TrackList `json:"tracks,omitempty"` 21 | } 22 | 23 | type ExtendedArtistList struct { 24 | Data []Artist `json:"data,omitempty"` 25 | Total int `json:"total,omitempty"` 26 | Next string `json:"next,omitempty"` 27 | } 28 | 29 | type ArtistList []Artist 30 | 31 | func (a *ArtistList) UnmarshalJSON(data []byte) error { 32 | extendedArtistList := ExtendedArtistList{} 33 | if err := json.Unmarshal(data, &extendedArtistList); err != nil { 34 | return err 35 | } 36 | 37 | *a = extendedArtistList.Data 38 | 39 | return nil 40 | } 41 | 42 | func GetArtist(id int) (Artist, error) { 43 | path := fmt.Sprintf("/artist/%d", id) 44 | result := Artist{} 45 | err := get(path, nil, &result) 46 | return result, err 47 | } 48 | 49 | func GetArtistTop(id, index, limit int) (TrackList, error) { 50 | path := fmt.Sprintf("/artist/%d/top", id) 51 | result := TrackList{} 52 | err := get(path, listParams(index, limit), &result) 53 | return result, err 54 | } 55 | 56 | func GetArtistAlbums(id, index, limit int) (AlbumList, error) { 57 | path := fmt.Sprintf("/artist/%d/albums", id) 58 | result := AlbumList{} 59 | err := get(path, listParams(index, limit), &result) 60 | return result, err 61 | } 62 | 63 | func GetArtistComments(id, index, limit int) (CommentList, error) { 64 | path := fmt.Sprintf("/artist/%d/comments", id) 65 | result := CommentList{} 66 | err := get(path, listParams(index, limit), &result) 67 | return result, err 68 | } 69 | 70 | func GetArtistFans(id, index, limit int) (UserList, error) { 71 | path := fmt.Sprintf("/artist/%d/fans", id) 72 | result := UserList{} 73 | err := get(path, listParams(index, limit), &result) 74 | return result, err 75 | } 76 | 77 | func GetArtistRelated(id, index, limit int) (ArtistList, error) { 78 | path := fmt.Sprintf("/artist/%d/related", id) 79 | result := ArtistList{} 80 | err := get(path, listParams(index, limit), &result) 81 | return result, err 82 | } 83 | 84 | func GetArtistRadio(id, index, limit int) (TrackList, error) { 85 | path := fmt.Sprintf("/artist/%d/radio", id) 86 | result := TrackList{} 87 | err := get(path, listParams(index, limit), &result) 88 | return result, err 89 | } 90 | -------------------------------------------------------------------------------- /search.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import ( 4 | "fmt" 5 | "net/url" 6 | "strconv" 7 | ) 8 | 9 | const ( 10 | RANKING = "RANKING" 11 | TRACK_ASC = "TRACK_ASC" 12 | TRACK_DESC = "TRACK_DESC" 13 | ARTIST_ASC = "ARTIST_ASC" 14 | ARTIST_DESC = "ARTIST_DESC" 15 | ALBUM_ASC = "ALBUM_ASC" 16 | ALBUM_DESC = "ALBUM_DESC" 17 | RATING_ASC = "RATING_ASC" 18 | RATING_DESC = "RATING_DESC" 19 | DURATION_ASC = "DURATION_ASC" 20 | DURATION_DESC = "DURATION_DESC" 21 | ) 22 | 23 | func searchParams(query string, strict bool, order string, index, limit int) *url.Values { 24 | v := &url.Values{} 25 | v.Set("q", query) 26 | v.Set("strict", strconv.FormatBool(strict)) 27 | v.Set("order", order) 28 | v.Set("index", strconv.Itoa(index)) 29 | v.Set("limit", strconv.Itoa(limit)) 30 | return v 31 | } 32 | 33 | func SearchTrack(query string, strict bool, order string, index, limit int) (TrackList, error) { 34 | path := "/search/track" 35 | result := TrackList{} 36 | err := get(path, searchParams(query, strict, order, index, limit), &result) 37 | return result, err 38 | } 39 | 40 | func SearchAlbum(query string, strict bool, order string, index, limit int) (AlbumList, error) { 41 | path := "/search/album" 42 | result := AlbumList{} 43 | err := get(path, searchParams(query, strict, order, index, limit), &result) 44 | return result, err 45 | } 46 | 47 | func SearchArtist(query string, strict bool, order string, index, limit int) (ArtistList, error) { 48 | path := "/search/artist" 49 | result := ArtistList{} 50 | err := get(path, searchParams(query, strict, order, index, limit), &result) 51 | return result, err 52 | } 53 | 54 | func SearchUser(query string, strict bool, order string, index, limit int) (UserList, error) { 55 | path := "/search/user" 56 | result := UserList{} 57 | err := get(path, searchParams(query, strict, order, index, limit), &result) 58 | return result, err 59 | } 60 | 61 | func SearchPlaylist(query string, strict bool, order string, index, limit int) (PlaylistList, error) { 62 | path := "/search/playlist" 63 | result := PlaylistList{} 64 | err := get(path, searchParams(query, strict, order, index, limit), &result) 65 | return result, err 66 | } 67 | 68 | type AdvancedSearch struct { 69 | Artist string 70 | Album string 71 | Track string 72 | Label string 73 | DurMin int 74 | DurMax int 75 | BPMMin int 76 | BPMMax int 77 | } 78 | 79 | func (a AdvancedSearch) String() (s string) { 80 | if a.Artist != "" { 81 | s += fmt.Sprintf("artist:\"%s\" ", a.Artist) 82 | } 83 | if a.Album != "" { 84 | s += fmt.Sprintf("album:\"%s\" ", a.Album) 85 | } 86 | if a.Track != "" { 87 | s += fmt.Sprintf("track:\"%s\" ", a.Track) 88 | } 89 | if a.Label != "" { 90 | s += fmt.Sprintf("label:\"%s\" ", a.Track) 91 | } 92 | if a.DurMin > 0 { 93 | s += fmt.Sprintf("dur_min:\"%d\" ", a.DurMin) 94 | } 95 | if a.DurMax > 0 { 96 | s += fmt.Sprintf("dur_max:\"%d\" ", a.DurMax) 97 | } 98 | if a.BPMMin > 0 { 99 | s += fmt.Sprintf("bpm_max:\"%d\" ", a.BPMMin) 100 | } 101 | if a.BPMMax > 0 { 102 | s += fmt.Sprintf("bpm_max:\"%d\" ", a.BPMMax) 103 | } 104 | return s 105 | } 106 | -------------------------------------------------------------------------------- /album.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | ) 7 | 8 | type Album struct { 9 | ID int `json:"id,omitempty"` // The Deezer album id 10 | Title string `json:"title,omitempty"` // The album title 11 | UPC string `json:"upc,omitempty"` // The album UPC 12 | Link string `json:"link,omitempty"` // The url of the album on Deezer url 13 | Share string `json:"share,omitempty"` // The share link of the album on Deezer 14 | Cover string `json:"cover,omitempty"` // The url of the album's cover. 15 | GenreID int `json:"genre_id,omitempty"` // The album's first genre id. NB : -1 for not found 16 | Genres GenreList `json:"genres,omitempty"` // List of genre object 17 | Label string `json:"label,omitempty"` // The album's label name 18 | NbTracks int `json:"nb_tracks,omitempty"` // Number of tracks 19 | Duration int `json:"duration,omitempty"` // The album's duration (seconds) 20 | Fans int `json:"fans,omitempty"` // The number of album's Fans 21 | Rating int `json:"rating,omitempty"` // The playlist's rate 22 | ReleaseDate string `json:"release_date,omitempty"` // The album's release date 23 | RecordType string `json:"record_type,omitempty"` // The record type of the album (EP / ALBUM / etc..) 24 | Available bool `json:"available,omitempty"` // If the album is avaiable 25 | // Alternative Album `json:"alternative,omitempty"` // Return an alternative album object if the current album is not available 26 | Tracklist string `json:"tracklist,omitempty"` // API Link to the tracklist of this album 27 | ExplicitLyrics bool `json:"explicit_lyrics,omitempty"` // Whether the album contains explicit lyrics 28 | Contributors []Artist `json:"contributors,omitempty"` // Return a list of contributors on the album 29 | Artist *Artist `json:"artist,omitempty"` // artist object containing : id, name, picture 30 | Tracks TrackList `json:"tracks,omitempty"` // list of track 31 | } 32 | 33 | type ExtendedAlbumList struct { 34 | Data []Album `json:"data,omitempty"` 35 | Total int `json:"total,omitempty"` 36 | Next string `json:"next,omitempty"` 37 | } 38 | 39 | type AlbumList []Album 40 | 41 | func (a *AlbumList) UnmarshalJSON(data []byte) error { 42 | extendedAlbumList := ExtendedAlbumList{} 43 | if err := json.Unmarshal(data, &extendedAlbumList); err != nil { 44 | return err 45 | } 46 | 47 | *a = extendedAlbumList.Data 48 | 49 | return nil 50 | } 51 | 52 | func GetAlbum(id int) (Album, error) { 53 | path := fmt.Sprintf("/album/%d", id) 54 | result := Album{} 55 | err := get(path, nil, &result) 56 | return result, err 57 | } 58 | 59 | func GetAlbumComments(id, index, limit int) (CommentList, error) { 60 | path := fmt.Sprintf("/album/%d/comments", id) 61 | result := CommentList{} 62 | err := get(path, listParams(index, limit), &result) 63 | return result, err 64 | } 65 | 66 | func GetAlbumFans(id, index, limit int) (UserList, error) { 67 | path := fmt.Sprintf("/album/%d/fans", id) 68 | result := UserList{} 69 | err := get(path, listParams(index, limit), &result) 70 | return result, err 71 | } 72 | 73 | func GetAlbumTracks(id, index, limit int) (TrackList, error) { 74 | path := fmt.Sprintf("/album/%d/tracks", id) 75 | result := TrackList{} 76 | err := get(path, listParams(index, limit), &result) 77 | return result, err 78 | } 79 | -------------------------------------------------------------------------------- /user.go: -------------------------------------------------------------------------------- 1 | package deezer 2 | 3 | import "fmt" 4 | 5 | type User struct { 6 | ID int `json:"id,omitempty"` // The user's Deezer ID 7 | Name string `json:"name,omitempty"` // The user's Deezer nickname 8 | Lastname string `json:"lastname,omitempty"` // The user's last name 9 | Firstname string `json:"firstname,omitempty"` // The user's first name 10 | Email string `json:"email,omitempty"` // The user's email 11 | Status int `json:"status,omitempty"` // The user's status 12 | Birthday int `json:"birthday,omitempty"` // The user's birthday 13 | InscriptionDate int `json:"inscription_date,omitempty"` // The user's inscription date 14 | Gender string `json:"gender,omitempty"` // The user's gender : F or M 15 | Link string `json:"link,omitempty"` // The url of the profil for the user on Deezer 16 | Picture string `json:"picture,omitempty"` // The url of the user's profil picture. 17 | Country string `json:"country,omitempty"` // The user's country 18 | Lang string `json:"lang,omitempty"` // The user's language 19 | Tracklist string `json:"tracklist,omitempty"` // API Link to the flow of this user 20 | } 21 | 22 | type UserList struct { 23 | Data []User `json:"data,omitempty"` 24 | Total int `json:"total,omitempty"` 25 | Next string `json:"next,omitempty"` 26 | } 27 | 28 | func GetUser(id int) (User, error) { 29 | path := fmt.Sprintf("/user/%d", id) 30 | result := User{} 31 | err := get(path, nil, &result) 32 | return result, err 33 | } 34 | 35 | func GetUserAlbums(id, index, limit int) (AlbumList, error) { 36 | path := fmt.Sprintf("/user/%d/albums", id) 37 | result := AlbumList{} 38 | err := get(path, listParams(index, limit), &result) 39 | return result, err 40 | } 41 | 42 | func GetUserArtists(id, index, limit int) (ArtistList, error) { 43 | path := fmt.Sprintf("/user/%d/artists", id) 44 | result := ArtistList{} 45 | err := get(path, listParams(index, limit), &result) 46 | return result, err 47 | } 48 | 49 | func GetUserCharts(id, index, limit int) (TrackList, error) { 50 | path := fmt.Sprintf("/user/%d/charts", id) 51 | result := TrackList{} 52 | err := get(path, listParams(index, limit), &result) 53 | return result, err 54 | } 55 | 56 | func GetUserFlow(id, index, limit int) (TrackList, error) { 57 | path := fmt.Sprintf("/user/%d/flow", id) 58 | result := TrackList{} 59 | err := get(path, listParams(index, limit), &result) 60 | return result, err 61 | } 62 | 63 | func GetUserFollowings(id, index, limit int) (UserList, error) { 64 | path := fmt.Sprintf("/user/%d/followings", id) 65 | result := UserList{} 66 | err := get(path, listParams(index, limit), &result) 67 | return result, err 68 | } 69 | 70 | func GetUserPlaylists(id, index, limit int) (PlaylistList, error) { 71 | path := fmt.Sprintf("/user/%d/playlists", id) 72 | result := PlaylistList{} 73 | err := get(path, listParams(index, limit), &result) 74 | return result, err 75 | } 76 | 77 | func GetUserRadios(id, index, limit int) (RadioList, error) { 78 | path := fmt.Sprintf("/user/%d/radios", id) 79 | result := RadioList{} 80 | err := get(path, listParams(index, limit), &result) 81 | return result, err 82 | } 83 | 84 | func GetUserTracks(id, index, limit int) (TrackList, error) { 85 | path := fmt.Sprintf("/user/%d/tracks", id) 86 | result := TrackList{} 87 | err := get(path, listParams(index, limit), &result) 88 | return result, err 89 | } 90 | --------------------------------------------------------------------------------