|
|
|
@ -10,21 +10,14 @@ import (
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
url string
|
|
|
|
|
folderTitleUrl string
|
|
|
|
|
max int
|
|
|
|
|
output string
|
|
|
|
|
chapter int
|
|
|
|
|
host = "https://img4.qy0.ru"
|
|
|
|
|
)
|
|
|
|
|
func Execute() {
|
|
|
|
|
rootCmd := NewRootCmd()
|
|
|
|
|
CommandInit(rootCmd)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
rootCmd.PersistentFlags().StringVarP(&url, "url", "u", "", "除域名外的链接")
|
|
|
|
|
rootCmd.PersistentFlags().IntVarP(&max, "max", "m", 1, "图片最大值")
|
|
|
|
|
rootCmd.PersistentFlags().StringVarP(&output, "output", "o", "anime", "设置漫画抓取结果的保存位置,默认为当前用户的主目录下的 anime 文件夹")
|
|
|
|
|
rootCmd.PersistentFlags().StringVarP(&folderTitleUrl, "folderTitleUrl", "t", "", "文件夹标题抓取链接")
|
|
|
|
|
rootCmd.PersistentFlags().IntVarP(&chapter, "chapter", "c", 1, "指定章节,用于文件夹标题抓取")
|
|
|
|
|
if err := rootCmd.Execute(); err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func IfPathNotExistDoMkdir(path string) error {
|
|
|
|
@ -39,13 +32,6 @@ func IfPathNotExistDoMkdir(path string) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Execute() {
|
|
|
|
|
if err := rootCmd.Execute(); err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FindChapterTitle 解析文件夹标题
|
|
|
|
|
func FindChapterTitle(url string) string {
|
|
|
|
|
resp, err := http.Get(url)
|
|
|
|
@ -68,7 +54,7 @@ func FindChapterTitle(url string) string {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
re := regexp.MustCompile(`\\u7b2c` + strconv.Itoa(chapter) + `\\u8bdd (.+?)"`)
|
|
|
|
|
re := regexp.MustCompile(`\\u7b2c` + strconv.Itoa(config.chapter) + `\\u8bdd (.+?)"`)
|
|
|
|
|
matches := re.FindAllStringSubmatch(string(body), -1)
|
|
|
|
|
|
|
|
|
|
if len(matches) == 0 {
|
|
|
|
|