banshee r3241 - in trunk/banshee: . src/Libraries/Lastfm src/Libraries/Lastfm/Lastfm src/Libraries/Lastfm/Lastfm.Data
- From: gburt svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r3241 - in trunk/banshee: . src/Libraries/Lastfm src/Libraries/Lastfm/Lastfm src/Libraries/Lastfm/Lastfm.Data
- Date: Fri, 15 Feb 2008 21:06:03 +0000 (GMT)
Author: gburt
Date: Fri Feb 15 21:06:02 2008
New Revision: 3241
URL: http://svn.gnome.org/viewvc/banshee?rev=3241&view=rev
Log:
2008-02-14 Gabriel Burt <gabriel burt gmail com>
* src/Libraries/Lastfm/Lastfm/Connection.cs: Fix warnings.
* src/Libraries/Lastfm/Makefile.am:
* src/Libraries/Lastfm/Lastfm.Data: Add new namespace.
* src/Libraries/Lastfm/Lastfm.Data/DataEntry.cs:
* src/Libraries/Lastfm/Lastfm.Data/UserTopArtists.cs:
* src/Libraries/Lastfm/Lastfm.Data/UserTopData.cs:
* src/Libraries/Lastfm/Lastfm.Data/LastfmDataCollection.cs:
* src/Libraries/Lastfm/Lastfm.Data/LastfmData.cs:
* src/Libraries/Lastfm/Lastfm.Data/Profile.cs:
* src/Libraries/Lastfm/Lastfm.Data/UserTopAlbums.cs:
* src/Libraries/Lastfm/Lastfm.Data/UserData.cs:
* src/Libraries/Lastfm/Lastfm.Data/UserTopTracks.cs: New files that expose
Last.fm metadata.
Added:
trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/
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/LastfmDataCollection.cs
trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/Profile.cs
trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserData.cs (contents, props changed)
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 (contents, props changed)
trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserTopTracks.cs
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Libraries/Lastfm/Lastfm/Connection.cs
trunk/banshee/src/Libraries/Lastfm/Makefile.am
Added: trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/DataEntry.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/DataEntry.cs Fri Feb 15 21:06:02 2008
@@ -0,0 +1,63 @@
+//
+// DataEntry.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 DataEntry
+ {
+ private XmlNode root;
+ public XmlNode Root {
+ get { return root; }
+ set { root = value; }
+ }
+
+ public DataEntry ()
+ {
+ }
+
+ public DataEntry (XmlNode root)
+ {
+ this.root = root;
+ }
+
+ public T Get<T> (string name)
+ {
+ try {
+ XmlNode node = root[name];
+ return (T) Convert.ChangeType (node.InnerText, typeof(T));
+ } catch (Exception) {
+ return default(T);
+ }
+ }
+ }
+}
Added: trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/LastfmData.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/LastfmData.cs Fri Feb 15 21:06:02 2008
@@ -0,0 +1,230 @@
+//
+// LastfmData.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 System.Net;
+using System.Web;
+using System.Xml;
+using ICSharpCode.SharpZipLib.GZip;
+
+using Hyena;
+
+namespace Lastfm.Data
+{
+ public enum CacheDuration
+ {
+ None = 0,
+ Normal,
+ Infinite
+ }
+
+ public enum TopType {
+ Overall,
+ ThreeMonth,
+ SixMonth,
+ TwelveMonth,
+ }
+
+ public abstract class LastfmData
+ {
+ 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 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, CacheDuration cacheDuration)
+ {
+ 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();
+ }
+
+ this.data_url = HostInjectionHack (String.Format ("http://ws.audioscrobbler.com/1.0/{0}", dataUrlFragment));
+ this.cache_file = GetCachedPathFromUrl (data_url);
+ this.cache_duration = cacheDuration;
+
+ // Download the content if necessary
+ DownloadContent ();
+
+ // Load the XML from the new or cached local file
+ doc = new XmlDocument ();
+ using (StreamReader reader = new StreamReader (cache_file)) {
+ doc.Load (reader);
+ }
+ }
+
+ public string DataUrl {
+ get { return data_url; }
+ }
+
+ 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;
+ }
+
+#region Private methods
+
+ private void DownloadContent ()
+ {
+ // See if we have a valid cached copy
+ 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) {
+ return;
+ }
+ }
+ }
+
+ HttpWebRequest request = (HttpWebRequest) WebRequest.Create (data_url);
+ request.UserAgent = UserAgent;
+ request.KeepAlive = false;
+
+ using (HttpWebResponse response = (HttpWebResponse) request.GetResponse ()) {
+ using (Stream stream = GetResponseStream (response)) {
+ using (FileStream file_stream = File.Open (cache_file, FileMode.Create)) {
+ using (BufferedStream buffered_stream = new BufferedStream (file_stream)) {
+ byte [] buffer = new byte[8192];
+ int read;
+
+ while (true) {
+ read = stream.Read (buffer, 0, buffer.Length);
+ if (read <= 0) {
+ break;
+ }
+
+ buffered_stream.Write (buffer, 0, read);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private static Stream GetResponseStream (HttpWebResponse response)
+ {
+ return response.ContentEncoding == "gzip"
+ ? new GZipInputStream (response.GetResponseStream ())
+ : response.GetResponseStream ();
+ }
+
+
+ private static string GetCachedPathFromUrl (string url)
+ {
+ string hash = url.GetHashCode ().ToString ("X").ToLower ();
+ return Path.Combine (Path.Combine (CachePath, hash.Substring (0, 2)), hash);
+ }
+
+ // FIXME: This is to (try to) work around a bug in last.fm's XML
+ // Some XML nodes with URIs as content do not return a URI with a
+ // host name. It appears that in these cases the hostname is to be
+ // static3.last.fm, but it may not always be the case - this is
+ // a bug in last.fm, but we attempt to work around it here
+ // http://bugzilla.gnome.org/show_bug.cgi?id=408068
+
+ private static string HostInjectionHack (string url)
+ {
+ if (url.StartsWith ("http:///storable/")) {
+ url = url.Insert (7, "static3.last.fm");
+ }
+
+ 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
+
+ }
+}
+
Added: trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/LastfmDataCollection.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/LastfmDataCollection.cs Fri Feb 15 21:06:02 2008
@@ -0,0 +1,90 @@
+//
+// LastfmDataCollection.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 LastfmDataCollection<T> : LastfmData, IEnumerable<T> where T : DataEntry
+ {
+ private XmlNode root;
+ private Dictionary<int, T> collection = new Dictionary<int, T> ();
+ private int count;
+
+ public LastfmDataCollection (string dataUrlFragment) : base (dataUrlFragment)
+ {
+ Initialize ();
+ }
+
+ public LastfmDataCollection (string dataUrlFragment, CacheDuration cacheDuration) : base (dataUrlFragment, cacheDuration)
+ {
+ Initialize ();
+ }
+
+ private void Initialize ()
+ {
+ if (doc.ChildNodes.Count == 2)
+ root = doc.ChildNodes [1];
+ else
+ root = doc.FirstChild;
+
+ count = root.ChildNodes.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 = root.ChildNodes.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 ();
+ }
+ }
+}
+
Added: trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/Profile.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/Profile.cs Fri Feb 15 21:06:02 2008
@@ -0,0 +1,74 @@
+//
+// Profile.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.Collections;
+using System.Xml;
+using System.Security.Cryptography;
+
+namespace Lastfm.Data
+{
+ // http://ws.audioscrobbler.com/1.0/user/RJ/profile.xml
+ // <profile id="1000002" cluster="2" username="RJ">
+ // <url>http://www.last.fm/user/RJ/</url>
+ // <realname>Richard Jones </realname>
+ // <mbox_sha1sum>0bf0949e67cffa83c66fd806e817dda3083c4d8b</mbox_sha1sum>
+ // <registered unixtime="1037793040">Nov 20, 2002</registered>
+ // <age>25</age>
+ // <gender>m</gender>
+ // <country>United Kingdom</country>
+ // <playcount>50644</playcount>
+ // <avatar>http://userserve-ak.last.fm/serve/160/622321.jpg</avatar>
+ // <icon>http://cdn.last.fm/depth/global/icon_staff.gif</icon>
+ // </profile>
+
+ public class Profile : LastfmData
+ {
+ private DataEntry profile;
+ private string username;
+
+ public Profile (string username) : base (String.Format ("user/{0}/profile.xml", username))
+ {
+ this.username = username;
+ profile = new DataEntry (doc["profile"]);
+ Console.WriteLine ("in profile have:\n{0}", doc.FirstChild.InnerXml);
+ }
+
+ public string Username { get { return username; } }
+ public string Url { get { return profile.Get<string> ("url"); } }
+ public string RealName { get { return profile.Get<string> ("realname"); } }
+ public string Gender { get { return profile.Get<string> ("gender"); } }
+ public string Country { get { return profile.Get<string> ("country"); } }
+ public string AvatarUrl { get { return profile.Get<string> ("avatar"); } }
+ public string IconUrl { get { return profile.Get<string> ("icon"); } }
+ public DateTime Registered { get { return profile.Get<DateTime> ("registered"); } }
+ public int Age { get { return profile.Get<int> ("age"); } }
+ public int PlayCount { get { return profile.Get<int> ("playcount"); } }
+ }
+}
+
Added: trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserData.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserData.cs Fri Feb 15 21:06:02 2008
@@ -0,0 +1,48 @@
+//
+// UserData.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.Collections;
+using System.Text;
+using System.Security.Cryptography;
+
+namespace Lastfm.Data
+{
+ public abstract class UserData<T> : LastfmDataCollection<T> where T : DataEntry
+ {
+ protected string username;
+
+ public UserData (string username, string fragment) : base (String.Format ("user/{0}/{1}", username, fragment))
+ {
+ this.username = username;
+ }
+
+ public string Username { get { return username; } }
+ }
+}
+
Added: trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserTopAlbums.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserTopAlbums.cs Fri Feb 15 21:06:02 2008
@@ -0,0 +1,56 @@
+//
+// UserTopAlbums.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.Collections;
+using System.Text;
+using System.Security.Cryptography;
+
+namespace Lastfm.Data
+{
+ // <topalbums user="RJ" type="overall">
+ // <album>
+ // <artist mbid="28503ab7-8bf2-4666-a7bd-2644bfc7cb1d">Dream Theater</artist>
+ // <name>Images and Words</name>
+ // <mbid>f20971f2-c8ad-4d26-91ab-730f6dedafb2</mbid>
+ // <playcount>154</playcount>
+ // <rank>1</rank>
+ // <url>http://www.last.fm/music/Dream+Theater/Images+and+Words</url>
+ // </album>
+ public class UserTopAlbums : UserTopData<TopAlbum>
+ {
+ public UserTopAlbums (string username, TopType type) : base (username, "topalbums.xml", type)
+ {
+ }
+ }
+
+ public class TopAlbum : UserTopEntry
+ {
+ public string Artist { get { return Get<string> ("artist"); } }
+ }
+}
Added: trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserTopArtists.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserTopArtists.cs Fri Feb 15 21:06:02 2008
@@ -0,0 +1,59 @@
+//
+// UserTopArtists.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.Collections;
+using System.Text;
+using System.Security.Cryptography;
+
+namespace Lastfm.Data
+{
+ // <topartists user="RJ" type="overall">
+ // <artist>
+ // <name>Dream Theater</name>
+ // <mbid>28503ab7-8bf2-4666-a7bd-2644bfc7cb1d</mbid>
+ // <playcount>1211</playcount>
+ // <rank>1</rank>
+ // <url>http://www.last.fm/music/Dream+Theater</url>
+ // <thumbnail>http://userserve-ak.last.fm/serve/50/235557.jpg</thumbnail>
+ // <image>http://userserve-ak.last.fm/serve/160/235557.jpg</image>
+ // </artist>
+ // </topartists>
+ public class UserTopArtists : UserTopData<TopArtist>
+ {
+ public UserTopArtists (string username, TopType type) : base (username, "topartists.xml", type)
+ {
+ }
+ }
+
+ public class TopArtist : UserTopEntry
+ {
+ public string ThumbnailUrl { get { return Get<string> ("thumbnail"); } }
+ public string ImageUrl { get { return Get<string> ("image"); } }
+ }
+}
Added: trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserTopData.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserTopData.cs Fri Feb 15 21:06:02 2008
@@ -0,0 +1,58 @@
+//
+// UserTopData.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.Collections;
+using System.Text;
+using System.Security.Cryptography;
+
+namespace Lastfm.Data
+{
+ public abstract class UserTopData<T> : UserData<T> where T : UserTopEntry
+ {
+ protected TopType type;
+ public TopType Type {
+ get { return type; }
+ }
+
+ public UserTopData (string username, string fragment, TopType type)
+ : base (username, String.Format ("{0}?type={1}", fragment, TopTypeToParam (type)))
+ {
+ this.type = type;
+ }
+ }
+
+ public abstract class UserTopEntry : DataEntry
+ {
+ public string Name { get { return Get<string> ("name"); } }
+ public string MbId { get { return Get<string> ("mbid"); } }
+ public int PlayCount { get { return Get<int> ("playcount"); } }
+ public int Rank { get { return Get<int> ("rank"); } }
+ public string Url { get { return Get<string> ("url"); } }
+ }
+}
Added: trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserTopTracks.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm.Data/UserTopTracks.cs Fri Feb 15 21:06:02 2008
@@ -0,0 +1,56 @@
+//
+// UserTopTracks.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.Collections;
+using System.Text;
+using System.Security.Cryptography;
+
+namespace Lastfm.Data
+{
+ // <toptracks user="RJ" type="overall">
+ // <track>
+ // <artist mbid="bc641be9-ca36-4c61-9394-5230433f6646">Liquid Tension Experiment</artist>
+ // <name>Three Minute Warning</name>
+ // <mbid/>
+ // <playcount>40</playcount>
+ // <rank>1</rank>
+ // <url>http://www.last.fm/music/Liquid+Tension+Experiment/_/Three+Minute+Warning</url>
+ // </track>
+ public class UserTopTracks : UserTopData<TopTrack>
+ {
+ public UserTopTracks (string username, TopType type) : base (username, "toptracks.xml", type)
+ {
+ }
+ }
+
+ public class TopTrack : UserTopEntry
+ {
+ public string Artist { get { return Get<string> ("artist"); } }
+ }
+}
Modified: trunk/banshee/src/Libraries/Lastfm/Lastfm/Connection.cs
==============================================================================
--- trunk/banshee/src/Libraries/Lastfm/Lastfm/Connection.cs (original)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm/Connection.cs Fri Feb 15 21:06:02 2008
@@ -87,7 +87,6 @@
private string base_url;
private string base_path;
private string info_message;
- private bool connect_requested = false;
private bool network_connected = false;
private static Regex station_error_regex = new Regex ("error=(\\d+)", RegexOptions.Compiled);
@@ -102,6 +101,10 @@
get { return subscriber; }
}
+ public string InfoMessage {
+ get { return info_message; }
+ }
+
public ConnectionState State {
get { return state; }
@@ -145,7 +148,6 @@
public void Connect ()
{
- connect_requested = true;
if (State == ConnectionState.Connecting || State == ConnectionState.Connected)
return;
@@ -353,7 +355,7 @@
}
HttpWebRequest request = (HttpWebRequest) WebRequest.Create (uri);
- request.UserAgent = user_agent; //Banshee.Web.Browser.UserAgent;
+ request.UserAgent = user_agent;
request.Timeout = 10000;
request.Method = "POST";
request.KeepAlive = false;
@@ -393,7 +395,7 @@
if (accept != null) {
request.Accept = accept;
}
- request.UserAgent = user_agent; //Banshee.Web.Browser.UserAgent;
+ request.UserAgent = user_agent;
request.Timeout = 10000;
request.KeepAlive = false;
request.AllowAutoRedirect = true;
Modified: trunk/banshee/src/Libraries/Lastfm/Makefile.am
==============================================================================
--- trunk/banshee/src/Libraries/Lastfm/Makefile.am (original)
+++ trunk/banshee/src/Libraries/Lastfm/Makefile.am Fri Feb 15 21:06:02 2008
@@ -5,7 +5,16 @@
SOURCES = \
Lastfm/Account.cs \
Lastfm/Browser.cs \
- Lastfm/Connection.cs
+ Lastfm/Connection.cs \
+ Lastfm.Data/DataEntry.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
include $(top_srcdir)/build/build.mk
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]