spotifyprivateapi

package module
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 12 Imported by: 0

README

Spotify Private API

This package provides a simple way to interact with Spotify's private API. It includes methods to fetch track information and play count.

Installation

go get github.com/FrostBreker/spotify-private-api

Usage

import "github.com/FrostBreker/spotify-private-api"

client := spotifyprivateapi.NewClient(spotifyprivateapi.Client{
		Debug: true,
})

// Fetch track information
track, err := client.FetchTrack("trackId")
if err != nil {
    log.Fatal(err)
}

// Fetch track play count
playCount, err := client.FetchTrackPlayCount("trackId")
if err != nil {
    log.Fatal(err)
}

// Fetch artist information
artist, err := client.FetchArtist("artistId")
if err != nil {
    log.Fatal(err)
}

// Fetch album information
album, err := client.FetchAlbum("albumId")
if err != nil {
    log.Fatal(err)
}

// Search in spotify
searchResults, err := client.Search("query")
if err != nil {
    log.Fatal(err)
}

// Search for top results in spotify
topTracks, err := client.SearchTopResult("query")
if err != nil {
    log.Fatal(err)
}

Documentation

FetchTrack(trackId string) (responseTypes.TrackResponse, error)

FetchTrack sends a GET request to Spotify's private API to fetch information about a track. The trackId parameter is the Spotify ID of the track. It returns a TrackResponse object and an error.

FetchTrackPlayCount(trackId string) (responseTypes.TrackPlayCount, error)

FetchTrackPlayCount first calls FetchTrack to get the track information, then it extracts the play count from the response. The trackId parameter is the Spotify ID of the track. It returns a TrackPlayCount object and an error.

FetchArtist(artistId string) (responseTypes.Artist, error)

FetchArtist fetches information about an artist from Spotify's private API. It takes an artistId parameter, which is the Spotify ID of the artist. It returns an Artist object and an error.

FetchAlbum(albumId string) (responseTypes.Album, error)

FetchAlbum fetches information about an album from Spotify's private API. It takes an albumId parameter, which is the Spotify ID of the album. It returns an AlbumResponseType object and an error.

Search(query string) (responseTypes.SearchResponseType, error)

Search sends a GET request to Spotify's private API to search for tracks, albums, artists and playlists. It takes a query parameter, which is the search query. It returns a SearchResponseType object and an error.

SearchTopResult(query string) (responseTypes.SearchTopResultResponseType, error)

SearchTopResult first calls Search to get the search results, then it extracts the top results from the response. It takes a query parameter, which is the search query. It returns a SearchTopResultResponseType object and an error.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Note: This package uses Spotify's private API and is not officially supported by Spotify. Use at your own risk.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HttpClient = &http.Client{
	Transport: &http.Transport{
		MaxIdleConnsPerHost: 100,
		IdleConnTimeout:     90 * time.Second,
	},
	Timeout: 30 * time.Second,
}

Functions

func FetchSpotifyClientToken

func FetchSpotifyClientToken() (spotifyprivateapi.ResponseClientToken, error)

The function `FetchSpotifyClientToken` fetches a Spotify client token from a specific URL and returns it as a response along with any errors encountered.

func GetFormatedTime

func GetFormatedTime() string

func GetSpotifyClientId

func GetSpotifyClientId() (spotifyprivateapi.ResponseClientId, error)

The function `GetSpotifyClientId` sends a POST request to the Spotify API to retrieve a client ID.

func GetSpotifyClientToken

func GetSpotifyClientToken() (spotifyprivateapi.ResponseClientToken, error)

The function `GetSpotifyClientToken` checks if a Spotify client token is saved in a file, and if not, fetches a new token and saves it.

func LogDebug

func LogDebug(message string)

func LogError

func LogError(message string)

func LogInfo

func LogInfo(message string)

func SetHeadersForSpotifyRequest

func SetHeadersForSpotifyRequest(req *http.Request) (*http.Request, error)

The function `SetHeadersForSpotifyRequest` sets the necessary headers for making a request to the Spotify API.

Types

type Client

type Client struct {
	Debug bool // false
}

The above code defines a struct type called "Client" with a boolean field called "Debug". @property {bool} Debug - The `Debug` property is a boolean value that indicates whether debugging mode is enabled or not. If `Debug` is set to `true`, it means that debugging mode is enabled. If `Debug` is set to `false`, it means that debugging mode is disabled.

func NewClient

func NewClient(options Client) *Client

The NewClient function creates a new client object with the specified options.

func (*Client) FetchAlbum added in v1.0.3

func (c *Client) FetchAlbum(albumId string) (responseTypes.AlbumResponseType, error)

The `FetchAlbum` function is a method of the `Client` struct in the `spotifyprivateapi` package. It is used to fetch information about an album from Spotify's private API. It takes an albumId parameter, which is the Spotify ID of the album. The function returns an AlbumResponseType object and an error.

func (*Client) FetchArtist added in v1.0.5

func (c *Client) FetchArtist(artistId string) (responseTypes.ArtistResponseType, error)

The `FetchArtist` function is a method of the `Client` struct in the `spotifyprivateapi` package. It is used to fetch information about an artist from Spotify's private API. It takes an artistId parameter, which is the Spotify ID of the artist. The function returns an Artist object and an error.

func (*Client) FetchTrack

func (c *Client) FetchTrack(trackId string) (responseTypes.TrackResponse, error)

FetchTrack fetches information about a track from Spotify's private API. It takes a trackId parameter, which is the Spotify ID of the track. The function returns a TrackResponse object and an error.

func (*Client) FetchTrackPlayCount

func (c *Client) FetchTrackPlayCount(trackId string) (responseTypes.TrackPlayCount, error)

FetchTrackPlayCount retrieves the play count for a track. It takes a trackId parameter, which is the Spotify ID of the track. The function internally calls the FetchTrack function to fetch the track information and then extracts the play count from the response. It returns a TrackPlayCount object and an error.

func (*Client) Search added in v1.0.8

func (c *Client) Search(sentence string) (responseTypes.SearchResponseType, error)

The `Search` function is a method of the `Client` struct in the `spotifyprivateapi` package. It is used to search for a term using Spotify's private API. It takes a `sentence` parameter, which is the search term to search for, and a `onlyTopResults` parameter, which is a boolean that specifies whether to only return the top results. The function returns a `SearchResponseType` object and an error.

func (*Client) SearchTopResult added in v1.0.8

func (c *Client) SearchTopResult(sentence string) (responseTypes.SearchTopResultsResponseType, error)

The `SearchTopResult` function is a method of the `Client` struct in the `spotifyprivateapi` package. It is used to search for a term using Spotify's private API and return only the top results. It takes a `sentence` parameter, which is the search term to search for. The function returns a `SearchTopResultsResponseType` object and an error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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