mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2025-12-13 13:38:16 +08:00
music id match up
This commit is contained in:
@@ -5,12 +5,15 @@ import (
|
||||
"fmt"
|
||||
"github.com/tidwall/gjson"
|
||||
"net/url"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
type Bilibili struct {
|
||||
InfoApi string
|
||||
FileApi string
|
||||
SearchApi string
|
||||
IdRegex0 *regexp.Regexp
|
||||
IdRegex1 *regexp.Regexp
|
||||
}
|
||||
|
||||
func _newBilibili() *Bilibili {
|
||||
@@ -18,6 +21,8 @@ func _newBilibili() *Bilibili {
|
||||
InfoApi: "https://www.bilibili.com/audio/music-service-c/web/song/info?sid=%s",
|
||||
FileApi: "https://api.bilibili.com/audio/music-service-c/url?device=phone&mid=8047632&mobi_app=iphone&platform=ios&privilege=2&songid=%s&quality=2",
|
||||
SearchApi: "https://api.bilibili.com/audio/music-service-c/s?search_type=music&keyword=%s&page=1&pagesize=100",
|
||||
IdRegex0: regexp.MustCompile("^[0-9]+"),
|
||||
IdRegex1: regexp.MustCompile("^au[0-9]+"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +37,26 @@ func (b *Bilibili) GetName() string {
|
||||
return "bilibili"
|
||||
}
|
||||
|
||||
func (b *Bilibili) MatchMedia(keyword string) *player.Media {
|
||||
if id := b.IdRegex0.FindString(keyword); id != "" {
|
||||
return &player.Media{
|
||||
Meta: Meta{
|
||||
Name: b.GetName(),
|
||||
Id: id,
|
||||
},
|
||||
}
|
||||
}
|
||||
if id := b.IdRegex1.FindString(keyword); id != "" {
|
||||
return &player.Media{
|
||||
Meta: Meta{
|
||||
Name: b.GetName(),
|
||||
Id: id[2:],
|
||||
},
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Bilibili) FormatPlaylistUrl(uri string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ type Kuwo struct {
|
||||
PlaylistApi string
|
||||
PlaylistRegex0 *regexp.Regexp
|
||||
PlaylistRegex1 *regexp.Regexp
|
||||
IdRegex0 *regexp.Regexp
|
||||
IdRegex1 *regexp.Regexp
|
||||
}
|
||||
|
||||
func _newKuwo() *Kuwo {
|
||||
@@ -32,6 +34,8 @@ func _newKuwo() *Kuwo {
|
||||
PlaylistApi: "http://www.kuwo.cn/api/www/playlist/playListInfo?pid=%s&pn=%d&rn=%d&httpsStatus=1",
|
||||
PlaylistRegex0: regexp.MustCompile("[0-9]+"),
|
||||
PlaylistRegex1: regexp.MustCompile("playlist/[0-9]+"),
|
||||
IdRegex0: regexp.MustCompile("^[0-9]+"),
|
||||
IdRegex1: regexp.MustCompile("^kw[0-9]+"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +50,26 @@ func (k *Kuwo) GetName() string {
|
||||
return "kuwo"
|
||||
}
|
||||
|
||||
func (k *Kuwo) MatchMedia(keyword string) *player.Media {
|
||||
if id := k.IdRegex0.FindString(keyword); id != "" {
|
||||
return &player.Media{
|
||||
Meta: Meta{
|
||||
Name: k.GetName(),
|
||||
Id: id,
|
||||
},
|
||||
}
|
||||
}
|
||||
if id := k.IdRegex1.FindString(keyword); id != "" {
|
||||
return &player.Media{
|
||||
Meta: Meta{
|
||||
Name: k.GetName(),
|
||||
Id: id[2:],
|
||||
},
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k *Kuwo) FormatPlaylistUrl(uri string) string {
|
||||
var id string
|
||||
id = k.PlaylistRegex0.FindString(uri)
|
||||
|
||||
@@ -15,6 +15,8 @@ type Netease struct {
|
||||
PlaylistRegex0 *regexp.Regexp
|
||||
PlaylistRegex1 *regexp.Regexp
|
||||
ReqData neteaseUtil.RequestData
|
||||
IdRegex0 *regexp.Regexp
|
||||
IdRegex1 *regexp.Regexp
|
||||
}
|
||||
|
||||
func _newNetease() *Netease {
|
||||
@@ -30,6 +32,8 @@ func _newNetease() *Netease {
|
||||
},
|
||||
},
|
||||
},
|
||||
IdRegex0: regexp.MustCompile("^[0-9]+"),
|
||||
IdRegex1: regexp.MustCompile("^wy[0-9]+"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +56,26 @@ func (n *Netease) GetName() string {
|
||||
return "netease"
|
||||
}
|
||||
|
||||
func (n *Netease) MatchMedia(keyword string) *player.Media {
|
||||
if id := n.IdRegex0.FindString(keyword); id != "" {
|
||||
return &player.Media{
|
||||
Meta: Meta{
|
||||
Name: n.GetName(),
|
||||
Id: id,
|
||||
},
|
||||
}
|
||||
}
|
||||
if id := n.IdRegex1.FindString(keyword); id != "" {
|
||||
return &player.Media{
|
||||
Meta: Meta{
|
||||
Name: n.GetName(),
|
||||
Id: id[2:],
|
||||
},
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *Netease) FormatPlaylistUrl(uri string) string {
|
||||
var id string
|
||||
id = n.PlaylistRegex0.FindString(uri)
|
||||
|
||||
@@ -19,6 +19,7 @@ type Meta struct {
|
||||
|
||||
type MediaProvider interface {
|
||||
GetName() string
|
||||
MatchMedia(keyword string) *player.Media
|
||||
GetPlaylist(playlist Meta) ([]*player.Media, error)
|
||||
FormatPlaylistUrl(uri string) string
|
||||
Search(keyword string) ([]*player.Media, error)
|
||||
|
||||
Reference in New Issue
Block a user