修复封面命名逻辑存在的问题
This commit is contained in:
parent
185a1bad1c
commit
0e6e964b70
21
crawler.go
21
crawler.go
@ -131,28 +131,31 @@ func (c *Crawler) fetchCoverImg(code string) error {
|
||||
imgUrl := strings.ReplaceAll(c.config.GetString("crawler.url"), `*`, code)
|
||||
suffix := filepath.Ext(imgUrl)
|
||||
|
||||
offset := 0
|
||||
startOffset := 0
|
||||
// 如果第一个字符为 '1',则从下一个字符开始查找
|
||||
if len(code) > 0 && code[0] == '1' {
|
||||
offset = 1
|
||||
startOffset = 1
|
||||
}
|
||||
|
||||
// 获取号码所在的位置
|
||||
index := strings.Index(code[offset:], "00")
|
||||
if index == -1 {
|
||||
splitIndex := strings.Index(code[startOffset:], "00")
|
||||
if splitIndex == -1 || splitIndex+startOffset < 3 {
|
||||
return nil
|
||||
}
|
||||
// 计算原始字符串中的真实位置
|
||||
splitIndex += startOffset
|
||||
|
||||
// 分隔字母部分及数字部分
|
||||
letters := code[:index]
|
||||
num := code[index+2:]
|
||||
if offset > 0 {
|
||||
letters = code[1:index]
|
||||
letters := code[startOffset:splitIndex]
|
||||
numPart := code[splitIndex+2:]
|
||||
|
||||
if len(letters) == 0 || len(numPart) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
fileName := filepath.Join(c.outputPath, fmt.Sprintf("%s-%s%s",
|
||||
strings.ToUpper(letters),
|
||||
num,
|
||||
numPart,
|
||||
suffix,
|
||||
))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user