Refactored NowPlaying

Also added a test case for skipping range
This commit is contained in:
Deluan
2016-03-24 17:14:13 -04:00
parent 3c8f6e9a65
commit 1cf8a0db44
5 changed files with 51 additions and 20 deletions
+9 -3
View File
@@ -10,6 +10,11 @@ import (
"github.com/deluan/gosonic/itunesbridge"
)
const (
minSkipped = time.Duration(3) * time.Second
maxSkipped = time.Duration(20) * time.Second
)
type Scrobbler interface {
Register(playerId int, trackId string, playDate time.Time) (*domain.MediaFile, error)
NowPlaying(playerId int, playerName, trackId, username string) (*domain.MediaFile, error)
@@ -46,7 +51,7 @@ func (s *scrobbler) detectSkipped(playerId int, trackId string) {
}
}
func (s *scrobbler) Register(playerId int, trackId string, playDate time.Time) (*domain.MediaFile, error) {
func (s *scrobbler) Register(playerId int, trackId string, playTime time.Time) (*domain.MediaFile, error) {
s.detectSkipped(playerId, trackId)
mf, err := s.mfRepo.Get(trackId)
@@ -58,7 +63,7 @@ func (s *scrobbler) Register(playerId int, trackId string, playDate time.Time) (
return nil, errors.New(fmt.Sprintf(`Id "%s" not found`, trackId))
}
if err := s.itunes.MarkAsPlayed(trackId, playDate); err != nil {
if err := s.itunes.MarkAsPlayed(trackId, playTime); err != nil {
return nil, err
}
return mf, nil
@@ -74,5 +79,6 @@ func (s *scrobbler) NowPlaying(playerId int, playerName, trackId, username strin
return nil, errors.New(fmt.Sprintf(`Id "%s" not found`, trackId))
}
return mf, s.npRepo.Enqueue(playerId, playerName, trackId, username)
info := &NowPlayingInfo{TrackId: trackId, Username: username, Start: time.Now(), PlayerId: playerId, PlayerName: playerName}
return mf, s.npRepo.Enqueue(info)
}