mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2025-12-13 21:48:30 +08:00
add search for bilivideo
This commit is contained in:
@@ -199,7 +199,7 @@ func registerPlayControllerHandler() {
|
|||||||
PlayController.SetDefaultCover()
|
PlayController.SetDefaultCover()
|
||||||
} else {
|
} else {
|
||||||
uri, err := storage.ParseURI(media.Cover)
|
uri, err := storage.ParseURI(media.Cover)
|
||||||
if err != nil {
|
if err != nil || uri == nil {
|
||||||
l().Warn("fail to load parse cover url", media.Cover)
|
l().Warn("fail to load parse cover url", media.Cover)
|
||||||
}
|
}
|
||||||
// async update
|
// async update
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,7 +24,7 @@ func _newBilibiliVideo() *BilibiliVideo {
|
|||||||
return &BilibiliVideo{
|
return &BilibiliVideo{
|
||||||
InfoApi: "https://api.bilibili.com/x/web-interface/view/detail?bvid=%s&aid=&jsonp=jsonp",
|
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",
|
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]+"),
|
BVRegex: regexp.MustCompile("^BV[0-9A-Za-z]+"),
|
||||||
IdRegex: regexp.MustCompile("^BV[0-9A-Za-z]+(\\?p=[0-9]+)?"),
|
IdRegex: regexp.MustCompile("^BV[0-9A-Za-z]+(\\?p=[0-9]+)?"),
|
||||||
PageRegex: regexp.MustCompile("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) {
|
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 {
|
func (b *BilibiliVideo) UpdateMedia(media *player.Media) error {
|
||||||
|
|||||||
@@ -84,3 +84,16 @@ func TestBV_GetMusic2(t *testing.T) {
|
|||||||
//fmt.Println(media)
|
//fmt.Println(media)
|
||||||
fmt.Println(media.Url)
|
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
|
package provider
|
||||||
|
|
||||||
import "AynaLivePlayer/player"
|
import (
|
||||||
|
"AynaLivePlayer/config"
|
||||||
|
"AynaLivePlayer/player"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type _LocalPlaylist struct {
|
||||||
|
Name string
|
||||||
|
Medias []*player.Media
|
||||||
|
}
|
||||||
|
|
||||||
type Local struct {
|
type Local struct {
|
||||||
|
Playlists []_LocalPlaylist
|
||||||
}
|
}
|
||||||
|
|
||||||
var LocalAPI *Local
|
var LocalAPI *Local
|
||||||
@@ -13,12 +23,26 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func _newLocal() *Local {
|
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 {
|
func (l *Local) GetName() string {
|
||||||
return "local"
|
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 {
|
func (l *Local) FormatPlaylistUrl(uri string) string {
|
||||||
return ""
|
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