rename store to cache
This commit is contained in:
parent
81fd9dbcf4
commit
23eb6d131c
48
main.go
48
main.go
@ -23,23 +23,23 @@ import (
|
|||||||
"github.com/schollz/progressbar/v3"
|
"github.com/schollz/progressbar/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Store struct {
|
type Cache struct {
|
||||||
MostRecent string
|
MostRecent string
|
||||||
Pages int
|
Pages int
|
||||||
CID string
|
CID string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cacheFile = flag.String("cache", "~/.taldl/cache.json", "cache file")
|
||||||
|
var outputDir = flag.String("output", "~/TAL", "output directory")
|
||||||
|
var tmpDir = flag.String("tmpdir", "~/.taldl", "tmp directory")
|
||||||
|
|
||||||
var formats = flag.String("formats", "zip,epub,pdf,a4.pdf,lt.pdf", "formats to download.")
|
var formats = flag.String("formats", "zip,epub,pdf,a4.pdf,lt.pdf", "formats to download.")
|
||||||
var fullUpdate = flag.Bool("full", false, "check everything for modifications")
|
var fullUpdate = flag.Bool("full", false, "check everything for modifications")
|
||||||
var verbose = flag.Bool("verbose", false, "verbose")
|
var verbose = flag.Bool("verbose", false, "verbose")
|
||||||
var workers = flag.Int("workers", 1, "amount of workers")
|
var workers = flag.Int("workers", 1, "amount of workers")
|
||||||
|
|
||||||
var storeFile = flag.String("store", "~/.taldl/cache.json", "store file")
|
|
||||||
var outputDir = flag.String("output", "~/TAL", "output directory")
|
|
||||||
var tmpDir = flag.String("zipdir", "~/.taldl", "zip directory")
|
|
||||||
|
|
||||||
var ipfsEnabled = flag.Bool("ipfs", false, "pin to ipfs")
|
|
||||||
var ipfsAPI = flag.String("ipfs-api", "localhost:5001", "ipfs api")
|
var ipfsAPI = flag.String("ipfs-api", "localhost:5001", "ipfs api")
|
||||||
|
var ipfsEnabled = flag.Bool("ipfs", false, "pin to ipfs")
|
||||||
|
|
||||||
var hrefs = []string{}
|
var hrefs = []string{}
|
||||||
var hrefsMutex sync.Mutex
|
var hrefsMutex sync.Mutex
|
||||||
@ -48,14 +48,14 @@ var done bool
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
var store Store
|
var cache Cache
|
||||||
var last int
|
var last int
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
*storeFile = fixpath(*storeFile)
|
*cacheFile = fixpath(*cacheFile)
|
||||||
storeData, _ := ioutil.ReadFile(*storeFile)
|
cacheData, _ := ioutil.ReadFile(*cacheFile)
|
||||||
_ = json.Unmarshal(storeData, &store)
|
_ = json.Unmarshal(cacheData, &cache)
|
||||||
|
|
||||||
*outputDir = fixpath(*outputDir)
|
*outputDir = fixpath(*outputDir)
|
||||||
*tmpDir = fixpath(*tmpDir)
|
*tmpDir = fixpath(*tmpDir)
|
||||||
@ -83,7 +83,7 @@ func main() {
|
|||||||
mostRecent = href
|
mostRecent = href
|
||||||
}
|
}
|
||||||
|
|
||||||
if store.MostRecent == href && *fullUpdate == false {
|
if cache.MostRecent == href && *fullUpdate == false {
|
||||||
done = true
|
done = true
|
||||||
} else {
|
} else {
|
||||||
hrefs = append(hrefs, href)
|
hrefs = append(hrefs, href)
|
||||||
@ -102,7 +102,7 @@ func main() {
|
|||||||
if *fullUpdate {
|
if *fullUpdate {
|
||||||
newPages = last - 1
|
newPages = last - 1
|
||||||
} else {
|
} else {
|
||||||
newPages = last - store.Pages - 1
|
newPages = last - cache.Pages - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
bar.ChangeMax(1 + newPages)
|
bar.ChangeMax(1 + newPages)
|
||||||
@ -127,13 +127,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
store.Pages = last
|
cache.Pages = last
|
||||||
store.MostRecent = mostRecent
|
cache.MostRecent = mostRecent
|
||||||
|
|
||||||
numJobs := len(hrefs)
|
numJobs := len(hrefs)
|
||||||
|
|
||||||
if numJobs == 0 {
|
if numJobs == 0 {
|
||||||
save(store)
|
save(cache)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ func main() {
|
|||||||
bar.Finish()
|
bar.Finish()
|
||||||
|
|
||||||
if downloadCount == 0 {
|
if downloadCount == 0 {
|
||||||
save(store)
|
save(cache)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
close(downloadResults)
|
close(downloadResults)
|
||||||
bar.Finish()
|
bar.Finish()
|
||||||
save(store)
|
save(cache)
|
||||||
|
|
||||||
if buffer != "" {
|
if buffer != "" {
|
||||||
fmt.Fprintln(os.Stderr, buffer)
|
fmt.Fprintln(os.Stderr, buffer)
|
||||||
@ -202,11 +202,11 @@ func main() {
|
|||||||
fmt.Fprintf(os.Stderr, "error: %s", err)
|
fmt.Fprintf(os.Stderr, "error: %s", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if store.CID != "" && store.CID != cid {
|
if cache.CID != "" && cache.CID != cid {
|
||||||
sh.Unpin(store.CID)
|
sh.Unpin(cache.CID)
|
||||||
}
|
}
|
||||||
store.CID = cid
|
cache.CID = cid
|
||||||
save(store)
|
save(cache)
|
||||||
|
|
||||||
fmt.Fprintln(os.Stderr, cid)
|
fmt.Fprintln(os.Stderr, cid)
|
||||||
}
|
}
|
||||||
@ -477,7 +477,7 @@ func checker(id int, jobs <-chan string, results chan<- string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func save(store Store) {
|
func save(cache Cache) {
|
||||||
storeData, _ := json.Marshal(&store)
|
cacheData, _ := json.Marshal(&cache)
|
||||||
_ = ioutil.WriteFile(*storeFile, storeData, 0644)
|
_ = ioutil.WriteFile(*cacheFile, cacheData, 0644)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user