check muse instead of zip
This commit is contained in:
parent
4764182d24
commit
01f3a51f8e
30
main.go
30
main.go
@ -188,7 +188,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if *verbose {
|
if *verbose {
|
||||||
fmt.Fprintf(os.Stderr, "Downloading %d entries...\r\n", downloadCount)
|
fmt.Fprintf(os.Stderr, "Downloading %d files...\r\n", downloadCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *progress {
|
if *progress {
|
||||||
@ -266,9 +266,14 @@ func dirnameForUrl(url string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func check(url string, path string, timeout time.Duration) (modified bool, err error) {
|
func check(url string, path string, timeout time.Duration) (modified bool, err error) {
|
||||||
|
if strings.HasSuffix(url, ".zip") {
|
||||||
|
url = strings.TrimSuffix(url, ".zip") + ".muse"
|
||||||
|
path = strings.TrimSuffix(path, ".zip") + ".muse"
|
||||||
|
}
|
||||||
|
|
||||||
request, err := http.NewRequest("HEAD", url, nil)
|
request, err := http.NewRequest("HEAD", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
@ -278,12 +283,12 @@ func check(url string, path string, timeout time.Duration) (modified bool, err e
|
|||||||
|
|
||||||
response, err := http.DefaultClient.Do(request)
|
response, err := http.DefaultClient.Do(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return false, err
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
if response.StatusCode == 404 {
|
if response.StatusCode == 404 {
|
||||||
fmt.Fprintln(os.Stderr, url+" was removed?")
|
fmt.Fprintln(os.Stderr, url+" not found.")
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,6 +434,10 @@ func unzip(src string, dest string) ([]string, error) {
|
|||||||
|
|
||||||
func downloader(id int, jobs <-chan string, results chan<- string) {
|
func downloader(id int, jobs <-chan string, results chan<- string) {
|
||||||
for href := range jobs {
|
for href := range jobs {
|
||||||
|
if strings.HasSuffix(href, ".muse") {
|
||||||
|
href = strings.TrimSuffix(href, ".muse") + ".zip"
|
||||||
|
}
|
||||||
|
|
||||||
result := ""
|
result := ""
|
||||||
|
|
||||||
dir := dirnameForUrl(href)
|
dir := dirnameForUrl(href)
|
||||||
@ -519,9 +528,16 @@ func checker(id int, jobs <-chan string, results chan<- string) {
|
|||||||
name := filenameForUrl(href)
|
name := filenameForUrl(href)
|
||||||
path := filepath.Join(*outputDir, dir, name)
|
path := filepath.Join(*outputDir, dir, name)
|
||||||
|
|
||||||
if !fileExists(path) {
|
if strings.HasSuffix(name, ".zip") {
|
||||||
results <- href
|
if !fileExists(strings.TrimSuffix(path, ".zip") + ".muse") {
|
||||||
continue
|
results <- href
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if !fileExists(path) {
|
||||||
|
results <- href
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
Loading…
Reference in New Issue
Block a user