Skip to content

Commit

Permalink
Merge pull request go-musicfox#68 from kylezb/master
Browse files Browse the repository at this point in the history
修复Windows下载失败的问题
  • Loading branch information
anhoder committed Mar 21, 2023
2 parents 2bd7fcf + 67704af commit e1d36d7
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 @@ -270,7 +270,7 @@ func DownloadMusic(song structs.Song) {
_ = os.Rename(f.Name(), targetFilename)
break
}
defer tag.Close()
// defer tag.Close() //fix: "The process cannot access the file because it is being used by another process" Err on Windows
tag.SetDefaultEncoding(id3v2.EncodingUTF8)
if imgResp, err := http.Get(AddResizeParamForPicUrl(song.PicUrl, 1024)); err == nil {
defer imgResp.Body.Close()
Expand All @@ -287,7 +287,16 @@ func DownloadMusic(song structs.Song) {
tag.SetAlbum(song.Album.Name)
tag.SetArtist(song.ArtistName())
_ = tag.Save()
_ = os.Rename(f.Name(), targetFilename)
tag.Close() //fix: "The process cannot access the file because it is being used by another process" Err on Windows
err = os.Rename(f.Name(), targetFilename)
if err != nil && runtime.GOOS == "windows" {
//fix: Windows下载路径修改为其他盘符时报错:The system cannot move the file to a different disk drive.
srcFile, _ := os.Open(f.Name())
dstFile, _ := os.Create(targetFilename)
defer dstFile.Close()
_, _ = io.Copy(dstFile, srcFile)
srcFile.Close()
}
default:
metadata, err := songtag.Read(f)
if err != nil {
Expand Down

0 comments on commit e1d36d7

Please sign in to comment.