允许通过参数输入番号,provider使用source作为数据源
parent
d548495ce8
commit
d59ccbe014
|
|
@ -2,8 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// epDataProvider中
|
||||
|
|
@ -33,8 +31,8 @@ type AVResponse struct {
|
|||
}
|
||||
|
||||
// GetAVData 根据videoNo从bilibili获取av数据
|
||||
func (*episodeDataProvider) GetAVData(avNo int64) (avdatas []AVData, err error) {
|
||||
file, err := ioutil.ReadFile("mock/av" + strconv.FormatInt(avNo, 10) + ".json")
|
||||
func (provider *episodeDataProvider) GetAVData(avNo int64) (avdatas []AVData, err error) {
|
||||
file, err := provider.dataSource.GetAVData(avNo)
|
||||
if err != nil {
|
||||
return avdatas, err
|
||||
}
|
||||
|
|
|
|||
11
epsource.go
11
epsource.go
|
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"regexp"
|
||||
"strconv"
|
||||
)
|
||||
|
|
@ -44,8 +43,8 @@ type SectionResponse struct {
|
|||
}
|
||||
|
||||
// GetEPData 根据videoNo从bilibili获取av数据
|
||||
func (*episodeDataProvider) GetEPData(epNo int64) (epdatas []EPData, err error) {
|
||||
htmlByte, err := ioutil.ReadFile("mock/ep" + strconv.FormatInt(epNo, 10) + ".html")
|
||||
func (provider *episodeDataProvider) GetEPData(epNo int64) (epdatas []EPData, err error) {
|
||||
htmlByte, err := provider.dataSource.GetEPData(epNo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -59,7 +58,11 @@ func (*episodeDataProvider) GetEPData(epNo int64) (epdatas []EPData, err error)
|
|||
return epdatas, errors.New("ssid not found")
|
||||
}
|
||||
ssid := string(ssidResult)[7:]
|
||||
ssByte, err := ioutil.ReadFile("mock/ss" + ssid + ".json")
|
||||
ssNo, err := strconv.ParseInt(ssid, 10, 64)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ssByte, err := provider.dataSource.GetSSData(ssNo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
69
main.go
69
main.go
|
|
@ -4,6 +4,8 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/yinhui87/go-component/language"
|
||||
)
|
||||
|
|
@ -11,11 +13,43 @@ import (
|
|||
func main() {
|
||||
dataSource := new(mockSource)
|
||||
episodeProvider := NewEpisodeDataProvider(dataSource)
|
||||
epdatas, err := episodeProvider.GetEpisodeData("av1742161", 143, 147)
|
||||
// epdatas, err := getEPData(episodeProvider, "ep173262")
|
||||
params := os.Args[1:]
|
||||
var epdatas []episode
|
||||
if len(params) > 0 {
|
||||
var skipEps []int64
|
||||
var err error
|
||||
if len(params) > 2 {
|
||||
// 处理如果有跳过的情况
|
||||
for _, param := range params[2:] {
|
||||
if sped := strings.Split(param, "-"); len(sped) == 2 {
|
||||
// 兼容1-10这样的批量写法
|
||||
skepStart, err := strconv.ParseInt(sped[0], 10, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
skepEnd, err := strconv.ParseInt(sped[1], 10, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for i := skepStart; i <= skepEnd; i++ {
|
||||
skipEps = append(skipEps, i)
|
||||
}
|
||||
} else {
|
||||
skipEp, err := strconv.ParseInt(param, 10, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
skipEps = append(skipEps, skipEp)
|
||||
}
|
||||
}
|
||||
}
|
||||
epdatas, err = episodeProvider.GetEpisodeData(params[0], skipEps...)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
// epdatas, err := episodeProvider.GetEpisodeData("av1742161", 143, 147)
|
||||
// epdatas, err := episodeProvider.GetEpisodeData("ep173262")
|
||||
for i, epdata := range epdatas {
|
||||
fmt.Printf("%dep %d Cid: %v, Title: %s\n", i, epdata.Index, epdata.Cid, epdata.Title)
|
||||
}
|
||||
|
|
@ -24,13 +58,21 @@ func main() {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if len(filenames) != len(epdatas) {
|
||||
panic(fmt.Errorf("file count[%d] diff with epdata count[%d]", len(filenames), len(epdatas)))
|
||||
length := len(filenames)
|
||||
if len(epdatas) < length {
|
||||
length = len(epdatas)
|
||||
}
|
||||
for i := 0; i < len(filenames); i++ {
|
||||
for i := 0; i < length; i++ {
|
||||
epdata := epdatas[i]
|
||||
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`) {
|
||||
newName = fmt.Sprintf(params[1], i+1, newName)
|
||||
} else {
|
||||
newName = fmt.Sprintf(params[1], newName)
|
||||
}
|
||||
}
|
||||
fmt.Println("rename ", filenames[i], " to ", newName)
|
||||
os.Rename(filenames[i], newName)
|
||||
}
|
||||
|
|
@ -41,21 +83,30 @@ func getFileList() (filenames []string, err error) {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer pwd.Close()
|
||||
files, err := pwd.Readdir(0)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fileTimeMap := make(map[int]string)
|
||||
fileinfoTimeMap := make(map[int]os.FileInfo)
|
||||
var fileTimes []int
|
||||
for _, fileInfo := range files {
|
||||
if !fileInfo.IsDir() {
|
||||
fileTimeMap[int(fileInfo.ModTime().Unix())] = fileInfo.Name()
|
||||
fileinfoTimeMap[int(fileInfo.ModTime().Unix())] = fileInfo
|
||||
fileTimes = append(fileTimes, int(fileInfo.ModTime().Unix()))
|
||||
}
|
||||
}
|
||||
fileTimes = language.ArraySort(fileTimes).([]int)
|
||||
for _, t := range fileTimes {
|
||||
filenames = append(filenames, fileTimeMap[t])
|
||||
for i, t := range fileTimes {
|
||||
fileinfo := fileinfoTimeMap[t]
|
||||
filenames = append(filenames, fileinfo.Name())
|
||||
if i > 0 {
|
||||
// 检测是否有相同大小的相邻文件,极有可能为下载错误下了一样的
|
||||
oldinfo := fileinfoTimeMap[fileTimes[i-1]]
|
||||
if fileinfo.Size() == oldinfo.Size() {
|
||||
fmt.Printf("warning: %s(%s) size is same with %s(%s)\n", oldinfo.Name(), oldinfo.ModTime().Format("2006-01-02 15:04:05"), fileinfo.Name(), fileinfo.ModTime().Format("2006-01-02 15:04:05"))
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue