mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2025-12-12 21:28:11 +08:00
add search for bilivideo
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/tidwall/gjson"
|
||||
"net/url"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
@@ -23,7 +24,7 @@ func _newBilibiliVideo() *BilibiliVideo {
|
||||
return &BilibiliVideo{
|
||||
InfoApi: "https://api.bilibili.com/x/web-interface/view/detail?bvid=%s&aid=&jsonp=jsonp",
|
||||
FileApi: "https://api.bilibili.com/x/player/playurl?type=&otype=json&fourk=1&qn=32&avid=&bvid=%s&cid=%s",
|
||||
SearchApi: "",
|
||||
SearchApi: "https://api.bilibili.com/x/web-interface/search/type?search_type=video&page=1&keyword=%s",
|
||||
BVRegex: regexp.MustCompile("^BV[0-9A-Za-z]+"),
|
||||
IdRegex: regexp.MustCompile("^BV[0-9A-Za-z]+(\\?p=[0-9]+)?"),
|
||||
PageRegex: regexp.MustCompile("p=[0-9]+"),
|
||||
@@ -78,7 +79,29 @@ func (b *BilibiliVideo) FormatPlaylistUrl(uri string) string {
|
||||
}
|
||||
|
||||
func (b *BilibiliVideo) Search(keyword string) ([]*player.Media, error) {
|
||||
return nil, ErrorExternalApi
|
||||
resp := httpGetString(fmt.Sprintf(b.SearchApi, url.QueryEscape(keyword)), nil)
|
||||
if resp == "" {
|
||||
return nil, ErrorExternalApi
|
||||
}
|
||||
jresp := gjson.Parse(resp)
|
||||
if jresp.Get("code").String() != "0" {
|
||||
return nil, ErrorExternalApi
|
||||
}
|
||||
result := make([]*player.Media, 0)
|
||||
r := regexp.MustCompile("</?em[^>]*>")
|
||||
jresp.Get("data.result").ForEach(func(key, value gjson.Result) bool {
|
||||
result = append(result, &player.Media{
|
||||
Title: r.ReplaceAllString(value.Get("title").String(), ""),
|
||||
Cover: "https:" + value.Get("pic").String(),
|
||||
Artist: value.Get("author").String(),
|
||||
Meta: Meta{
|
||||
Name: b.GetName(),
|
||||
Id: value.Get("bvid").String(),
|
||||
},
|
||||
})
|
||||
return true
|
||||
})
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (b *BilibiliVideo) UpdateMedia(media *player.Media) error {
|
||||
|
||||
@@ -84,3 +84,16 @@ func TestBV_GetMusic2(t *testing.T) {
|
||||
//fmt.Println(media)
|
||||
fmt.Println(media.Url)
|
||||
}
|
||||
|
||||
func TestBV_Search(t *testing.T) {
|
||||
var api MediaProvider = BilibiliVideoAPI
|
||||
result, err := api.Search("家有女友")
|
||||
if err != nil {
|
||||
fmt.Println(1, err)
|
||||
return
|
||||
}
|
||||
fmt.Println(len(result))
|
||||
for _, r := range result {
|
||||
fmt.Println(r.Artist)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
package provider
|
||||
|
||||
import "AynaLivePlayer/player"
|
||||
import (
|
||||
"AynaLivePlayer/config"
|
||||
"AynaLivePlayer/player"
|
||||
"os"
|
||||
)
|
||||
|
||||
type _LocalPlaylist struct {
|
||||
Name string
|
||||
Medias []*player.Media
|
||||
}
|
||||
|
||||
type Local struct {
|
||||
Playlists []_LocalPlaylist
|
||||
}
|
||||
|
||||
var LocalAPI *Local
|
||||
@@ -13,12 +23,26 @@ func init() {
|
||||
}
|
||||
|
||||
func _newLocal() *Local {
|
||||
return &Local{}
|
||||
l := &Local{Playlists: make([]_LocalPlaylist, 0)}
|
||||
if err := os.MkdirAll(config.Provider.LocalDir, 0755); err != nil {
|
||||
return l
|
||||
}
|
||||
|
||||
return l
|
||||
}
|
||||
|
||||
func (l *Local) GetName() string {
|
||||
return "local"
|
||||
}
|
||||
func (l *Local) MatchMedia(keyword string) *player.Media {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (l *Local) UpdateMediaLyric(media *player.Media) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (l *Local) FormatPlaylistUrl(uri string) string {
|
||||
return ""
|
||||
|
||||
25
provider/local_test.go
Normal file
25
provider/local_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLocal_Read(t *testing.T) {
|
||||
items, _ := ioutil.ReadDir(".")
|
||||
for _, item := range items {
|
||||
if item.IsDir() {
|
||||
subitems, _ := ioutil.ReadDir(item.Name())
|
||||
for _, subitem := range subitems {
|
||||
if !subitem.IsDir() {
|
||||
// handle file there
|
||||
fmt.Println(item.Name() + "/" + subitem.Name())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// handle file there
|
||||
fmt.Println(item.Name())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user