[Banshee-List] [PATCH] Rudimentary seek detection for the audioscrobbler plugin



Made this small patch between two sessions of study. It adds a
rudimentary seek detection for the audioscrobbler plugin.

>From the audioscrobbler protocol specs:

 * If a user seeks (i.e. manually changes position) within a song before
   the song is due to be submitted, do not submit that song.

Hence this patch.

Happy new year everybody!
  Ruben


--
Ruben Vermeersch (rubenv)
http://www.Lambda1.be/
Rudimentary seek detection.

From the audioscrobbler protocol specs:

 * If a user seeks (i.e. manually changes position) within a song before the
   song is due to be submitted, do not submit that song.

 Engine.cs |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Index: src/Banshee.Plugins/Audioscrobbler/Engine.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/Banshee.Plugins/Audioscrobbler/Engine.cs,v
retrieving revision 1.6
diff -u -p -r1.6 Engine.cs
--- src/Banshee.Plugins/Audioscrobbler/Engine.cs	30 Dec 2005 06:08:43 -0000	1.6
+++ src/Banshee.Plugins/Audioscrobbler/Engine.cs	31 Dec 2005 16:59:06 -0000
@@ -87,6 +87,8 @@ namespace Banshee.Plugins.Audioscrobbler
 		DateTime next_interval;
 		
 		bool queued; /* if current_track has been queued */
+		bool sought; /* if the user has sought in the current playing song */
+		uint position; /* position in the playing song, on previous tick */
 		TrackInfo current_track;
 		ArrayList queue;
 
@@ -154,12 +156,19 @@ namespace Banshee.Plugins.Audioscrobbler
 				if (track != current_track) {
 					current_track = track;
 					queued = false;
+					sought = false;
+					position = 0;
+				}
+
+				/* did the user seek? */
+				if (player.Position > position + TICK_INTERVAL * 2) {
+					sought = true;
 				}
 
 				/* Each song should be posted to the server
 				   when it is 50% or 240 seconds complete,
 				   whichever comes first. */
-				if (!queued
+				if (!queued && !sought
 				    && (player.Position > player.Length / 2
 					|| player.Position > 240)) {
 					queue.Add (new QueuedTrack (track,
@@ -167,6 +176,8 @@ namespace Banshee.Plugins.Audioscrobbler
 												 - TimeSpan.FromSeconds (player.Position))));
 					queued = true;
 				}
+
+				position = player.Position;
 			}
 			else {
 				current_track = null;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]