添加了bilibili数据源
parent
d3075883b5
commit
3dc30135db
|
|
@ -1 +1,2 @@
|
|||
rename
|
||||
testdata
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// BilibiliSource bilibili数据源
|
||||
type BilibiliSource struct{}
|
||||
|
||||
// GetAVData 获取av视频的数据源
|
||||
func (source *BilibiliSource) GetAVData(avNo int64) (avdata []byte, err error) {
|
||||
resp, err := http.DefaultClient.Get(fmt.Sprintf("https://api.bilibili.com/x/player/pagelist?aid=%d&jsonp=jsonp", avNo))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
avdata, err = ioutil.ReadAll(resp.Body)
|
||||
return
|
||||
}
|
||||
|
||||
// GetEPData 获取ep视频的数据源
|
||||
func (source *BilibiliSource) GetEPData(epNo int64) (epdata []byte, err error) {
|
||||
resp, err := http.DefaultClient.Get(fmt.Sprintf("https://www.bilibili.com/bangumi/play/ep%d", epNo))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
epdata, err = ioutil.ReadAll(resp.Body)
|
||||
return
|
||||
}
|
||||
|
||||
// GetSSData 获取ss视频的数据源
|
||||
func (source *BilibiliSource) GetSSData(ssNo int64) (ssdata []byte, err error) {
|
||||
resp, err := http.DefaultClient.Get(fmt.Sprintf("https://api.bilibili.com/pgc/web/season/section?season_id=%d&season_type=1", ssNo))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
ssdata, err = ioutil.ReadAll(resp.Body)
|
||||
return
|
||||
}
|
||||
5
main.go
5
main.go
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
|
@ -11,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
dataSource := new(mockSource)
|
||||
dataSource := new(BilibiliSource)
|
||||
episodeProvider := NewEpisodeDataProvider(dataSource)
|
||||
params := os.Args[1:]
|
||||
var epdatas []episode
|
||||
|
|
@ -67,7 +68,7 @@ func main() {
|
|||
fmt.Printf("file %s cid[%d] title is %s\n", filenames[i], epdata.Cid, epdata.Title)
|
||||
newName := fmt.Sprintf("%s%s", epdata.Title, path.Ext(filenames[i]))
|
||||
if len(params) > 1 {
|
||||
if strings.Contains(params[1], `%d`) {
|
||||
if match, _ := regexp.MatchString(".*%\\d*d.*", params[1]); match {
|
||||
newName = fmt.Sprintf(params[1], i+1, newName)
|
||||
} else {
|
||||
newName = fmt.Sprintf(params[1], newName)
|
||||
|
|
|
|||
Loading…
Reference in New Issue