musixmatch

package module
v0.0.0-...-185a339 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2017 License: MIT Imports: 9 Imported by: 0

README

go-musixmatch

Go client for the Musixmatch API

This is primarily a practice project, strongly based on Stripe's go client.

Finished:

  • Track endpoints

TODO:

  • Chart endpoints
  • Artist endpoints
  • Album endpoints
  • Unit tests

Usage Example:

func main() {
  // setup musixmatch api key
	musixmatch.Key = config.Key

  // get track by ID
	track, err := tracks.GetByID(15445186))
	if err != nil {
		// handle err
	}

  // search for tracks
	trackList, err := tracks.Search(&musixmatch.TrackListParams{
		Artist: musixmatch.String("lady gaga"),
	})
	if err != nil {
		// handle err
	}

	for _, t := range trackList.Tracks {
		fmt.Println(t.Name)
	}

  // get specific lyrics
	lyric, err := tracks.GetLyric(&musixmatch.TrackLyricsParams{
		Artist: musixmatch.String("adele"),
    TrackTitle: musixmatch.String("hello"),
	})
	if err != nil {
		// handle err
	}

  // get lyrics by ID
  lyric, err := tracks.GetLyricByID(15445186)
  if err!=nil{
    // handle err
  }
}

Documentation

Index

Constants

View Source
const (
	//BaseURL is the API URL
	BaseURL = "http://api.musixmatch.com/ws/1.1"
)

Variables

Key is the MusixMatch API key

Functions

func CheckStatusCode

func CheckStatusCode(code int) error

CheckStatusCode checks for response errors

func Int

func Int(v int) *int

func Int64

func Int64(v int64) *int64

func SetArtistGetParams

func SetArtistGetParams(agp *ArtistGetParams) string

func SetArtistSearchParams

func SetArtistSearchParams(asp *ArtistSearchParams) string

func SetTrackGetParams

func SetTrackGetParams(tgp *TrackGetParams) string

SetTrackGetParams ...

func SetTrackListParams

func SetTrackListParams(tlp *TrackListParams) string

SetTrackListParams ...

func SetTrackLyricsParams

func SetTrackLyricsParams(tlp *TrackLyricsParams) string

SetTrackLyricsParams ...

func String

func String(v string) *string

Types

type Artist

type Artist struct {
	ID            int64       `json:"artist_id"`
	MBID          string      `json:"artist_mbid"`
	Name          string      `json:"artist_name"`
	Comment       string      `json:"artist_comment"`
	Country       string      `json:"artist_country"`
	Rating        int         `json:"artist_rating"`
	PrimaryGenres Genres      `json:"primary_genres"`
	ShareURL      string      `json:"artist_share_url"`
	Credits       ArtistsList `json:"artist_credits"`
	Restricted    FlexBool    `json:"restricted"`
	Managed       FlexBool    `json:"managed"`
}

type ArtistGetParams

type ArtistGetParams struct {
	ID   *int64
	MBID *string
}

type ArtistSearchParams

type ArtistSearchParams struct {
	Artist   *string
	ID       *int64
	MBID     *string
	Page     *int
	PageSize *int
}

type Artists

type Artists struct {
	Artist `json:"artist"`
}

type ArtistsList

type ArtistsList struct {
	Artists []*Artists `json:"artist_list"`
}

type Backend

type Backend struct {
	Key        string
	HTTPClient *http.Client
}

Backend holds the user API key and the HTTP client

func GetBackend

func GetBackend() Backend

GetBackend returns a Backend with the default HTTPClient

func SetBackend

func SetBackend(client *http.Client) Backend

SetBackend sets a Backend type with a custom HTTPClient

func (Backend) Call

func (b Backend) Call(method string, path string, params string, v *Return) error

Call is a helper function to execute an API request

type BackendService

type BackendService interface {
	Call(method string, path string, params string, v *Return) error
}

BackendService is an interface to be implemented by MusixMatch clients

type FlexBool

type FlexBool bool

FlexBool is a custom bool type that can convert 1 and 0 to true and false

func (FlexBool) MarshalJSON

func (fx FlexBool) MarshalJSON() ([]byte, error)

MarshalJSON implements the Marshaler interface for FlexBool

func (*FlexBool) UnmarshalJSON

func (fx *FlexBool) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the Unmarshaler interface for FlexBool

type FlexTime

type FlexTime struct {
	time.Time
}

FlexTime is a custom type that holds musixmatch time representation, which can be either time or empty string

func (*FlexTime) UnmarshalJSON

func (ft *FlexTime) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the Unmarshaler interface for FlexTime

type GenreFields

type GenreFields struct {
	ID           int64  `json:"music_genre_id"`
	ParentID     int64  `json:"music_genre_parent_id"`
	Name         string `json:"music_genre_name"`
	NameExtended string `json:"music_genre_name_extended"`
	Vanity       string `json:"music_genre_vanity"`
}

GenreFields represents the fields of the music genre type

type Genres

type Genres struct {
	GenreList []*MusicGenre `json:"music_genre_list"`
}

Genres represents the list of primary music genres

type Header struct {
	StatusCode int `json:"status_code"`
}

Header contains the Status Code returned from the API request

type Lyric

type Lyric struct {
	ID                int64    `json:"lyrics_id"`
	Restricted        FlexBool `json:"restricted"`
	Instrumental      FlexBool `json:"instrumental"`
	Body              string   `json:"lyrics_body"`
	Language          string   `json:"lyrics_language"`
	ScriptTrackingURL string   `json:"script_tracking_url"`
	PixelTrackingURL  string   `json:"pixel_tracking_url"`
	HTMLTrackinURL    string   `json:"html_tracking_url"`
	Copyright         string   `json:"lyrics_copyright"`
	UpdatedAt         FlexTime `json:"updated_time"`
}

Lyric represents info returned from get.lyrics.track

type LyricInfo

type LyricInfo struct {
	Lyric `json:"lyrics"`
}

LyricInfo holds a Lyric instance

type Message

type Message struct {
	Header Header           `json:"header"`
	Body   *json.RawMessage `json:"body"`
}

Message represents the JSON object returned from the API request

type MusicGenre

type MusicGenre struct {
	Genre GenreFields `json:"music_genre"`
}

MusicGenre represents the music genre type

type Return

type Return struct {
	Message `json:"message"`
}

Return is the type that will hold the response from the API request

type Track

type Track struct {
	ID               int64    `json:"track_id"`
	MBID             string   `json:"track_mbid"`
	Name             string   `json:"track_name"`
	Rating           int      `json:"track_rating"`
	Instrumental     FlexBool `json:"instrumental"`
	Explicit         FlexBool `json:"explicit"`
	Favourites       int      `json:"num_favourite"`
	Genres           Genres   `json:"primary_genres"`
	HasLyrics        FlexBool `json:"has_lyrics"`
	HasSubtitles     FlexBool `json:"has_subtitles"`
	LyricsID         int64    `json:"lyrics_id"`
	SubtitleID       int64    `json:"subtitle_id"`
	AlbumID          int64    `json:"album_id"`
	AlbumName        string   `json:"album_name"`
	ArtistID         int64    `json:"artist_id"`
	ArtistName       string   `json:"artist_name"`
	ShareURL         string   `json:"track_share_url"`
	Restricted       FlexBool `json:"restricted"`
	FirstReleaseDate FlexTime `json:"first_release_date"`
	UpdatedTime      FlexTime `json:"updated_time"`
}

Track represents the fields of the track type

type TrackGetParams

type TrackGetParams struct {
	ID   *int64
	MBID *string
}

TrackGetParams are the acceptable params for the get.track request

type TrackList

type TrackList struct {
	Tracks []*Tracks `json:"track_list"`
}

TrackList represents a list of Track instances

type TrackListParams

type TrackListParams struct {
	TrackTitle           *string
	Artist               *string
	Lyrics               *string
	FilterArtistID       *int64
	FilterMusicGenreID   *int64
	FilterLyricsLang     *string
	FilterLyricsOnly     *bool
	FilterByArtistRating *string
	FilterByTrackRating  *string
	Page                 *int
	PageSize             *int
}

TrackListParams are the param options acceptable for requests returning a track list

type TrackLyricsParams

type TrackLyricsParams struct {
	TrackTitle *string
	Artist     *string
	ID         *int64
	MBID       *string
}

TrackLyricsParams are the acceptable params for the track.lyrics.get and matcher.track.get requests

type Tracks

type Tracks struct {
	Track `json:"track"`
}

Tracks represents the main track type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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