banshee r3320 - in trunk/banshee: . src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea src/Libraries/Lastfm src/Libraries/Lastfm/Lastfm



Author: ahixon
Date: Sun Feb 24 09:47:56 2008
New Revision: 3320
URL: http://svn.gnome.org/viewvc/banshee?rev=3320&view=rev

Log:
2008-02-23  Alexander Hixon  <hixon alexander mediati org>
    * src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/TrackInfoPopup.cs:
      Decrease spacing between time and progress bar.
    
    * src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs:
    * src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs:
    * src/Libraries/Lastfm/Makefile.am:
    * src/Libraries/Lastfm/Lastfm/LastfmCore.cs: Use LastfmCore as a singleton
      to access Last.fm classes.
    
    * src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs: Provide support
      for user agent when sending requests to Audioscrobbler servers. Can be
      passed via ctor or by setting the UserAgent property. Also marked ctor
      as internal.
    
    * src/Libraries/Lastfm/Lastfm/RadioConnection.cs: Added UserAgent property.
      Marked ctor as internal.
    
    * src/Libraries/Lastfm/Lastfm/Account.cs: Remove the static Account instance,
      since it's now provided by LastfmCore as a singleton.


Added:
   trunk/banshee/src/Libraries/Lastfm/Lastfm/LastfmCore.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs
   trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs
   trunk/banshee/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/TrackInfoPopup.cs
   trunk/banshee/src/Libraries/Lastfm/Lastfm/Account.cs
   trunk/banshee/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs
   trunk/banshee/src/Libraries/Lastfm/Lastfm/RadioConnection.cs
   trunk/banshee/src/Libraries/Lastfm/Makefile.am

Modified: trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs	Sun Feb 24 09:47:56 2008
@@ -74,15 +74,20 @@
         
         void IExtensionService.Initialize ()
         {
-            account = Account.Instance;
+            account = LastfmCore.Account;
             
             if (account.UserName == null) {
                 account.UserName = LastUserSchema.Get ();
                 account.CryptedPassword = LastPassSchema.Get ();
             }
             
+            if (LastfmCore.UserAgent == null) {
+                LastfmCore.UserAgent = Banshee.Web.Browser.UserAgent;
+            }
+            
             queue = new Queue ();
-            connection = new AudioscrobblerConnection (account, queue);
+            LastfmCore.AudioscrobblerQueue = queue;
+            connection = LastfmCore.Audioscrobbler;
             
             // This auto-connects for us if we start off connected to the network.
             connection.UpdateNetworkState (NetworkDetect.Instance.Connected);

Modified: trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs	Sun Feb 24 09:47:56 2008
@@ -69,7 +69,7 @@
 
         public LastfmSource () : base (lastfm, lastfm, 150)
         {
-            account = Account.Instance;
+            account = LastfmCore.Account;
 
             // We don't automatically connect to Last.fm, but load the last Last.fm
             // username we used so we can load the user's stations.
@@ -78,7 +78,11 @@
                 account.CryptedPassword = LastPassSchema.Get ();
             }
 
-            connection = new RadioConnection (account, Banshee.Web.Browser.UserAgent);
+            if (LastfmCore.UserAgent == null) {
+                LastfmCore.UserAgent = Banshee.Web.Browser.UserAgent;
+            }
+            
+            connection = LastfmCore.Radio;
             connection.UpdateNetworkState (NetworkDetect.Instance.Connected);
             NetworkDetect.Instance.StateChanged += delegate (object o, NetworkStateChangedArgs args) {
                 connection.UpdateNetworkState (args.Connected);

Modified: trunk/banshee/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/TrackInfoPopup.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/TrackInfoPopup.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/TrackInfoPopup.cs	Sun Feb 24 09:47:56 2008
@@ -55,7 +55,7 @@
             
             // Position label and linear progress bar
             HBox position_box = new HBox ();
-            position_box.Spacing = 10;
+            //position_box.Spacing = 10;
             
             position_label = new Label ();
             position_label.Xalign = 0.0f;

Modified: trunk/banshee/src/Libraries/Lastfm/Lastfm/Account.cs
==============================================================================
--- trunk/banshee/src/Libraries/Lastfm/Lastfm/Account.cs	(original)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm/Account.cs	Sun Feb 24 09:47:56 2008
@@ -34,18 +34,7 @@
 namespace Lastfm
 {
     public class Account
-    {
-        private static Account instance;
-        public static Account Instance {
-            get {
-                if (instance == null) {
-                    instance = new Account ();
-                }
-                
-                return instance;
-            }
-        }
-    
+    {    
         public event EventHandler Updated;
 
         private string username;

Modified: trunk/banshee/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs
==============================================================================
--- trunk/banshee/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs	(original)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs	Sun Feb 24 09:47:56 2008
@@ -62,6 +62,7 @@
         const string SCROBBLER_VERSION = "1.2";
 
         Account account;
+        string user_agent;
         string post_url;
         string session_id = null;
         string now_playing_url;
@@ -75,6 +76,11 @@
         public bool Started {
             get { return started; }
         }
+        
+        public string UserAgent {
+            get { return user_agent; }
+            set { user_agent = value; }
+        }
 
         System.Timers.Timer timer;
         DateTime next_interval;
@@ -85,12 +91,16 @@
         int hard_failures = 0;
         int hard_failure_retry_sec = 60;
         
-        WebRequest now_playing_post;
-        WebRequest current_web_req;
+        HttpWebRequest now_playing_post;
+        HttpWebRequest current_web_req;
         IAsyncResult current_async_result;
         State state;
         
-        public AudioscrobblerConnection (Account account, IQueue queue)
+        internal AudioscrobblerConnection (Account account, IQueue queue) : this (account, queue, "")
+        {
+        }
+        
+        internal AudioscrobblerConnection (Account account, IQueue queue, string user_agent)
         {
             this.account = account;
             
@@ -98,6 +108,8 @@
             
             state = State.IDLE;
             this.queue = queue;
+            
+            this.user_agent = user_agent;
         }
         
         private void AccountUpdated (object o, EventArgs args)
@@ -228,13 +240,6 @@
                 /* nothing here */
                 break;
             }
-            
-            // Only submit if queue is empty, otherwise the submission
-            // gets overruled by the queue submission by Last.fm
-            /*if (queue.Count == 0 && !now_playing_submitted && state == State.IDLE && is_playing) {
-                NowPlaying (PlayerEngineCore.CurrentTrack);
-            }*/
-            // TODO
         }
 
         //
@@ -267,7 +272,8 @@
 
             sb.Append (queue.GetTransmitInfo (out num_tracks_transmitted));
 
-            current_web_req = WebRequest.Create (post_url);
+            current_web_req = (HttpWebRequest) WebRequest.Create (post_url);
+            current_web_req.UserAgent = user_agent;
             current_web_req.Method = "POST";
             current_web_req.ContentType = "application/x-www-form-urlencoded";
             current_web_req.ContentLength = sb.Length;
@@ -414,7 +420,7 @@
                                         timestamp,
                                         security_token);
 
-            current_web_req = WebRequest.Create (uri);
+            current_web_req = (HttpWebRequest) WebRequest.Create (uri);
 
             state = State.WAITING_FOR_HANDSHAKE_RESP;
             current_async_result = current_web_req.BeginGetResponse (HandshakeGetResponse, null);
@@ -530,7 +536,8 @@
                                             str_track_number,
     			                            mbrainzid);
 
-                now_playing_post = WebRequest.Create (uri);
+                now_playing_post = (HttpWebRequest) WebRequest.Create (uri);
+                now_playing_post.UserAgent = user_agent;
                 now_playing_post.Method = "POST";
                 now_playing_post.ContentType = "application/x-www-form-urlencoded";
                 now_playing_post.ContentLength = uri.Length;
@@ -549,6 +556,10 @@
                 StreamReader sr = new StreamReader (s, Encoding.UTF8);
 
                 string line = sr.ReadLine ();
+                if (line == null) {
+                    Hyena.Log.Warning ("Audioscrobbler NowPlaying failed", "No response", false);
+                }
+                
                 if (line.StartsWith ("BADSESSION")) {
                     Hyena.Log.Warning ("Audioscrobbler NowPlaying failed", "Session ID sent was invalid", false);
                     /* attempt to re-handshake on the next interval */

Added: trunk/banshee/src/Libraries/Lastfm/Lastfm/LastfmCore.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm/LastfmCore.cs	Sun Feb 24 09:47:56 2008
@@ -0,0 +1,95 @@
+//
+// LastfmCore.cs
+//
+// Authors:
+//   Alexander Hixon <hixon alexander mediati org>
+//
+// Copyright (C) 2008 Alexander Hixon
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace Lastfm
+{
+    public static class LastfmCore
+    {
+        private static Account account;
+        public static Account Account {
+            get {
+                if (account == null) {
+                    account = new Account ();
+                }
+                
+                return account;
+            }
+        }
+        
+        private static string user_agent;
+        public static string UserAgent {
+            get { return user_agent; }
+            set {
+                user_agent = value;
+                if (radio != null) {
+                    radio.UserAgent = value;
+                }
+                
+                if (audioscrobbler != null) {
+                    audioscrobbler.UserAgent = value;
+                }
+            }
+        }
+        
+        private static RadioConnection radio;
+        public static RadioConnection Radio {
+            get {
+                if (radio == null) {
+                    radio = new RadioConnection (LastfmCore.Account, user_agent);
+                }
+                
+                return radio;
+            }
+        }
+        
+        private static IQueue queue;
+        public static IQueue AudioscrobblerQueue {
+            get { return queue; }
+            set { queue = value; }
+        }
+        
+        private static AudioscrobblerConnection audioscrobbler;
+        public static AudioscrobblerConnection Audioscrobbler {
+            get {
+                if (audioscrobbler == null) {
+                    if (queue == null) {
+                        throw new ApplicationException
+                            ("Queue instance must be defined before referencing Audioscrobbler.");
+                    }
+                    
+                    audioscrobbler = new AudioscrobblerConnection (LastfmCore.Account,queue,
+                        user_agent);
+                }
+                
+                return audioscrobbler;
+            }
+        }
+    }
+}

Modified: trunk/banshee/src/Libraries/Lastfm/Lastfm/RadioConnection.cs
==============================================================================
--- trunk/banshee/src/Libraries/Lastfm/Lastfm/RadioConnection.cs	(original)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm/RadioConnection.cs	Sun Feb 24 09:47:56 2008
@@ -96,7 +96,12 @@
         public Account Account {
             get { return account; }
         }
-
+        
+        public string UserAgent {
+            get { return user_agent; }
+            set { user_agent = value; }
+        }
+        
         private bool subscriber;
         public bool Subscriber {
             get { return subscriber; }
@@ -131,7 +136,7 @@
             get { return station; }
         }
 
-        public RadioConnection (Account account, string user_agent)
+        internal RadioConnection (Account account, string user_agent)
         {
             this.account = account;
             this.user_agent = user_agent;

Modified: trunk/banshee/src/Libraries/Lastfm/Makefile.am
==============================================================================
--- trunk/banshee/src/Libraries/Lastfm/Makefile.am	(original)
+++ trunk/banshee/src/Libraries/Lastfm/Makefile.am	Sun Feb 24 09:47:56 2008
@@ -7,6 +7,7 @@
 	Lastfm/AudioscrobblerConnection.cs \
 	Lastfm/Browser.cs \
 	Lastfm/IQueue.cs \
+	Lastfm/LastfmCore.cs \
 	Lastfm/RadioConnection.cs \
 	Lastfm.Data/DataCore.cs \
 	Lastfm.Data/DataEntry.cs \



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