Skip to content

🎧 Your Personal Streaming Service

Skipping now working(?)

Deluanc8184da0edcf
diff --git a/engine/scrobbler.go b/engine/scrobbler.go
index 2de62a41b..9ebb14f49 100644
--- a/engine/scrobbler.go
+++ b/engine/scrobbler.go
@@ -11,7 +11,7 @@ import (
)
const (
- minSkipped = time.Duration(3) * time.Second
+ minSkipped = time.Duration(5) * time.Second
maxSkipped = time.Duration(20) * time.Second
)
@@ -31,22 +31,37 @@ type scrobbler struct {
}
func (s *scrobbler) detectSkipped(playerId int, trackId string) {
- for {
- size, _ := s.npRepo.Count(playerId)
- np, err := s.npRepo.Tail(playerId)
- if err != nil || np == nil || (size == 1 && np.TrackId != trackId) {
- break
+ size, _ := s.npRepo.Count(playerId)
+ switch size {
+ case 0:
+ return
+ case 1:
+ np, _ := s.npRepo.Tail(playerId)
+ if np.TrackId != trackId {
+ return
}
-
s.npRepo.Dequeue(playerId)
- if np.TrackId == trackId {
- break
- }
- err = s.itunes.MarkAsSkipped(np.TrackId, np.Start.Add(time.Duration(1)*time.Minute))
- if err != nil {
- beego.Warn("Error skipping track", np.TrackId)
- } else {
- beego.Debug("Skipped track", np.TrackId)
+ default:
+ prev, _ := s.npRepo.Dequeue(playerId)
+ for {
+ if prev.TrackId == trackId {
+ break
+ }
+ np, err := s.npRepo.Dequeue(playerId)
+ if np == nil || err != nil {
+ break
+ }
+ diff := np.Start.Sub(prev.Start)
+ if diff < minSkipped || diff > maxSkipped {
+ prev = np
+ continue
+ }
+ err = s.itunes.MarkAsSkipped(prev.TrackId, prev.Start.Add(time.Duration(1)*time.Minute))
+ if err != nil {
+ beego.Warn("Error skipping track", prev.TrackId)
+ } else {
+ beego.Debug("Skipped track", prev.TrackId)
+ }
}
}
}
diff --git a/engine/scrobbler_test.go b/engine/scrobbler_test.go
index c9eca94b9..e12860b46 100644
--- a/engine/scrobbler_test.go
+++ b/engine/scrobbler_test.go
@@ -109,7 +109,17 @@ func TestSkipping(t *testing.T) {
So(err, ShouldBeNil)
})
})
- SkipConvey("And I skip it after 20 seconds", func() {
+ Convey("And I skip it after 5 seconds", func() {
+ npRepo.OverrideNow(start.Add(time.Duration(3) * time.Second))
+ scrobbler.NowPlaying(1, "DSub", "2", "deluan")
+ Convey("Then the first song should be marked as skipped", func() {
+ mf, err := scrobbler.Register(1, "2", start.Add(time.Duration(3)*time.Minute))
+ So(mf.Id, ShouldEqual, "2")
+ So(itCtrl.skipped, ShouldBeEmpty)
+ So(err, ShouldBeNil)
+ })
+ })
+ Convey("And I skip it after 20 seconds", func() {
npRepo.OverrideNow(start.Add(time.Duration(30) * time.Second))
scrobbler.NowPlaying(1, "DSub", "2", "deluan")
Convey("Then the first song should be marked as skipped", func() {