允许通过参数输入番号,provider使用source作为数据源
parent
d548495ce8
commit
d59ccbe014
|
|
@ -2,8 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// epDataProvider中
|
// epDataProvider中
|
||||||
|
|
@ -33,8 +31,8 @@ type AVResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAVData 根据videoNo从bilibili获取av数据
|
// GetAVData 根据videoNo从bilibili获取av数据
|
||||||
func (*episodeDataProvider) GetAVData(avNo int64) (avdatas []AVData, err error) {
|
func (provider *episodeDataProvider) GetAVData(avNo int64) (avdatas []AVData, err error) {
|
||||||
file, err := ioutil.ReadFile("mock/av" + strconv.FormatInt(avNo, 10) + ".json")
|
file, err := provider.dataSource.GetAVData(avNo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return avdatas, err
|
return avdatas, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
epsource.go
11
epsource.go
|
|
@ -3,7 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
@ -44,8 +43,8 @@ type SectionResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetEPData 根据videoNo从bilibili获取av数据
|
// GetEPData 根据videoNo从bilibili获取av数据
|
||||||
func (*episodeDataProvider) GetEPData(epNo int64) (epdatas []EPData, err error) {
|
func (provider *episodeDataProvider) GetEPData(epNo int64) (epdatas []EPData, err error) {
|
||||||
htmlByte, err := ioutil.ReadFile("mock/ep" + strconv.FormatInt(epNo, 10) + ".html")
|
htmlByte, err := provider.dataSource.GetEPData(epNo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -59,7 +58,11 @@ func (*episodeDataProvider) GetEPData(epNo int64) (epdatas []EPData, err error)
|
||||||
return epdatas, errors.New("ssid not found")
|
return epdatas, errors.New("ssid not found")
|
||||||
}
|
}
|
||||||
ssid := string(ssidResult)[7:]
|
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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
73
main.go
73
main.go
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/yinhui87/go-component/language"
|
"github.com/yinhui87/go-component/language"
|
||||||
)
|
)
|
||||||
|
|
@ -11,11 +13,43 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
dataSource := new(mockSource)
|
dataSource := new(mockSource)
|
||||||
episodeProvider := NewEpisodeDataProvider(dataSource)
|
episodeProvider := NewEpisodeDataProvider(dataSource)
|
||||||
epdatas, err := episodeProvider.GetEpisodeData("av1742161", 143, 147)
|
params := os.Args[1:]
|
||||||
// epdatas, err := getEPData(episodeProvider, "ep173262")
|
var epdatas []episode
|
||||||
if err != nil {
|
if len(params) > 0 {
|
||||||
panic(err)
|
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 {
|
for i, epdata := range epdatas {
|
||||||
fmt.Printf("%dep %d Cid: %v, Title: %s\n", i, epdata.Index, epdata.Cid, epdata.Title)
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if len(filenames) != len(epdatas) {
|
length := len(filenames)
|
||||||
panic(fmt.Errorf("file count[%d] diff with epdata count[%d]", len(filenames), len(epdatas)))
|
if len(epdatas) < length {
|
||||||
|
length = len(epdatas)
|
||||||
}
|
}
|
||||||
for i := 0; i < len(filenames); i++ {
|
for i := 0; i < length; i++ {
|
||||||
epdata := epdatas[i]
|
epdata := epdatas[i]
|
||||||
fmt.Printf("file %s cid[%d] title is %s\n", filenames[i], epdata.Cid, epdata.Title)
|
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]))
|
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)
|
fmt.Println("rename ", filenames[i], " to ", newName)
|
||||||
os.Rename(filenames[i], newName)
|
os.Rename(filenames[i], newName)
|
||||||
}
|
}
|
||||||
|
|
@ -41,21 +83,30 @@ func getFileList() (filenames []string, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer pwd.Close()
|
||||||
files, err := pwd.Readdir(0)
|
files, err := pwd.Readdir(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fileTimeMap := make(map[int]string)
|
fileinfoTimeMap := make(map[int]os.FileInfo)
|
||||||
var fileTimes []int
|
var fileTimes []int
|
||||||
for _, fileInfo := range files {
|
for _, fileInfo := range files {
|
||||||
if !fileInfo.IsDir() {
|
if !fileInfo.IsDir() {
|
||||||
fileTimeMap[int(fileInfo.ModTime().Unix())] = fileInfo.Name()
|
fileinfoTimeMap[int(fileInfo.ModTime().Unix())] = fileInfo
|
||||||
fileTimes = append(fileTimes, int(fileInfo.ModTime().Unix()))
|
fileTimes = append(fileTimes, int(fileInfo.ModTime().Unix()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fileTimes = language.ArraySort(fileTimes).([]int)
|
fileTimes = language.ArraySort(fileTimes).([]int)
|
||||||
for _, t := range fileTimes {
|
for i, t := range fileTimes {
|
||||||
filenames = append(filenames, fileTimeMap[t])
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue