spotify

package module
v0.0.0-...-a268b5b Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PlaylistPageLimit     = 50
	PlaylistPageMaxOffset = 1000
)

Paging of playlist searching https://developer.spotify.com/documentation/web-api/reference/#/operations/search

View Source
const SeenDebug = false
View Source
const (
	TracksPageLimit = 50
)
View Source
const (
	UpdateTracksBatchSize = 32 // < 50

)

Variables

View Source
var AuthHolder = &authHolder{}

AuthHolder global spotify token holder 单例

View Source
var Config struct {
	ClientID            string   `json:"client_id"`
	ClientSecret        string   `json:"client_secret"`
	DB                  string   `json:"db"`
	Profile             string   `json:"profile"`
	Seed                string   `json:"seed"`
	Playlists           int      `json:"playlists"`
	SeenWords           []string `json:"seen_words"`
	UpdateTracksWorkers int      `json:"update_tracks_workers"`
}
View Source
var DB *gorm.DB

DB 全局的数据库单例

View Source
var ErrTrackNotFound = errors.New("no matching track")
View Source
var SearchTrackLimit = 5

Functions

func ChineseStringEqual

func ChineseStringEqual(a, b string) bool

ChineseStringEqual checks if string a == b **in Chinese**. It converts traditional Chinese text into simplified Chinese if necessary. lower/upper and Punct chars will be ignored. 繁简混合的情况下 a 繁、b 简 比较快。 For example:

ChineseStringEqual("自然語言處理", "自然语言处理") == true

See Also: cc_benchmark_test.go

func ComplementTracksImage

func ComplementTracksImage()

ComplementTracksImage is an instance of UpdateTracks to complement Tracks' ImageUrl fields.

func CrawlPlaylistsAndTracks

func CrawlPlaylistsAndTracks(seed string, maxNum int)

CrawlPlaylistsAndTracks 从 seed 开始,获取 maxNum 个包含这个单词的播放列表。

计算这些列表中所有单词出现的频次。 然后对列表中出现次数最多的单词执行相同的操作。 重复,知道获取到足够的列表。

func FetchTracks

func FetchTracks(client *spotify.Client, playlist *spotify.SimplePlaylist) <-chan spotify.FullTrack

FetchTracks 获取给定的 playlist 中的曲目

返回一个出 spotify.SimpleTrack 的 chan (带缓冲: size = TracksPageLimit),结果这个 chan 传

func FindPlaylist

func FindPlaylist(client *spotify.Client, w string) <-chan spotify.SimplePlaylist

FindPlaylist 获取匹配搜索项 w 的所有播放列表

返回一个出 spotify.SimplePlaylist 的 chan (带缓冲: size = PlaylistPageLimit),结果这个 chan 传

func InitAll

func InitAll(configfile string)

func InitAuth

func InitAuth()

func InitConfig

func InitConfig(configfile string)

InitConfig read the config file

func InitDB

func InitDB()

InitDB 初始化 DB

func InitSeenPlaylists

func InitSeenPlaylists()

InitSeenPlaylists 初始化已见播放列表. After InitConfig & InitDB

func InitSeenWords

func InitSeenWords()

InitSeenWords 初始化已见词表. After InitConfig

func InitT2S

func InitT2S() error

InitT2S 初始化简繁转化器 t2s。 默认懒汉调用,但暴露出来提供饿汉支持。

func NewSpotifyClient

func NewSpotifyClient() *spotify.Client

func RemovePunct

func RemovePunct(s string) string

func Save

func Save(playlist *Playlist)

Save 在一次事物中保存播放列表及其中所有曲目

func SeenPlaylist

func SeenPlaylist(id string) bool

func SeenWord

func SeenWord(w string) bool

SeenWord 返回 false 若没见过 w,同时把 w 标记为见过

Example:

w := "notSeen"
SeenWord(w) // false
SeenWord(w) // true

func T2S

func T2S(t string) (string, error)

T2S converts Traditional Chinese to Simplified Chinese 繁 => 简

func UpdateTracks

func UpdateTracks(where string)

UpdateTracks 请求 spotify,更新数据库中所有 Track 的数据。 where 是数据库取 Track 的 where 查询条件。

也可用于在数据库新增字段后,补充之前的记录。

Types

type Artist

type Artist struct {
	Name string `json:"name"`
	ID   string `json:"id" gorm:"primaryKey"`
	URI  string `json:"uri"`
}

type AudioFeatures

type AudioFeatures = spotify.AudioFeatures

func GetAudioFeatures

func GetAudioFeatures(client *spotify.Client, trackIds ...string) ([]*AudioFeatures, error)

type AuthError

type AuthError struct {
	Field   string      // 失败的地方
	Err     error       // 遇到的错误
	Context interface{} // 附加的信息
}

AuthError Spotify 认证失败

func (AuthError) Error

func (a AuthError) Error() string

type AuthResp

type AuthResp struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	ExpiresIn   int    `json:"expires_in"`
}

AuthResp is the response of Auth

func Auth

func Auth(clientId, clientSecret string) (*AuthResp, error)

Auth authenticate using a client credentials flow

type Playlist

type Playlist struct {
	Collaborative bool    `json:"collaborative"`
	Endpoint      string  `json:"href"`
	ID            string  `json:"id" gorm:"primaryKey"`
	Name          string  `json:"name"`
	IsPublic      bool    `json:"public"`
	SnapshotID    string  `json:"snapshot_id"`
	URI           string  `json:"uri"`
	Tracks        []Track `json:"my_tracks" gorm:"many2many:playlist_tracks"`
}

Playlist 是 spotify.SimplePlaylist 删掉不要的字段

func PlaylistFromSpotify

func PlaylistFromSpotify(sp spotify.SimplePlaylist, sts []spotify.FullTrack) *Playlist

type Track

type Track struct {
	Artist      []Artist `json:"artists" gorm:"many2many:track_artists"`
	DiscNumber  int      `json:"disc_number"`
	Duration    int      `json:"duration_ms"`
	Explicit    bool     `json:"explicit"`
	Endpoint    string   `json:"href"`
	ID          string   `json:"id"  gorm:"primaryKey"`
	Name        string   `json:"name"`
	PreviewURL  string   `json:"preview_url"`
	TrackNumber int      `json:"track_number"`
	URI         string   `json:"uri"`
	Type        string   `json:"type"`
	ImageUrl    string   `json:"image_url"`
}

func SearchTrack

func SearchTrack(client *spotify.Client, query *TrackQuery) (*Track, error)

func SpotifyRecommendTracks

func SpotifyRecommendTracks(client *spotify.Client, seedTrackIds []string, limit int) ([]*Track, error)

type TrackQuery

type TrackQuery struct {
	TrackName string
	Artists   []string
}

func (TrackQuery) String

func (q TrackQuery) String() string

Directories

Path Synopsis
Package priority implements a PriorityQueue
Package priority implements a PriorityQueue

Jump to

Keyboard shortcuts

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