forked from metafates/mangal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapter.go
40 lines (33 loc) · 1.02 KB
/
chapter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package update
import (
"github.com/metafates/mangal/constant"
"github.com/metafates/mangal/filesystem"
"github.com/metafates/mangal/log"
"os"
"path/filepath"
)
type downloadedChapter struct {
path string
format string
}
func getChapters(manga string) ([]*downloadedChapter, error) {
log.Infof("getting chapters for %s", manga)
var chapters []*downloadedChapter
err := filesystem.Api().Walk(manga, func(path string, info os.FileInfo, err error) error {
// we will ignore plain chapter (aka folder ones) for the sake of simplicity
if info.IsDir() {
return nil
}
name := info.Name()
switch filepath.Ext(name)[1:] {
case constant.FormatCBZ:
chapters = append(chapters, &downloadedChapter{path: path, format: constant.FormatCBZ})
case constant.FormatPDF:
chapters = append(chapters, &downloadedChapter{path: path, format: constant.FormatPDF})
case constant.FormatZIP:
chapters = append(chapters, &downloadedChapter{path: path, format: constant.FormatZIP})
}
return nil
})
return chapters, err
}