banshee r3253 - in trunk/banshee: . src/Libraries/Lastfm src/Libraries/Lastfm/Lastfm.Data



Author: gburt
Date: Sun Feb 17 02:54:59 2008
New Revision: 3253
URL: http://svn.gnome.org/viewvc/banshee?rev=3253&view=rev

Log:
2008-02-16  Gabriel Burt  <gabriel burt gmail com>

	This commit adds support for most of the user-particular data feeds
	Audioscrobbler offers into Lastfm.dll, our Banshee-independent Lastfm
	library.

	* src/Libraries/Lastfm/Lastfm.Data/LastfmDataCollection.cs:
	* src/Libraries/Lastfm/Lastfm.Data/UserTopTracks.cs:
	* src/Libraries/Lastfm/Lastfm.Data/UserTopArtists.cs:
	* src/Libraries/Lastfm/Lastfm.Data/UserTopData.cs:
	* src/Libraries/Lastfm/Lastfm.Data/Profile.cs:
	* src/Libraries/Lastfm/Lastfm.Data/UserTopAlbums.cs: Removed files.

	* src/Libraries/Lastfm/Test.cs:
	* src/Libraries/Lastfm.Gui/Test.cs: Moved test to Lastfm.Gui.

	* src/Libraries/Lastfm/Lastfm.Data/DataCore.cs: New static class for doing
	initialization and settings.

	* src/Libraries/Lastfm/Lastfm.Data/DataEntryCollection.cs: New class that
	wraps a XmlNodeList.

	* src/Libraries/Lastfm/Makefile.am: Updates, add make test rule.

	* src/Libraries/Lastfm/Lastfm.Data/DataEntry.cs: Move all DataEntry
	subclasses here.  There are too many to have in separate classes (and the
	header/code ratio is really high).

	* src/Libraries/Lastfm/Lastfm.Data/UserData.cs: Wrap almost all of the
	Last.fm data feeds that pertain to a particular user.

	* src/Libraries/Lastfm/Lastfm.Data/LastfmData.cs: Update for DataCore
	changes, and instantiate and wrap a DataEntryCollection.


Added:
   trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/DataCore.cs
   trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/DataEntryCollection.cs
Removed:
   trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/LastfmDataCollection.cs
   trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/Profile.cs
   trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserTopAlbums.cs
   trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserTopArtists.cs
   trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserTopData.cs
   trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserTopTracks.cs
   trunk/banshee/src/Libraries/Lastfm/Test.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/DataEntry.cs
   trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/LastfmData.cs
   trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserData.cs
   trunk/banshee/src/Libraries/Lastfm/Makefile.am

Added: trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/DataCore.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/DataCore.cs	Sun Feb 17 02:54:59 2008
@@ -0,0 +1,104 @@
+//
+// DataCore.cs
+//
+// Authors:
+//   Gabriel Burt <gburt novell com>
+//
+// Copyright (C) 2008 Novell, Inc.
+//
+// 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;
+using System.IO;
+
+using Hyena;
+
+namespace Lastfm.Data
+{
+    public sealed class DataCore
+    {
+        private const int CACHE_VERSION = 2;
+        public static string UserAgent = null; //Banshee.Web.Browser.UserAgent;
+        public static string CachePath = null; //Path.Combine (Banshee.Base.Paths.UserPluginDirectory, "recommendation");
+        public static TimeSpan NormalCacheTime = TimeSpan.FromHours (2);
+
+        private static bool initialized = false;
+
+        internal static void Initialize ()
+        {
+            if (!initialized) {
+                initialized = true;
+
+                if (CachePath == null || UserAgent == null) {
+                    throw new NotSupportedException ("Lastfm.Data.DataCore.CachePath and/or Lastfm.Data.DataCore.Useragent are null.  Applications must set this value.");
+                }
+
+                CheckForCacheWipe();
+                SetupCache();
+            }
+        }
+
+        private static void SetupCache()
+        {
+            bool clean = false;
+            
+            if(!Directory.Exists(CachePath)) {
+                clean = true;
+                Directory.CreateDirectory(CachePath);
+            }
+            
+            // Create our cache subdirectories.
+            for(int i = 0; i < 256; ++i) {
+                string subdir = i.ToString("x");
+                if(i < 16) {
+                    subdir = "0" + subdir;
+                }
+                
+                subdir = System.IO.Path.Combine(CachePath, subdir);
+                
+                if(!Directory.Exists(subdir)) {
+                    Directory.CreateDirectory(subdir);
+                }
+            }
+            
+            //RecommendationPlugin.CacheVersion.Set (CACHE_VERSION);
+            
+            if(clean) {
+                Log.Debug("Recommendation Plugin", "Created a new cache layout");
+            }
+        }
+
+        private static void CheckForCacheWipe()
+        {
+            //bool wipe = false;
+            
+            if(!Directory.Exists(CachePath)) {
+                return;
+            }
+            
+            /*if (RecommendationPlugin.CacheVersion.Get() < CACHE_VERSION) {
+                Directory.Delete(CachePath, true);
+                Log.Debug("Recommendation Plugin", "Destroyed outdated cache");
+            }*/
+        }
+    }
+}
+

Modified: trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/DataEntry.cs
==============================================================================
--- trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/DataEntry.cs	(original)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/DataEntry.cs	Sun Feb 17 02:54:59 2008
@@ -60,4 +60,128 @@
             }
         }
     }
+
+    // Generic types
+    public class NamedEntry : DataEntry
+    {
+        public string Name              { get { return Get<string>   ("name"); } }
+        public string Url               { get { return Get<string>   ("url"); } }
+    }
+
+    public class TopTag : NamedEntry
+    {
+        public int Count { get { return Get<int>   ("count"); } }
+    }
+
+    public class RssEntry : DataEntry
+    {
+        public string Title             { get { return Get<string>   ("title"); } }
+        public string Link              { get { return Get<string>   ("link"); } }
+        public DateTime PublicationDate { get { return Get<DateTime> ("pubDate"); } }
+        public string Guid              { get { return Get<string>   ("guid"); } }
+        public string Description       { get { return Get<string>   ("description"); } }
+    }
+
+    // User-specific types
+
+    public class ProfileEntry : DataEntry
+    {
+        public string Url               { get { return Get<string>   ("url"); } }
+        public string RealName          { get { return Get<string>   ("realname"); } }
+        public string Gender            { get { return Get<string>   ("gender"); } }
+        public string Country           { get { return Get<string>   ("country"); } }
+        public string AvatarUrl         { get { return Get<string>   ("avatar"); } }
+        public string IconUrl           { get { return Get<string>   ("icon"); } }
+        public DateTime Registered      { get { return Get<DateTime> ("registered"); } }
+        public int Age                  { get { return Get<int>      ("age"); } }
+        public int PlayCount            { get { return Get<int>      ("playcount"); } }
+    }
+
+    public class UserTopArtist : NamedEntry
+    {
+        public string MbId              { get { return Get<string>   ("mbid"); } }
+        public int Rank                 { get { return Get<int>      ("rank"); } }
+        public int PlayCount            { get { return Get<int>      ("playcount"); } }
+        public string ThumbnailUrl      { get { return Get<string>   ("thumbnail"); } }
+        public string ImageUrl          { get { return Get<string>   ("image"); } }
+    }
+
+    public class UserTopAlbum : NamedEntry
+    {
+        public string Artist            { get { return Get<string>   ("artist"); } }
+        public string MbId              { get { return Get<string>   ("mbid"); } }
+        public int Rank                 { get { return Get<int>      ("rank"); } }
+        public int PlayCount            { get { return Get<int>      ("playcount"); } }
+    }
+
+    public class UserTopTrack : NamedEntry
+    {
+        public string Artist            { get { return Get<string>   ("artist"); } }
+        public int Rank                 { get { return Get<int>      ("rank"); } }
+        public int PlayCount            { get { return Get<int>      ("playcount"); } }
+    }
+
+    public class Friend : DataEntry
+    {
+        public string UserName          { get { return Get<string>   ("username"); } }
+        public string Url               { get { return Get<string>   ("url"); } }
+        public string ImageUrl          { get { return Get<string>   ("image"); } }
+    }
+
+    public class Neighbor : Friend
+    {
+        public double Match             { get { return Get<double>   ("match"); } }
+        public int MatchAsInt           { get { return (int) Math.Round (Match); } }
+    }
+
+    public class RecentTrack : NamedEntry
+    {
+        public string Artist            { get { return Get<string>   ("artist"); } }
+        public string Album             { get { return Get<string>   ("album"); } }
+        public DateTime Date            { get { return Get<DateTime> ("date"); } }
+    }
+
+    public class DateRangeEntry : DataEntry
+    {
+        public DateTime From            { get { return Get<DateTime> ("from"); } }
+        public DateTime To              { get { return Get<DateTime> ("to"); } }
+    }
+
+    public class ArtistChartEntry : NamedEntry
+    {
+        public string MbId              { get { return Get<string>   ("mbid"); } }
+        public int PlayCount            { get { return Get<int>      ("playcount"); } }
+        public int ChartPosition        { get { return Get<int>      ("chartposition"); } }
+    }
+
+    public class RecommendedArtistEntry : NamedEntry
+    {
+        public string MbId              { get { return Get<string>   ("mbid"); } }
+    }
+
+    public class EventEntry : RssEntry
+    {
+        public DateTime Begins          { get { return Get<DateTime> ("xcal:dtstart"); } }
+        public DateTime Ends            { get { return Get<DateTime> ("xcal:dtend"); } }
+    }
+
+    public class TasteArtist : RssEntry
+    {
+        public string Name              { get { return Get<string>   ("name"); } }
+    }
+
+    public class TasteEntry : DataEntry
+    {
+        public double Score             { get { return Get<double>   ("score"); } }
+
+        private DataEntryCollection<TasteArtist> artists;
+        public DataEntryCollection<TasteArtist> Artists {
+            get {
+                if (artists == null) {
+                    artists = new DataEntryCollection<TasteArtist> (Root ["commonArtists"].ChildNodes);
+                }
+                return artists;
+            }
+        }
+    }
 }

Added: trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/DataEntryCollection.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/DataEntryCollection.cs	Sun Feb 17 02:54:59 2008
@@ -0,0 +1,83 @@
+//
+// DataEntryCollection.cs
+//
+// Authors:
+//   Gabriel Burt <gburt novell com>
+//
+// Copyright (C) 2008 Novell, Inc.
+//
+// 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;
+using System.Xml;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace Lastfm.Data
+{
+    public class DataEntryCollection<T> : IEnumerable<T> where T : DataEntry
+    {
+        private XmlNodeList nodes;
+        private Dictionary<int, T> collection = new Dictionary<int, T> ();
+        private int count;
+
+        public DataEntryCollection (XmlDocument doc)
+        {
+            XmlNode node = doc.ChildNodes [doc.ChildNodes.Count - 1];
+            nodes = (node.Name == "rss") ? node.SelectNodes ("channel/items") : node.ChildNodes;
+            count = nodes.Count;
+        }
+
+        public DataEntryCollection (XmlNodeList nodes)
+        {
+            this.nodes = nodes;
+            count = nodes.Count;
+        }
+
+        public int Count {
+            get { return count; }
+        }
+
+        public T this[int i] {
+            get {
+                if (!collection.ContainsKey (i)) {
+                    T t = (T) Activator.CreateInstance (typeof(T));
+                    t.Root = nodes.Item (i);
+                    collection[i] = t;
+                }
+                return collection[i];
+            }
+        }
+
+        public IEnumerator<T> GetEnumerator ()
+        {
+            for (int i = 0; i < Count; i++) {
+                yield return this [i];
+            }
+        }
+
+        IEnumerator IEnumerable.GetEnumerator ()
+        {
+            return GetEnumerator ();
+        }
+    }
+}
+

Modified: trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/LastfmData.cs
==============================================================================
--- trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/LastfmData.cs	(original)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/LastfmData.cs	Sun Feb 17 02:54:59 2008
@@ -31,6 +31,8 @@
 using System.Net;
 using System.Web;
 using System.Xml;
+using System.Collections;
+using System.Collections.Generic;
 using ICSharpCode.SharpZipLib.GZip;
 
 using Hyena;
@@ -44,42 +46,29 @@
         Infinite
     }
 
-    public enum TopType {
-        Overall,
-        ThreeMonth,
-        SixMonth,
-        TwelveMonth,
-    }
-
-    public abstract class LastfmData
+    public abstract class LastfmData<T> : IEnumerable<T> where T : DataEntry
     {
-        private const int CACHE_VERSION = 2;
-        private static bool first_instance = true;
-
-        public static string UserAgent = null; //Banshee.Web.Browser.UserAgent;
-        public static string CachePath = null; //Path.Combine (Banshee.Base.Paths.UserPluginDirectory, "recommendation");
-        public static TimeSpan NormalCacheTime = TimeSpan.FromHours (2);
-
+        protected DataEntryCollection<T> collection;
         protected XmlDocument doc;
         protected string data_url;
         protected string cache_file;
         protected CacheDuration cache_duration;
 
-        public LastfmData (string dataUrlFragment) : this (dataUrlFragment, CacheDuration.Normal)
+        public LastfmData (string dataUrlFragment) : this (dataUrlFragment, CacheDuration.Normal, null)
         {
         }
 
-        public LastfmData (string dataUrlFragment, CacheDuration cacheDuration)
+        public LastfmData (string dataUrlFragment, string xpath) : this (dataUrlFragment, CacheDuration.Normal, xpath)
         {
-            if (CachePath == null || UserAgent == null) {
-                throw new NotSupportedException ("LastfmData.CachePath and/or LastfmData.Useragent are null.  Applications must set this value.");
-            }
+        }
 
-            if (first_instance) {
-                first_instance = false;
-                CheckForCacheWipe();
-                SetupCache();
-            }
+        public LastfmData (string dataUrlFragment, CacheDuration cacheDuration) : this (dataUrlFragment, cacheDuration, null)
+        {
+        }
+
+        public LastfmData (string dataUrlFragment, CacheDuration cacheDuration, string xpath)
+        {
+            DataCore.Initialize ();
 
             this.data_url = HostInjectionHack (String.Format ("http://ws.audioscrobbler.com/1.0/{0}";, dataUrlFragment));
             this.cache_file = GetCachedPathFromUrl (data_url);
@@ -93,23 +82,40 @@
             using (StreamReader reader = new StreamReader (cache_file)) {
                 doc.Load (reader);
             }
+
+            if (xpath == null) {
+                collection = new DataEntryCollection<T> (doc);
+            } else {
+                collection = new DataEntryCollection<T> (doc.SelectNodes (xpath));
+            }
         }
 
         public string DataUrl {
             get { return data_url; }
         }
 
-        protected static string TopTypeToParam (TopType type)
+#region DataEntryCollection wrapper
+
+        public int Count {
+            get { return collection.Count; }
+        }
+
+        public T this[int i] {
+            get { return collection [i]; }
+        }
+
+        public IEnumerator<T> GetEnumerator ()
         {
-            switch (type) {
-                case TopType.Overall:       return "overall";
-                case TopType.ThreeMonth:    return "3month";
-                case TopType.SixMonth:      return "6month";
-                case TopType.TwelveMonth:   return "12month";
-            }
-            return null;
+            return collection.GetEnumerator ();
+        }
+
+        IEnumerator IEnumerable.GetEnumerator ()
+        {
+            return collection.GetEnumerator ();
         }
 
+#endregion
+
 #region Private methods
 
         private void DownloadContent ()
@@ -118,14 +124,14 @@
             if (cache_duration != CacheDuration.None) {
                 if (File.Exists (cache_file)) {
                     DateTime last_updated_time = File.GetLastWriteTime (cache_file);
-                    if (cache_duration == CacheDuration.Infinite || DateTime.Now - last_updated_time < NormalCacheTime) {
+                    if (cache_duration == CacheDuration.Infinite || DateTime.Now - last_updated_time < DataCore.NormalCacheTime) {
                         return;
                     }
                 }
             }
             
             HttpWebRequest request = (HttpWebRequest) WebRequest.Create (data_url);
-            request.UserAgent = UserAgent;
+            request.UserAgent = DataCore.UserAgent;
             request.KeepAlive = false;
             
             using (HttpWebResponse response = (HttpWebResponse) request.GetResponse ()) {
@@ -160,7 +166,7 @@
         private static string GetCachedPathFromUrl (string url)
         {
             string hash = url.GetHashCode ().ToString ("X").ToLower ();
-            return Path.Combine (Path.Combine (CachePath, hash.Substring (0, 2)), hash);
+            return Path.Combine (Path.Combine (DataCore.CachePath, hash.Substring (0, 2)), hash);
         }
 
         // FIXME: This is to (try to) work around a bug in last.fm's XML
@@ -179,50 +185,6 @@
             return url;
         }
 
-        private void SetupCache()
-        {
-            bool clean = false;
-            
-            if(!Directory.Exists(CachePath)) {
-                clean = true;
-                Directory.CreateDirectory(CachePath);
-            }
-            
-            // Create our cache subdirectories.
-            for(int i = 0; i < 256; ++i) {
-                string subdir = i.ToString("x");
-                if(i < 16) {
-                    subdir = "0" + subdir;
-                }
-                
-                subdir = System.IO.Path.Combine(CachePath, subdir);
-                
-                if(!Directory.Exists(subdir)) {
-                    Directory.CreateDirectory(subdir);
-                }
-            }
-            
-            //RecommendationPlugin.CacheVersion.Set (CACHE_VERSION);
-            
-            if(clean) {
-                Log.Debug("Recommendation Plugin", "Created a new cache layout");
-            }
-        }
-
-        private void CheckForCacheWipe()
-        {
-            //bool wipe = false;
-            
-            if(!Directory.Exists(CachePath)) {
-                return;
-            }
-            
-            /*if (RecommendationPlugin.CacheVersion.Get() < CACHE_VERSION) {
-                Directory.Delete(CachePath, true);
-                Log.Debug("Recommendation Plugin", "Destroyed outdated cache");
-            }*/
-        }
-
 #endregion
 
     }

Modified: trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserData.cs
==============================================================================
--- trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserData.cs	(original)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserData.cs	Sun Feb 17 02:54:59 2008
@@ -30,16 +30,152 @@
 
 namespace Lastfm.Data
 {
-    public abstract class UserData<T> : LastfmDataCollection<T> where T : DataEntry
+    public enum TopType {
+        Overall,
+        ThreeMonth,
+        SixMonth,
+        TwelveMonth,
+    }
+
+    public class UserData<T> : LastfmData<T> where T : DataEntry
     {
         protected string username;
+        public string Username {
+            get { return username; }
+        }
+
+        public UserData (string username, string fragment) : this (username, fragment, null)
+        {
+        }
 
-        public UserData (string username, string fragment) : base (String.Format ("user/{0}/{1}", username, fragment))
+        public UserData (string username, string fragment, string xpath) : base (String.Format ("user/{0}/{1}", username, fragment), xpath)
         {
             this.username = username;
         }
+    }
+
+    public sealed class UserData
+    {
+        public static ProfileEntry GetProfile (string username)
+        {
+            return (new UserData<ProfileEntry> (username, "profile.xml", "/"))[0];
+        }
+
+        public static UserData<UserTopArtist> GetTopArtists (string username, TopType type)
+        {
+            return new UserData<UserTopArtist> (username, AppendType ("topartists.xml", type));
+        }
+
+        public static UserData<UserTopAlbum> GetTopAlbums (string username, TopType type)
+        {
+            return new UserData<UserTopAlbum> (username, AppendType ("topalbums.xml", type));
+        }
+
+        public static UserData<UserTopTrack> GetTopTracks (string username, TopType type)
+        {
+            return new UserData<UserTopTrack> (username, AppendType ("toptracks.xml", type));
+        }
+
+        public static UserData<TopTag> GetTopTags (string username)
+        {
+            return new UserData<TopTag> (username, "tags.xml");
+        }
+
+        public static UserData<TopTag> GetTopTagsForArtist (string username, string artist)
+        {
+            return new UserData<TopTag> (username, String.Format ("artisttags.xml?artist={0}", artist));
+        }
+
+        public static UserData<TopTag> GetTopTagsForAlbum (string username, string artist, string album)
+        {
+            return new UserData<TopTag> (username, String.Format ("albumtags.xml?artist={0}&album={1}", artist, album));
+        }
+
+        public static UserData<TopTag> GetTopTagsForTrack (string username, string artist, string track)
+        {
+            return new UserData<TopTag> (username, String.Format ("tracktags.xml?artist={0}&track={1}", artist, track));
+        }
+
+        public static UserData<Friend> GetFriends (string username)
+        {
+            return new UserData<Friend> (username, "friends.xml");
+        }
+
+        public static UserData<Neighbor> GetNeighbors (string username)
+        {
+            return new UserData<Neighbor> (username, "neighbours.xml");
+        }
 
-        public string Username { get { return username; } }
+        public static UserData<RecentTrack> GetRecentTracks (string username)
+        {
+            return new UserData<RecentTrack> (username, "recenttracks.xml");
+        }
+
+        public static UserData<RecentTrack> GetRecentLovedTracks (string username)
+        {
+            return new UserData<RecentTrack> (username, "recentlovedtracks.xml");
+        }
+
+        public static UserData<RecentTrack> GetRecentBannedTracks (string username)
+        {
+            return new UserData<RecentTrack> (username, "recentbannedtracks.xml");
+        }
+
+        public static UserData<RssEntry> GetRecentJournalEntries (string username)
+        {
+            return new UserData<RssEntry> (username, "journals.rss");
+        }
+
+        public static UserData<DateRangeEntry> GetWeeklyChartList (string username)
+        {
+            return new UserData<DateRangeEntry> (username, "weeklychartlist.xml");
+        }
+
+        public static UserData<ArtistChartEntry> GetWeeklyArtistChart (string username)
+        {
+            return new UserData<ArtistChartEntry> (username, "weeklyartistchart.xml");
+        }
+
+        public static UserData<RecommendedArtistEntry> GetRecommendedArtists (string username)
+        {
+            return new UserData<RecommendedArtistEntry> (username, "systemrecs.xml");
+        }
+
+        public static UserData<RssEntry> GetManualRecommendations (string username)
+        {
+            return new UserData<RssEntry> (username, "manualrecs.rss");
+        }
+
+        public static UserData<EventEntry> GetFriendsEvents (string username)
+        {
+            return new UserData<EventEntry> (username, "friendevents.rss");
+        }
+
+        public static UserData<EventEntry> GetRecommendedEvents (string username)
+        {
+            return new UserData<EventEntry> (username, "eventsysrecs.rss");
+        }
+
+        public static TasteEntry GetTasteOMeter (string username, string other_username)
+        {
+            return (new UserData<TasteEntry> (username, String.Format ("tasteometer.xml?with={0}", other_username)))[0];
+        }
+
+        private static string AppendType (string fragment, TopType type)
+        {
+            return String.Format ("{0}?type={1}", fragment, TopTypeToParam (type));
+        }
+
+        protected static string TopTypeToParam (TopType type)
+        {
+            switch (type) {
+                case TopType.Overall:       return "overall";
+                case TopType.ThreeMonth:    return "3month";
+                case TopType.SixMonth:      return "6month";
+                case TopType.TwelveMonth:   return "12month";
+            }
+            return null;
+        }
     }
 }
 

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 17 02:54:59 2008
@@ -6,15 +6,16 @@
 	Lastfm/Account.cs \
 	Lastfm/Browser.cs \
 	Lastfm/Connection.cs \
+	Lastfm.Data/DataCore.cs \
 	Lastfm.Data/DataEntry.cs \
+	Lastfm.Data/DataEntryCollection.cs \
 	Lastfm.Data/LastfmData.cs \
-	Lastfm.Data/LastfmDataCollection.cs \
-	Lastfm.Data/UserData.cs \
-	Lastfm.Data/UserTopData.cs \
-	Lastfm.Data/UserTopArtists.cs \
-	Lastfm.Data/UserTopAlbums.cs \
-	Lastfm.Data/UserTopTracks.cs \
-	Lastfm.Data/Profile.cs
+	Lastfm.Data/UserData.cs 
 
 include $(top_srcdir)/build/build.mk
 
+test: Test.cs
+	gmcs -r:$(top_builddir)/bin/Lastfm.dll -out:TestLastfm.exe Test.cs && \
+	mv TestLastfm.exe $(top_builddir)/bin/
+	@pushd $(top_builddir)/bin/; mono --debug TestLastfm.exe; \
+	popd;



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