Skip to content

Commit

Permalink
Merge pull request #150 from kylezb/feat
Browse files Browse the repository at this point in the history
  • Loading branch information
anhoder committed Jul 13, 2023
2 parents f944442 + b56e883 commit 4a43018
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ func DownloadMusic(song structs.Song) {
}

fileName := fmt.Sprintf("%s-%s.%s", song.Name, song.ArtistName(), musicType)
// Windows Linux 均不允许文件名中出现 / \ 替换为 _
fileName = strings.Replace(fileName, "/", "_", -1)
targetFilename := path.Join(downloadDir, fileName)
if _, err := os.Stat(targetFilename); err == nil {
Notify(NotifyContent{
Expand All @@ -211,7 +213,10 @@ func DownloadMusic(song structs.Song) {
return
}

resp, err := http.Get(url)
client := &http.Client{
Timeout: 60 * time.Second,
}
resp, err := client.Get(url)
if err != nil {
errHandler(err)
return
Expand All @@ -232,7 +237,11 @@ func DownloadMusic(song structs.Song) {
GroupId: constants.GroupID,
})

_, _ = io.Copy(f, resp.Body)
_, err = io.Copy(f, resp.Body)
if err != nil {
errHandler(err)
return
}

version := songtag.CheckVersion(f)
switch version {
Expand Down

0 comments on commit 4a43018

Please sign in to comment.