feat: delete file if download fails
This commit is contained in:
@@ -90,6 +90,7 @@ func downloadContent(contentType string, args []string) {
|
|||||||
if err := session.GetData(album, id); err != nil {
|
if err := session.GetData(album, id); err != nil {
|
||||||
fmt.Printf("\r[%d/%d] Getting data for album %s... FAILED\n", i+1, nArgs, id)
|
fmt.Printf("\r[%d/%d] Getting data for album %s... FAILED\n", i+1, nArgs, id)
|
||||||
fmt.Fprintf(os.Stderr, "Error: could not get album data: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error: could not get album data: %v\n", err)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
resource = album
|
resource = album
|
||||||
@@ -99,11 +100,13 @@ func downloadContent(contentType string, args []string) {
|
|||||||
if err := session.GetData(playlist, id); err != nil {
|
if err := session.GetData(playlist, id); err != nil {
|
||||||
fmt.Printf("\r[%d/%d] Getting data for playlist %s... FAILED\n", i+1, nArgs, id)
|
fmt.Printf("\r[%d/%d] Getting data for playlist %s... FAILED\n", i+1, nArgs, id)
|
||||||
fmt.Fprintf(os.Stderr, "Error: could not get playlist data: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error: could not get playlist data: %v\n", err)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if playlist.Results.Data.Status == 1 && playlist.Results.Data.CollabKey == "" {
|
if playlist.Results.Data.Status == 1 && playlist.Results.Data.CollabKey == "" {
|
||||||
fmt.Printf("\r[%d/%d] Getting data for playlist %s... FAILED\n", i+1, nArgs, id)
|
fmt.Printf("\r[%d/%d] Getting data for playlist %s... FAILED\n", i+1, nArgs, id)
|
||||||
fmt.Fprintf(os.Stderr, "Error: playlist is private and no valid arl cookie was provided\n")
|
fmt.Fprintf(os.Stderr, "Error: playlist is private and no valid arl cookie was provided\n")
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,6 +119,7 @@ func downloadContent(contentType string, args []string) {
|
|||||||
output := resource.GetOutputPath(outputDir)
|
output := resource.GetOutputPath(outputDir)
|
||||||
if err := utils.EnsureDir(output); err != nil {
|
if err := utils.EnsureDir(output); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error: could not create output directory: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error: could not create output directory: %v\n", err)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,12 +139,14 @@ func downloadContent(contentType string, args []string) {
|
|||||||
if err.Error() == "invalid license token" {
|
if err.Error() == "invalid license token" {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(media.Data) == 0 || len(media.Data[0].Media) == 0 || len(media.Data[0].Media[0].Sources) == 0 {
|
if len(media.Data) == 0 || len(media.Data[0].Media) == 0 || len(media.Data[0].Media[0].Sources) == 0 {
|
||||||
fmt.Printf(" Downloading %s... FAILED\n", songTitle)
|
fmt.Printf(" Downloading %s... FAILED\n", songTitle)
|
||||||
fmt.Fprintf(os.Stderr, "Error: could not get media sources\n")
|
fmt.Fprintf(os.Stderr, "Error: could not get media sources\n")
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,6 +184,8 @@ func downloadContent(contentType string, args []string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("\r Downloading %s... FAILED\n", songTitle)
|
fmt.Printf("\r Downloading %s... FAILED\n", songTitle)
|
||||||
fmt.Fprintf(os.Stderr, "Error: could not download song: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error: could not download song: %v\n", err)
|
||||||
|
utils.DeleteFile(filePath)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Printf("\r Downloading %s... DONE\n", songTitle)
|
fmt.Printf("\r Downloading %s... DONE\n", songTitle)
|
||||||
|
|||||||
@@ -7,3 +7,11 @@ func FileExists(path string) bool {
|
|||||||
|
|
||||||
return err == nil && !info.IsDir()
|
return err == nil && !info.IsDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeleteFile(path string) error {
|
||||||
|
if !FileExists(path) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return os.Remove(path)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user