Skip to content

Commit

Permalink
fix:
Browse files Browse the repository at this point in the history
1. mpd在第一次下载缓存后panic
2. 删除多余的setSongTag调用
3. 修复cacheLimit语义
  • Loading branch information
imxyy1soope1 committed Jul 8, 2023
1 parent 63e90df commit 9bc1442
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/configs/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func NewRegistryWithDefault() *Registry {
MainAltScreen: true,
MainEnableMouseEvent: true,
MainDownloadDir: "",
MainCacheLimit: -1,
MainCacheLimit: 0,
PlayerEngine: constants.BeepPlayer,
PlayerBeepMp3Decoder: constants.BeepGoMp3Decoder,

Expand Down
26 changes: 18 additions & 8 deletions pkg/player/mpd_player.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ func (p *mpdPlayer) listen() {
err error
)

Loop:
for {
select {
case <-p.close:
Expand Down Expand Up @@ -204,10 +203,21 @@ Loop:
isCache = true
}

_, err = p.client().Update("") // Update music database (for cached music)
if err != nil && isCache {
mpdErrorHandler(err, true)
continue Loop
if isCache {
_, err := p.client().Update(url)
mpdErrorHandler(err, false)
for {
var attr map[string]string
if attr, err = p.client().Status(); err != nil {
mpdErrorHandler(err, true)
break
}
if _, ok := attr["updating_db"]; ok {
continue
}
// 确保更新完成
break
}
}

p.curSongId, err = p.client().AddID(url, 0)
Expand All @@ -234,11 +244,11 @@ Loop:
// Doing this because github.com/fhs/gompd/v2/mpd hasn't implement "addtagid" yet
command := "addtagid %d %s %s"
err = p.client().Command(command, p.curSongId, "artist", p.curMusic.ArtistName()).OK()
mpdErrorHandler(err, false)
mpdErrorHandler(err, true)
err = p.client().Command(command, p.curSongId, "album", p.curMusic.Album.Name).OK()
mpdErrorHandler(err, false)
mpdErrorHandler(err, true)
err = p.client().Command(command, p.curSongId, "title", p.curMusic.Name).OK()
mpdErrorHandler(err, false)
mpdErrorHandler(err, true)
}
p.Resume()
}
Expand Down
2 changes: 0 additions & 2 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,6 @@ func CopyCachedSong(song structs.Song) error {
defer dst.Close()
_, _ = io.Copy(dst, src)
}
f, _ := os.OpenFile(targetFilename, os.O_RDWR, os.ModePerm)
SetSongTag(f, song)
return nil
}

Expand Down

0 comments on commit 9bc1442

Please sign in to comment.