Polishing

This commit is contained in:
Deluan 2016-04-21 10:44:27 -04:00
parent 5b9b430825
commit 60bc1d7a11
5 changed files with 18 additions and 18 deletions

View File

@ -2,7 +2,7 @@ package engine
import "time" import "time"
const NowPlayingExpire = time.Duration(60) * time.Minute const NowPlayingExpire = 60 * time.Minute
type NowPlayingInfo struct { type NowPlayingInfo struct {
TrackId string TrackId string

View File

@ -11,8 +11,8 @@ import (
) )
const ( const (
minSkipped = time.Duration(3) * time.Second minSkipped = 3 * time.Second
maxSkipped = time.Duration(10) * time.Second maxSkipped = 20 * time.Second
) )
type Scrobbler interface { type Scrobbler interface {
@ -57,7 +57,7 @@ func (s *scrobbler) detectSkipped(playerId int, trackId string) {
prev = np prev = np
continue continue
} }
err = s.itunes.MarkAsSkipped(prev.TrackId, prev.Start.Add(time.Duration(1)*time.Minute)) err = s.itunes.MarkAsSkipped(prev.TrackId, prev.Start.Add(1*time.Minute))
if err != nil { if err != nil {
beego.Warn("Error skipping track", prev.TrackId) beego.Warn("Error skipping track", prev.TrackId)
} else { } else {

View File

@ -100,9 +100,9 @@ func TestSkipping(t *testing.T) {
Convey("When I skip 2 songs", func() { Convey("When I skip 2 songs", func() {
npRepo.OverrideNow(aPointInTime) npRepo.OverrideNow(aPointInTime)
scrobbler.NowPlaying(1, "DSub", "1", "deluan") scrobbler.NowPlaying(1, "DSub", "1", "deluan")
npRepo.OverrideNow(aPointInTime.Add(time.Duration(2) * time.Second)) npRepo.OverrideNow(aPointInTime.Add(2 * time.Second))
scrobbler.NowPlaying(1, "DSub", "3", "deluan") scrobbler.NowPlaying(1, "DSub", "3", "deluan")
npRepo.OverrideNow(aPointInTime.Add(time.Duration(3) * time.Second)) npRepo.OverrideNow(aPointInTime.Add(3 * time.Second))
scrobbler.NowPlaying(1, "DSub", "2", "deluan") scrobbler.NowPlaying(1, "DSub", "2", "deluan")
Convey("Then the NowPlaying song should be the last one", func() { Convey("Then the NowPlaying song should be the last one", func() {
np, err := npRepo.GetAll() np, err := npRepo.GetAll()
@ -114,31 +114,31 @@ func TestSkipping(t *testing.T) {
Convey("When I play one song", func() { Convey("When I play one song", func() {
npRepo.OverrideNow(aPointInTime) npRepo.OverrideNow(aPointInTime)
scrobbler.NowPlaying(1, "DSub", "1", "deluan") scrobbler.NowPlaying(1, "DSub", "1", "deluan")
Convey("And I skip it before 10 seconds", func() { Convey("And I skip it before 20 seconds", func() {
npRepo.OverrideNow(aPointInTime.Add(time.Duration(7) * time.Second)) npRepo.OverrideNow(aPointInTime.Add(7 * time.Second))
scrobbler.NowPlaying(1, "DSub", "2", "deluan") scrobbler.NowPlaying(1, "DSub", "2", "deluan")
Convey("Then the first song should be marked as skipped", func() { Convey("Then the first song should be marked as skipped", func() {
mf, err := scrobbler.Register(1, "2", aPointInTime.Add(time.Duration(3)*time.Minute)) mf, err := scrobbler.Register(1, "2", aPointInTime.Add(3*time.Minute))
So(mf.Id, ShouldEqual, "2") So(mf.Id, ShouldEqual, "2")
So(itCtrl.skipped, ShouldContainKey, "1") So(itCtrl.skipped, ShouldContainKey, "1")
So(err, ShouldBeNil) So(err, ShouldBeNil)
}) })
}) })
Convey("And I skip it before 3 seconds", func() { Convey("And I skip it before 3 seconds", func() {
npRepo.OverrideNow(aPointInTime.Add(time.Duration(2) * time.Second)) npRepo.OverrideNow(aPointInTime.Add(2 * time.Second))
scrobbler.NowPlaying(1, "DSub", "2", "deluan") scrobbler.NowPlaying(1, "DSub", "2", "deluan")
Convey("Then the first song should be marked as skipped", func() { Convey("Then the first song should be marked as skipped", func() {
mf, err := scrobbler.Register(1, "2", aPointInTime.Add(time.Duration(3)*time.Minute)) mf, err := scrobbler.Register(1, "2", aPointInTime.Add(3*time.Minute))
So(mf.Id, ShouldEqual, "2") So(mf.Id, ShouldEqual, "2")
So(itCtrl.skipped, ShouldBeEmpty) So(itCtrl.skipped, ShouldBeEmpty)
So(err, ShouldBeNil) So(err, ShouldBeNil)
}) })
}) })
Convey("And I skip it after 10 seconds", func() { Convey("And I skip it after 20 seconds", func() {
npRepo.OverrideNow(aPointInTime.Add(time.Duration(30) * time.Second)) npRepo.OverrideNow(aPointInTime.Add(30 * time.Second))
scrobbler.NowPlaying(1, "DSub", "2", "deluan") scrobbler.NowPlaying(1, "DSub", "2", "deluan")
Convey("Then the first song should be marked as skipped", func() { Convey("Then the first song should be marked as skipped", func() {
mf, err := scrobbler.Register(1, "2", aPointInTime.Add(time.Duration(3)*time.Minute)) mf, err := scrobbler.Register(1, "2", aPointInTime.Add(3*time.Minute))
So(mf.Id, ShouldEqual, "2") So(mf.Id, ShouldEqual, "2")
So(itCtrl.skipped, ShouldBeEmpty) So(itCtrl.skipped, ShouldBeEmpty)
So(err, ShouldBeNil) So(err, ShouldBeNil)
@ -156,9 +156,9 @@ func TestSkipping(t *testing.T) {
Convey("When the NowPlaying for the next song happens before the Scrobble", func() { Convey("When the NowPlaying for the next song happens before the Scrobble", func() {
npRepo.OverrideNow(aPointInTime) npRepo.OverrideNow(aPointInTime)
scrobbler.NowPlaying(1, "DSub", "1", "deluan") scrobbler.NowPlaying(1, "DSub", "1", "deluan")
npRepo.OverrideNow(aPointInTime.Add(time.Duration(10) * time.Second)) npRepo.OverrideNow(aPointInTime.Add(10 * time.Second))
scrobbler.NowPlaying(1, "DSub", "2", "deluan") scrobbler.NowPlaying(1, "DSub", "2", "deluan")
scrobbler.Register(1, "1", aPointInTime.Add(time.Duration(10)*time.Minute)) scrobbler.Register(1, "1", aPointInTime.Add(10*time.Minute))
Convey("Then the NowPlaying song should be the last one", func() { Convey("Then the NowPlaying song should be the last one", func() {
np, _ := npRepo.GetAll() np, _ := npRepo.GetAll()
So(np, ShouldHaveLength, 1) So(np, ShouldHaveLength, 1)

View File

@ -66,7 +66,7 @@ func (r *albumRepository) PurgeInactive(active domain.Albums) ([]string, error)
func (r *albumRepository) GetStarred(options domain.QueryOptions) (domain.Albums, error) { func (r *albumRepository) GetStarred(options domain.QueryOptions) (domain.Albums, error) {
var as = make(domain.Albums, 0) var as = make(domain.Albums, 0)
start := time.Time{}.Add(time.Duration(1) * time.Hour) start := time.Time{}.Add(1 * time.Hour)
err := r.loadRange("Starred", start, time.Now(), &as, options) err := r.loadRange("Starred", start, time.Now(), &as, options)
return as, err return as, err
} }

View File

@ -47,7 +47,7 @@ func (r *mediaFileRepository) FindByAlbum(albumId string) (domain.MediaFiles, er
func (r *mediaFileRepository) GetStarred(options domain.QueryOptions) (domain.MediaFiles, error) { func (r *mediaFileRepository) GetStarred(options domain.QueryOptions) (domain.MediaFiles, error) {
var mfs = make(domain.MediaFiles, 0) var mfs = make(domain.MediaFiles, 0)
start := time.Time{}.Add(time.Duration(1) * time.Hour) start := time.Time{}.Add(1 * time.Hour)
err := r.loadRange("Starred", start, time.Now(), &mfs, options) err := r.loadRange("Starred", start, time.Now(), &mfs, options)
return mfs, err return mfs, err
} }