banshee r3685 - in trunk/banshee: . src/Core/Banshee.Core/Resources src/Libraries/MusicBrainz src/Libraries/MusicBrainz/MusicBrainz
- From: scottp svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r3685 - in trunk/banshee: . src/Core/Banshee.Core/Resources src/Libraries/MusicBrainz src/Libraries/MusicBrainz/MusicBrainz
- Date: Sun, 6 Apr 2008 03:38:29 +0100 (BST)
Author: scottp
Date: Sun Apr 6 03:38:28 2008
New Revision: 3685
URL: http://svn.gnome.org/viewvc/banshee?rev=3685&view=rev
Log:
* src/Libraries/MusicBrainz/*: Synced w/ MB#
Added:
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/LinuxDisc.cs
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Win32Disc.cs
Removed:
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/DiscLinux.cs
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/DiscWin32.cs
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Core/Banshee.Core/Resources/translators.xml
trunk/banshee/src/Libraries/MusicBrainz/Makefile.am
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz.mdp
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Artist.cs
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Disc.cs
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Event.cs
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Label.cs
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/LocalDisc.cs
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzEntity.cs
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzException.cs
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzItem.cs
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzObject.cs
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzService.cs
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Query.cs
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Relation.cs
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Release.cs
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Track.cs
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Utils.cs
trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/XmlRequestEventArgs.cs
Modified: trunk/banshee/src/Core/Banshee.Core/Resources/translators.xml
==============================================================================
--- trunk/banshee/src/Core/Banshee.Core/Resources/translators.xml (original)
+++ trunk/banshee/src/Core/Banshee.Core/Resources/translators.xml Sun Apr 6 03:38:28 2008
@@ -94,7 +94,6 @@
</language>
<language code="pl" name="Polish">
<person>Tomasz Dominikowski</person>
- <person>wadim dziedzic</person>
</language>
<language code="pt" name="Portuguese">
<person>Filipe Gomes</person>
Modified: trunk/banshee/src/Libraries/MusicBrainz/Makefile.am
==============================================================================
--- trunk/banshee/src/Libraries/MusicBrainz/Makefile.am (original)
+++ trunk/banshee/src/Libraries/MusicBrainz/Makefile.am Sun Apr 6 03:38:28 2008
@@ -4,10 +4,9 @@
SOURCES = \
MusicBrainz/Artist.cs \
MusicBrainz/Disc.cs \
- MusicBrainz/DiscLinux.cs \
- MusicBrainz/DiscWin32.cs \
MusicBrainz/Event.cs \
MusicBrainz/Label.cs \
+ MusicBrainz/LinuxDisc.cs \
MusicBrainz/LocalDisc.cs \
MusicBrainz/MusicBrainzEntity.cs \
MusicBrainz/MusicBrainzException.cs \
@@ -19,6 +18,7 @@
MusicBrainz/Release.cs \
MusicBrainz/Track.cs \
MusicBrainz/Utils.cs \
+ MusicBrainz/Win32Disc.cs \
MusicBrainz/XmlRequestEventArgs.cs
include $(top_srcdir)/build/build.mk
Modified: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz.mdp
==============================================================================
--- trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz.mdp (original)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz.mdp Sun Apr 6 03:38:28 2008
@@ -10,10 +10,9 @@
<Contents>
<File name="MusicBrainz/Artist.cs" subtype="Code" buildaction="Compile" />
<File name="MusicBrainz/Disc.cs" subtype="Code" buildaction="Compile" />
- <File name="MusicBrainz/DiscLinux.cs" subtype="Code" buildaction="Compile" />
- <File name="MusicBrainz/DiscWin32.cs" subtype="Code" buildaction="Compile" />
<File name="MusicBrainz/Event.cs" subtype="Code" buildaction="Compile" />
<File name="MusicBrainz/Label.cs" subtype="Code" buildaction="Compile" />
+ <File name="MusicBrainz/LinuxDisc.cs" subtype="Code" buildaction="Compile" />
<File name="MusicBrainz/LocalDisc.cs" subtype="Code" buildaction="Compile" />
<File name="MusicBrainz/MusicBrainzEntity.cs" subtype="Code" buildaction="Compile" />
<File name="MusicBrainz/MusicBrainzException.cs" subtype="Code" buildaction="Compile" />
@@ -25,6 +24,7 @@
<File name="MusicBrainz/Release.cs" subtype="Code" buildaction="Compile" />
<File name="MusicBrainz/Track.cs" subtype="Code" buildaction="Compile" />
<File name="MusicBrainz/Utils.cs" subtype="Code" buildaction="Compile" />
+ <File name="MusicBrainz/Win32Disc.cs" subtype="Code" buildaction="Compile" />
<File name="MusicBrainz/XmlRequestEventArgs.cs" subtype="Code" buildaction="Compile" />
</Contents>
<References>
@@ -40,4 +40,4 @@
<AsmRefVar />
<ProjectRefVar />
</MonoDevelop.Autotools.MakefileInfo>
-</Project>
\ No newline at end of file
+</Project>
Modified: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Artist.cs
==============================================================================
--- trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Artist.cs (original)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Artist.cs Sun Apr 6 03:38:28 2008
@@ -1,3 +1,5 @@
+#region License
+
// Artist.cs
//
// Copyright (c) 2008 Scott Peterson <lunchtimemama gmail com>
@@ -19,7 +21,8 @@
// 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.
-//
+
+#endregion
using System;
using System.Collections.Generic;
@@ -29,57 +32,18 @@
namespace MusicBrainz
{
- public enum ArtistType
- {
- Unknown,
- Group,
- Person
- }
-
- public sealed class ArtistReleaseType
+ public sealed class Artist : MusicBrainzEntity
{
- string str;
-
- public ArtistReleaseType (ReleaseType type, bool various) : this ((Enum)type, various)
- {
- }
-
- public ArtistReleaseType (ReleaseStatus status, bool various) : this ((Enum)status, various)
- {
- }
- public ArtistReleaseType (ReleaseType type, ReleaseStatus status, bool various)
- {
- StringBuilder builder = new StringBuilder ();
- Format (builder, type, various);
- builder.Append ('+');
- Format (builder, status, various);
- str = builder.ToString ();
- }
-
- ArtistReleaseType (Enum enumeration, bool various)
- {
- StringBuilder builder = new StringBuilder ();
- Format (builder, enumeration, various);
- str = builder.ToString ();
- }
+ #region Private
- void Format (StringBuilder builder, Enum enumeration, bool various)
- {
- builder.Append (various ? "va-" : "sa-");
- Utils.EnumToString (builder, enumeration.ToString ());
- }
-
- public override string ToString ()
- {
- return str;
- }
-
- }
-
- public sealed class Artist : MusicBrainzEntity
- {
const string EXTENSION = "artist";
+ ArtistReleaseType artist_release_type = DefaultArtistReleaseType;
+ ArtistType? type;
+ ReadOnlyCollection<Release> releases;
+ bool have_all_releases;
+
+ #endregion
#region Constructors
@@ -104,7 +68,7 @@
#endregion
- #region Protected Overrides
+ #region Protected
protected override string UrlExtension {
get { return EXTENSION; }
@@ -168,8 +132,6 @@
public static ArtistReleaseType DefaultArtistReleaseType =
new ArtistReleaseType (ReleaseStatus.Official, false);
- ArtistReleaseType artist_release_type = DefaultArtistReleaseType;
-
public ArtistReleaseType ArtistReleaseType {
get { return artist_release_type; }
set {
@@ -189,14 +151,11 @@
get { return base.Name; }
}
- ArtistType? type;
[Queryable ("artype")]
public ArtistType Type {
get { return GetPropertyOrDefault (ref type, ArtistType.Unknown); }
}
- ReadOnlyCollection<Release> releases;
- bool have_all_releases;
public ReadOnlyCollection<Release> Releases {
get {
return releases ?? (have_all_releases
@@ -235,4 +194,57 @@
#endregion
}
+
+ #region Ancillary Types
+
+ public enum ArtistType
+ {
+ Unknown,
+ Group,
+ Person
+ }
+
+ public sealed class ArtistReleaseType
+ {
+ string str;
+
+ public ArtistReleaseType (ReleaseType type, bool various) : this ((Enum)type, various)
+ {
+ }
+
+ public ArtistReleaseType (ReleaseStatus status, bool various) : this ((Enum)status, various)
+ {
+ }
+
+ public ArtistReleaseType (ReleaseType type, ReleaseStatus status, bool various)
+ {
+ StringBuilder builder = new StringBuilder ();
+ Format (builder, type, various);
+ builder.Append ('+');
+ Format (builder, status, various);
+ str = builder.ToString ();
+ }
+
+ ArtistReleaseType (Enum enumeration, bool various)
+ {
+ StringBuilder builder = new StringBuilder ();
+ Format (builder, enumeration, various);
+ str = builder.ToString ();
+ }
+
+ void Format (StringBuilder builder, Enum enumeration, bool various)
+ {
+ builder.Append (various ? "va-" : "sa-");
+ Utils.EnumToString (builder, enumeration.ToString ());
+ }
+
+ public override string ToString ()
+ {
+ return str;
+ }
+
+ }
+
+ #endregion
+
}
Modified: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Disc.cs
==============================================================================
--- trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Disc.cs (original)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Disc.cs Sun Apr 6 03:38:28 2008
@@ -1,3 +1,5 @@
+#region License
+
// Disc.cs
//
// Copyright (c) 2008 Scott Peterson <lunchtimemama gmail com>
@@ -19,7 +21,8 @@
// 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.
-//
+
+#endregion
using System;
using System.Xml;
Modified: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Event.cs
==============================================================================
--- trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Event.cs (original)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Event.cs Sun Apr 6 03:38:28 2008
@@ -1,3 +1,5 @@
+#region License
+
// Event.cs
//
// Copyright (c) 2008 Scott Peterson <lunchtimemama gmail com>
@@ -19,7 +21,8 @@
// 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.
-//
+
+#endregion
using System;
using System.Xml;
Modified: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Label.cs
==============================================================================
--- trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Label.cs (original)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Label.cs Sun Apr 6 03:38:28 2008
@@ -1,3 +1,5 @@
+#region License
+
// Label.cs
//
// Copyright (c) 2008 Scott Peterson <lunchtimemama gmail com>
@@ -19,7 +21,8 @@
// 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.
-//
+
+#endregion
using System;
using System.Text;
@@ -27,23 +30,18 @@
namespace MusicBrainz
{
- public enum LabelType
- {
- Unspecified,
- Distributor,
- Holding,
- OriginalProduction,
- BootlegProduction,
- ReissueProduction
- }
-
public sealed class Label : MusicBrainzEntity
{
+
+ #region Private
+
const string EXTENSION = "label";
+ string country;
+ LabelType? type;
- protected override string UrlExtension {
- get { return EXTENSION; }
- }
+ #endregion
+
+ #region Constructors
Label (string mbid) : base (mbid, null)
{
@@ -56,6 +54,14 @@
internal Label (XmlReader reader) : base (reader, false)
{
}
+
+ #endregion
+
+ #region Protected
+
+ protected override string UrlExtension {
+ get { return EXTENSION; }
+ }
protected override void LoadMissingDataCore ()
{
@@ -85,17 +91,21 @@
reader.Close ();
return result;
}
+
+ #endregion
- string country;
+ #region Properties
+
public string Country {
get { return GetPropertyOrNull (ref country); }
}
- LabelType? type;
public LabelType Type {
- get { return GetPropertyOrDefault (ref type, LabelType.Unspecified); }
+ get { return GetPropertyOrDefault (ref type, LabelType.None); }
}
+ #endregion
+
#region Static
public static Label Get (string mbid)
@@ -124,4 +134,19 @@
#endregion
}
+
+ #region Ancillary Types
+
+ public enum LabelType
+ {
+ None,
+ Distributor,
+ Holding,
+ OriginalProduction,
+ BootlegProduction,
+ ReissueProduction
+ }
+
+ #endregion
+
}
Added: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/LinuxDisc.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/LinuxDisc.cs Sun Apr 6 03:38:28 2008
@@ -0,0 +1,166 @@
+#region License
+
+// LinuxDisc.cs
+//
+// Copyright (c) 2008 Scott Peterson <lunchtimemama gmail com>
+//
+// 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.
+
+#endregion
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace MusicBrainz
+{
+ internal sealed class LinuxDisc : LocalDisc
+ {
+ const int O_RDONLY = 0x0;
+ const int O_NONBLOCK = 0x4000;
+ const int CDROMREADTOCHDR = 0x5305;
+ const int CDROMREADTOCENTRY = 0x5306;
+ const int CDROMMULTISESSION = 0x5310;
+ const int CDROM_LBA = 0x01;
+ const int CDROM_LEADOUT = 0xAA;
+ const int CD_FRAMES = 75;
+ const int XA_INTERVAL = ((60 + 90 + 2) * CD_FRAMES);
+
+ [DllImport ("libc.so.6")]
+ static extern int open (string path, int flags);
+
+ [DllImport ("libc.so.6")]
+ static extern int close (int fd);
+
+ [DllImport ("libc.so.6", EntryPoint = "ioctl")]
+ static extern int read_toc_header (int fd, int request, ref cdrom_tochdr header);
+ static int read_toc_header (int fd, ref cdrom_tochdr header)
+ {
+ return read_toc_header (fd, CDROMREADTOCHDR, ref header);
+ }
+
+ [DllImport ("libc.so.6", EntryPoint = "ioctl")]
+ static extern int read_multisession (int fd, int request, ref cdrom_multisession multisession);
+ static int read_multisession (int fd, ref cdrom_multisession multisession)
+ {
+ return read_multisession (fd, CDROMMULTISESSION, ref multisession);
+ }
+
+ [DllImport ("libc.so.6", EntryPoint = "ioctl")]
+ static extern int read_toc_entry (int fd, int request, ref cdrom_tocentry entry);
+ static int read_toc_entry (int fd, ref cdrom_tocentry entry)
+ {
+ return read_toc_entry (fd, CDROMREADTOCENTRY, ref entry);
+ }
+
+ struct cdrom_tochdr
+ {
+ public byte cdth_trk0;
+ public byte cdth_trk1;
+ }
+
+ struct cdrom_tocentry
+ {
+ public byte cdte_track;
+ public byte adr_ctrl;
+ public byte cdte_format;
+ public int lba;
+ public byte cdte_datamode;
+ }
+
+ struct cdrom_multisession
+ {
+ public int lba;
+ public byte xa_flag;
+ public byte addr_format;
+ }
+
+ int ReadTocHeader (int fd)
+ {
+ cdrom_tochdr th = new cdrom_tochdr ();
+ cdrom_multisession ms = new cdrom_multisession ();
+
+ int ret = read_toc_header (fd, ref th);
+
+ if (ret < 0) return ret;
+
+ FirstTrack = th.cdth_trk0;
+ LastTrack = th.cdth_trk1;
+
+ ms.addr_format = CDROM_LBA;
+ ret = read_multisession (fd, ref ms);
+
+ if(ms.xa_flag != 0) LastTrack--;
+
+ return ret;
+ }
+
+ int ReadTocEntry (int fd, byte track_number, ref ulong lba)
+ {
+ cdrom_tocentry te = new cdrom_tocentry ();
+ te.cdte_track = track_number;
+ te.cdte_format = CDROM_LBA;
+
+ int ret = read_toc_entry (fd, ref te);
+
+ if(ret == 0) lba = (ulong)te.lba;
+
+ return ret;
+ }
+
+ int ReadLeadout (int fd, ref ulong lba)
+ {
+ cdrom_multisession ms = new cdrom_multisession ();
+ ms.addr_format = CDROM_LBA;
+
+ int ret = read_multisession (fd, ref ms);
+
+ if (ms.xa_flag != 0) {
+ lba = (ulong)(ms.lba - XA_INTERVAL);
+ return ret;
+ }
+
+ return ReadTocEntry (fd, CDROM_LEADOUT, ref lba);
+ }
+
+ internal LinuxDisc (string device)
+ {
+ int fd = open (device, O_RDONLY | O_NONBLOCK);
+
+ if (fd < 0) throw new Exception (String.Format ("Cannot open device '{0}'", device));
+
+ try {
+ if (ReadTocHeader(fd) < 0) throw new Exception ("Cannot read table of contents");
+ if (LastTrack == 0) throw new Exception ("This disc has no tracks");
+
+ ulong lba = 0;
+ ReadLeadout (fd, ref lba);
+ TrackOffsets [0] = (int)lba + 150;
+
+ for (byte i = FirstTrack; i <= LastTrack; i++) {
+ ReadTocEntry (fd, i, ref lba);
+ TrackOffsets[i] = (int)lba + 150;
+ }
+ } finally {
+ close (fd);
+ }
+
+ Init ();
+ }
+ }
+}
Modified: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/LocalDisc.cs
==============================================================================
--- trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/LocalDisc.cs (original)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/LocalDisc.cs Sun Apr 6 03:38:28 2008
@@ -1,3 +1,5 @@
+#region License
+
// LocalDisc.cs
//
// Copyright (c) 2008 Scott Peterson <lunchtimemama gmail com>
@@ -19,7 +21,8 @@
// 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.
-//
+
+#endregion
using System;
using System.Security.Cryptography;
@@ -29,6 +32,8 @@
{
public abstract class LocalDisc : Disc
{
+ public static string SubmissionServiceUrl = "http://mm.musicbrainz.org/bare/cdlookup.html";
+
byte first_track;
byte last_track;
int [] track_durations;
@@ -94,35 +99,36 @@
string submission_url;
public string SubmissionUrl {
- get {
- if (submission_url == null) {
- StringBuilder builder = new StringBuilder ();
- builder.Append ("http://mm.musicbrainz.org/bare/cdlookup.html");
- builder.Append ("?id=");
- builder.Append (Id);
- builder.Append ("&tracks=");
- builder.Append (last_track);
- builder.Append ("&toc=");
- builder.Append (first_track);
- builder.Append ('+');
- builder.Append (last_track);
- builder.Append ('+');
- builder.Append (track_offsets [0]);
- for (int i = first_track; i <= last_track; i++) {
- builder.Append ('+');
- builder.Append (track_offsets [i]);
- }
- submission_url = builder.ToString ();
- }
- return submission_url;
+ get { return submission_url ?? submission_url = BuildSubmissionUrl (); }
+ }
+
+ string BuildSubmissionUrl ()
+ {
+ StringBuilder builder = new StringBuilder ();
+ builder.Append (SubmissionServiceUrl);
+ builder.Append ("?id=");
+ builder.Append (Id);
+ builder.Append ("&tracks=");
+ builder.Append (last_track);
+ builder.Append ("&toc=");
+ builder.Append (first_track);
+ builder.Append ('+');
+ builder.Append (last_track);
+ builder.Append ('+');
+ builder.Append (track_offsets [0]);
+ for (int i = first_track; i <= last_track; i++) {
+ builder.Append ('+');
+ builder.Append (track_offsets [i]);
}
+ return builder.ToString ();
}
public static LocalDisc GetFromDevice (string device)
{
if (device == null) throw new ArgumentNullException ("device");
return Environment.OSVersion.Platform != PlatformID.Unix
- ? (LocalDisc)new DiscWin32 (device) : new DiscLinux (device);
+ ? (LocalDisc)new Win32Disc (device)
+ : new LinuxDisc (device);
}
}
}
Modified: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzEntity.cs
==============================================================================
--- trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzEntity.cs (original)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzEntity.cs Sun Apr 6 03:38:28 2008
@@ -1,3 +1,5 @@
+#region License
+
// MusicBrainzEntity.cs
//
// Copyright (c) 2008 Scott Peterson <lunchtimemama gmail com>
@@ -19,7 +21,8 @@
// 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.
-//
+
+#endregion
using System;
using System.Collections.Generic;
@@ -33,6 +36,17 @@
public abstract class MusicBrainzEntity : MusicBrainzObject
{
+ #region Private
+
+ string name;
+ string sort_name;
+ string disambiguation;
+ string begin_date;
+ string end_date;
+ ReadOnlyCollection<string> aliases;
+
+ #endregion
+
#region Constructors
internal MusicBrainzEntity (string mbid, string parameters) : base (mbid, parameters)
@@ -45,7 +59,7 @@
#endregion
- #region Protected Overrides
+ #region Protected
protected override void CreateIncCore (StringBuilder builder)
{
@@ -105,40 +119,39 @@
return result;
}
+ protected static string CreateNameParameter (string name)
+ {
+ return "&name=" + Utils.PercentEncode (name);
+ }
+
#endregion
#region Properties
- string name;
public virtual string Name {
get { return GetPropertyOrNull (ref name); }
}
- string sort_name;
[Queryable]
public virtual string SortName {
get { return GetPropertyOrNull (ref sort_name); }
}
- string disambiguation;
[Queryable ("comment")]
public virtual string Disambiguation {
get { return GetPropertyOrNull (ref disambiguation); }
}
- string begin_date;
[Queryable ("begin")]
public virtual string BeginDate {
get { return GetPropertyOrNull (ref begin_date); }
}
- string end_date;
[Queryable ("end")]
public virtual string EndDate {
get { return GetPropertyOrNull (ref end_date); }
}
- ReadOnlyCollection<string> aliases;
[QueryableMember ("Contains", "alias")]
public virtual ReadOnlyCollection<string> Aliases {
get { return GetPropertyOrNew (ref aliases); }
@@ -146,14 +159,14 @@
#endregion
- protected static string CreateNameParameter (string name)
- {
- return "&name=" + Utils.PercentEncode (name);
- }
-
+ #region Public
+
public override string ToString ()
{
return name;
}
+
+ #endregion
+
}
}
Modified: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzException.cs
==============================================================================
--- trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzException.cs (original)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzException.cs Sun Apr 6 03:38:28 2008
@@ -1,3 +1,5 @@
+#region License
+
// MusicBrainzException.cs
//
// Copyright (c) 2008 Scott Peterson <lunchtimemama gmail com>
@@ -19,7 +21,8 @@
// 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.
-//
+
+#endregion
using System;
Modified: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzItem.cs
==============================================================================
--- trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzItem.cs (original)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzItem.cs Sun Apr 6 03:38:28 2008
@@ -1,3 +1,5 @@
+#region License
+
// MusicBrainzItem.cs
//
// Copyright (c) 2008 Scott Peterson <lunchtimemama gmail com>
@@ -19,7 +21,8 @@
// 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.
-//
+
+#endregion
using System;
using System.Text;
@@ -27,81 +30,17 @@
namespace MusicBrainz
{
- public abstract class ItemQueryParameters
- {
- internal ItemQueryParameters ()
- {
- }
-
- string title;
- public string Title {
- get { return title; }
- set { title = value; }
- }
-
- string artist;
- public string Artist {
- get { return artist; }
- set { artist = value; }
- }
-
- string artist_id;
- public string ArtistId {
- get { return artist_id; }
- set { artist_id = value; }
- }
-
- ReleaseType? release_type;
- public ReleaseType? ReleaseType {
- get { return release_type; }
- set { release_type = value; }
- }
-
- ReleaseStatus? release_status;
- public ReleaseStatus? ReleaseStatus {
- get { return release_status; }
- set { release_status = value; }
- }
-
- int? count;
- public int? TrackCount {
- get { return count; }
- set { count = value; }
- }
-
- protected void AppendBaseToBuilder (StringBuilder builder)
- {
- if (title != null) {
- builder.Append ("&title=");
- Utils.PercentEncode (builder, title);
- }
- if (artist != null) {
- builder.Append ("&artist=");
- Utils.PercentEncode (builder, artist);
- }
- if (artist_id != null) {
- builder.Append ("&artistid=");
- builder.Append (artist_id);
- }
- if (release_type != null) {
- builder.Append ("&releasetypes=");
- builder.Append (Utils.EnumToString (release_type.Value));
- }
- if (release_status != null) {
- builder.Append (release_type != null ? "+" : "&releasetypes=");
- builder.Append (release_status);
- }
- if (count != null) {
- builder.Append ("&count=");
- builder.Append (count.Value);
- }
- }
- }
-
// The item-like product of an artist, such as a track or a release.
public abstract class MusicBrainzItem : MusicBrainzObject
{
+ #region Private
+
+ string title;
+ Artist artist;
+
+ #endregion
+
#region Constructors
internal MusicBrainzItem (string mbid, string parameters) : base (mbid, parameters)
@@ -153,12 +92,10 @@
#region Properties
- string title;
public virtual string Title {
get { return GetPropertyOrNull (ref title); }
}
- Artist artist;
[Queryable ("artist")]
public virtual Artist Artist {
get { return GetPropertyOrNull (ref artist); }
@@ -166,9 +103,90 @@
#endregion
+ #region Public
+
public override string ToString ()
{
return title;
}
+
+ #endregion
+
+ }
+
+ #region Ancillary Types
+
+ public abstract class ItemQueryParameters
+ {
+ internal ItemQueryParameters ()
+ {
+ }
+
+ string title;
+ public string Title {
+ get { return title; }
+ set { title = value; }
+ }
+
+ string artist;
+ public string Artist {
+ get { return artist; }
+ set { artist = value; }
+ }
+
+ string artist_id;
+ public string ArtistId {
+ get { return artist_id; }
+ set { artist_id = value; }
+ }
+
+ ReleaseType? release_type;
+ public ReleaseType? ReleaseType {
+ get { return release_type; }
+ set { release_type = value; }
+ }
+
+ ReleaseStatus? release_status;
+ public ReleaseStatus? ReleaseStatus {
+ get { return release_status; }
+ set { release_status = value; }
+ }
+
+ int? count;
+ public int? TrackCount {
+ get { return count; }
+ set { count = value; }
+ }
+
+ protected void AppendBaseToBuilder (StringBuilder builder)
+ {
+ if (title != null) {
+ builder.Append ("&title=");
+ Utils.PercentEncode (builder, title);
+ }
+ if (artist != null) {
+ builder.Append ("&artist=");
+ Utils.PercentEncode (builder, artist);
+ }
+ if (artist_id != null) {
+ builder.Append ("&artistid=");
+ builder.Append (artist_id);
+ }
+ if (release_type != null) {
+ builder.Append ("&releasetypes=");
+ builder.Append (Utils.EnumToString (release_type.Value));
+ }
+ if (release_status != null) {
+ builder.Append (release_type != null ? "+" : "&releasetypes=");
+ builder.Append (release_status);
+ }
+ if (count != null) {
+ builder.Append ("&count=");
+ builder.Append (count.Value);
+ }
+ }
}
+
+ #endregion
+
}
Modified: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzObject.cs
==============================================================================
--- trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzObject.cs (original)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzObject.cs Sun Apr 6 03:38:28 2008
@@ -1,3 +1,5 @@
+#region License
+
// MusicBrainzObject.cs
//
// Copyright (c) 2008 Scott Peterson <lunchtimemama gmail com>
@@ -19,7 +21,8 @@
// 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.
-//
+
+#endregion
using System;
using System.Collections.Generic;
@@ -33,26 +36,36 @@
namespace MusicBrainz
{
- internal delegate void XmlProcessingDelegate (XmlReader reader);
-
public abstract class MusicBrainzObject
{
- static TimeSpan min_interval = new TimeSpan (0, 0, 1); // 1 second
+
+ #region Private Fields
+
static DateTime last_accessed;
+ static readonly TimeSpan min_interval = new TimeSpan (0, 0, 1); // 1 second
static readonly object server_mutex = new object ();
-
+ static readonly string [] rels_params = new string [] {
+ "artist-rels",
+ "release-rels",
+ "track-rels",
+ "label-rels",
+ "url-rels"
+ };
+
bool all_data_loaded;
- protected bool AllDataLoaded {
- get { return all_data_loaded; }
- }
-
bool all_rels_loaded;
- protected bool AllRelsLoaded {
- get { return all_rels_loaded; }
- set { all_rels_loaded = value; }
- }
-
- protected abstract string UrlExtension { get; }
+
+ string id;
+ byte score;
+ ReadOnlyCollection<Relation<Artist>> artist_rels;
+ ReadOnlyCollection<Relation<Release>> release_rels;
+ ReadOnlyCollection<Relation<Track>> track_rels;
+ ReadOnlyCollection<Relation<Label>> label_rels;
+ ReadOnlyCollection<UrlRelation> url_rels;
+
+ #endregion
+
+ #region Constructors
internal MusicBrainzObject (string mbid, string parameters)
{
@@ -65,48 +78,11 @@
this.all_rels_loaded = all_rels_loaded;
CreateFromXml (reader);
}
-
- protected string CreateInc ()
- {
- StringBuilder builder = new StringBuilder ();
- CreateIncCore (builder);
- return builder.ToString ();
- }
- static readonly string [] rels_params = new string [] {
- "artist-rels",
- "release-rels",
- "track-rels",
- "label-rels",
- "url-rels"
- };
-
- protected virtual void CreateIncCore (StringBuilder builder)
- {
- if (!all_rels_loaded)
- AppendIncParameters (builder, rels_params);
- }
+ #endregion
- protected void AppendIncParameters (StringBuilder builder, string parameter)
- {
- builder.Append (builder.Length == 0 ? "&inc=" : "+");
- builder.Append (parameter);
- }
+ #region Private Methods
- protected void AppendIncParameters (StringBuilder builder, string parameter1, string parameter2)
- {
- builder.Append (builder.Length == 0 ? "&inc=" : "+");
- builder.Append (parameter1);
- builder.Append ('+');
- builder.Append (parameter2);
- }
-
- protected void AppendIncParameters (StringBuilder builder, string [] parameters)
- {
- foreach (string parameter in parameters)
- AppendIncParameters (builder, parameter);
- }
-
void CreateFromMbid (string mbid, string parameters)
{
XmlProcessingClosure (
@@ -119,9 +95,6 @@
}
);
}
-
- protected abstract bool ProcessAttributes (XmlReader reader);
- protected abstract bool ProcessXml (XmlReader reader);
void CreateFromXml (XmlReader reader)
{
@@ -180,7 +153,53 @@
}
reader.Close ();
}
+
+ #endregion
+
+ #region Protected
+
+ protected bool AllDataLoaded {
+ get { return all_data_loaded; }
+ }
+
+ protected bool AllRelsLoaded {
+ get { return all_rels_loaded; }
+ set { all_rels_loaded = value; }
+ }
+
+ protected string CreateInc ()
+ {
+ StringBuilder builder = new StringBuilder ();
+ CreateIncCore (builder);
+ return builder.ToString ();
+ }
+
+ protected virtual void CreateIncCore (StringBuilder builder)
+ {
+ if (!all_rels_loaded)
+ AppendIncParameters (builder, rels_params);
+ }
+
+ protected void AppendIncParameters (StringBuilder builder, string parameter)
+ {
+ builder.Append (builder.Length == 0 ? "&inc=" : "+");
+ builder.Append (parameter);
+ }
+
+ protected void AppendIncParameters (StringBuilder builder, string parameter1, string parameter2)
+ {
+ builder.Append (builder.Length == 0 ? "&inc=" : "+");
+ builder.Append (parameter1);
+ builder.Append ('+');
+ builder.Append (parameter2);
+ }
+ protected void AppendIncParameters (StringBuilder builder, string [] parameters)
+ {
+ foreach (string parameter in parameters)
+ AppendIncParameters (builder, parameter);
+ }
+
protected void LoadMissingData ()
{
if (!all_data_loaded) {
@@ -189,7 +208,6 @@
}
}
- protected abstract void LoadMissingDataCore ();
protected void LoadMissingDataCore (MusicBrainzObject obj)
{
if (!all_rels_loaded) {
@@ -200,7 +218,14 @@
url_rels = obj.UrlRelations;
}
}
-
+
+ protected abstract void LoadMissingDataCore ();
+ protected abstract bool ProcessAttributes (XmlReader reader);
+ protected abstract bool ProcessXml (XmlReader reader);
+ protected abstract string UrlExtension { get; }
+
+ #endregion
+
#region Properties
protected T GetPropertyOrNull<T> (ref T field_reference) where T : class
@@ -226,41 +251,38 @@
return field_reference ?? new ReadOnlyCollection<T> (new T [0]);
}
- string id;
public virtual string Id {
get { return id; }
}
- byte score;
public virtual byte Score {
get { return score; }
}
- ReadOnlyCollection<Relation<Artist>> artist_rels;
public virtual ReadOnlyCollection<Relation<Artist>> ArtistRelations {
get { return GetPropertyOrNew (ref artist_rels, !all_rels_loaded); }
}
- ReadOnlyCollection<Relation<Release>> release_rels;
public virtual ReadOnlyCollection<Relation<Release>> ReleaseRelations {
get { return GetPropertyOrNew (ref release_rels, !all_rels_loaded); }
}
- ReadOnlyCollection<Relation<Track>> track_rels;
public virtual ReadOnlyCollection<Relation<Track>> TrackRelations {
get { return GetPropertyOrNew (ref track_rels, !all_rels_loaded); }
}
- ReadOnlyCollection<Relation<Label>> label_rels;
public virtual ReadOnlyCollection<Relation<Label>> LabelRelations {
get { return GetPropertyOrNew (ref label_rels, !all_rels_loaded); }
}
- ReadOnlyCollection<UrlRelation> url_rels;
public virtual ReadOnlyCollection<UrlRelation> UrlRelations {
get { return GetPropertyOrNew (ref url_rels, !all_rels_loaded); }
}
+ #endregion
+
+ #region Public
+
public override bool Equals (object obj)
{
MusicBrainzObject mbobj = obj as MusicBrainzObject;
@@ -271,7 +293,7 @@
{
return (GetType ().Name + Id).GetHashCode ();
}
-
+
#endregion
#region Static
@@ -320,8 +342,8 @@
static string CreateUrl (string url_extension, string mbid, string parameters)
{
StringBuilder builder = new StringBuilder (
- MusicBrainzService.ProviderUrl.Length + mbid.Length + parameters.Length + 9);
- builder.Append (MusicBrainzService.ProviderUrl);
+ MusicBrainzService.ServiceUrl.Length + mbid.Length + parameters.Length + 9);
+ builder.Append (MusicBrainzService.ServiceUrl);
builder.Append (url_extension);
builder.Append ('/');
builder.Append (mbid);
@@ -433,4 +455,6 @@
#endregion
}
+
+ internal delegate void XmlProcessingDelegate (XmlReader reader);
}
Modified: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzService.cs
==============================================================================
--- trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzService.cs (original)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/MusicBrainzService.cs Sun Apr 6 03:38:28 2008
@@ -1,3 +1,5 @@
+#region License
+
// MusicBrainzService.cs
//
// Copyright (c) 2008 Scott Peterson <lunchtimemama gmail com>
@@ -19,7 +21,8 @@
// 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.
-//
+
+#endregion
using System;
using System.Net.Cache;
@@ -28,7 +31,7 @@
{
public static class MusicBrainzService
{
- public static string ProviderUrl = @"http://musicbrainz.org/ws/1/";
+ public static string ServiceUrl = @"http://musicbrainz.org/ws/1/";
public static RequestCachePolicy CachePolicy;
public static event EventHandler<XmlRequestEventArgs> XmlRequest;
Modified: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Query.cs
==============================================================================
--- trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Query.cs (original)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Query.cs Sun Apr 6 03:38:28 2008
@@ -1,3 +1,5 @@
+#region License
+
// Query.cs
//
// Copyright (c) 2008 Scott Peterson <lunchtimemama gmail com>
@@ -19,7 +21,8 @@
// 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.
-//
+
+#endregion
using System;
using System.Collections;
@@ -30,16 +33,15 @@
{
public sealed class Query<T> : IEnumerable<T> where T : MusicBrainzObject
{
+
+ #region Private
+
string parameters;
string url_extension;
byte limit;
-
- internal Query (string url_extension, byte limit, string parameters)
- {
- this.url_extension = url_extension;
- this.limit = limit;
- this.parameters = parameters;
- }
+
+ int offset;
+ int? count;
List<T> results;
List<T> ResultsWindow {
@@ -50,7 +52,6 @@
}
}
- int offset;
Dictionary<int, WeakReference> weak_references = new Dictionary<int, WeakReference> ();
int Offset {
get { return offset; }
@@ -70,8 +71,22 @@
}
}
}
+
+ #endregion
- int? count;
+ #region Constructors
+
+ internal Query (string url_extension, byte limit, string parameters)
+ {
+ this.url_extension = url_extension;
+ this.limit = limit;
+ this.parameters = parameters;
+ }
+
+ #endregion
+
+ #region Public
+
public int Count {
get {
if(count == null && ResultsWindow == null) { } // just accessing ResultsWindow will give count a value
@@ -87,7 +102,41 @@
return ResultsWindow [i - offset];
}
}
-
+
+ public T First ()
+ {
+ byte tmp_limit = limit;
+ limit = 1;
+ T result = Count > 0 ? this [0] : null;
+ limit = tmp_limit;
+ return result;
+ }
+
+ public T PerfectMatch ()
+ {
+ byte tmp_limit = limit;
+ limit = 2;
+ T result1 = Count > 0 ? this [0] : null;
+ T result2 = Count > 1 ? this [1] : null;
+ limit = tmp_limit;
+
+ return (result1 != null && result1.Score == 100 && (result2 == null || result2.Score < 100))
+ ? result1 : null;
+ }
+
+ public IEnumerable<T> Best ()
+ {
+ return Best (100);
+ }
+
+ public IEnumerable<T> Best (int score_threshold)
+ {
+ foreach (T result in this) {
+ if (result.Score < score_threshold) yield break;
+ yield return result;
+ }
+ }
+
public List<T> ToList ()
{
return ToList (0);
@@ -106,7 +155,7 @@
for(int i = 0; i < Count; i++) array [i] = this [i];
return array;
}
-
+
public IEnumerator<T> GetEnumerator ()
{
for (int i = 0; i < Count; i++) yield return this [i];
@@ -117,44 +166,13 @@
return GetEnumerator ();
}
- public IEnumerable<T> Best ()
- {
- return Best (100);
- }
-
- public IEnumerable<T> Best (int score_threshold)
- {
- foreach (T result in this) {
- if (result.Score < score_threshold) yield break;
- yield return result;
- }
- }
-
- public T PerfectMatch ()
- {
- byte tmp_limit = limit;
- limit = 2;
- T result1 = Count > 0 ? this [0] : null;
- T result2 = Count > 1 ? this [1] : null;
- limit = tmp_limit;
-
- return (result1 != null && result1.Score == 100 && (result2 == null || result2.Score < 100))
- ? result1 : null;
- }
-
- public T First ()
- {
- byte tmp_limit = limit;
- limit = 1;
- T result = Count > 0 ? this [0] : null;
- limit = tmp_limit;
- return result;
- }
-
public static implicit operator T (Query<T> query)
{
return query.First ();
}
+
+ #endregion
+
}
[AttributeUsage (AttributeTargets.Property)]
@@ -177,6 +195,7 @@
{
public readonly string Name;
public readonly string Member;
+
public QueryableMemberAttribute (string member, string name)
{
Member = member;
Modified: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Relation.cs
==============================================================================
--- trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Relation.cs (original)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Relation.cs Sun Apr 6 03:38:28 2008
@@ -1,3 +1,5 @@
+#region License
+
// Relation.cs
//
// Copyright (c) 2008 Scott Peterson <lunchtimemama gmail com>
@@ -19,29 +21,24 @@
// 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.
-//
+
+#endregion
using System;
namespace MusicBrainz
{
- public enum RelationDirection
- {
- Forward,
- Backward
- }
-
public abstract class RelationBase<T>
{
T target;
string type;
- string[] attributes;
+ string [] attributes;
RelationDirection direction;
string begin;
string end;
internal RelationBase (string type, T target, RelationDirection direction,
- string begin, string end, string[] attributes)
+ string begin, string end, string [] attributes)
{
this.type = type;
this.target = target;
@@ -101,4 +98,10 @@
{
}
}
+
+ public enum RelationDirection
+ {
+ Forward,
+ Backward
+ }
}
Modified: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Release.cs
==============================================================================
--- trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Release.cs (original)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Release.cs Sun Apr 6 03:38:28 2008
@@ -1,3 +1,5 @@
+#region License
+
// Release.cs
//
// Copyright (c) 2008 Scott Peterson <lunchtimemama gmail com>
@@ -19,7 +21,8 @@
// 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.
-//
+
+#endregion
using System;
using System.Collections.Generic;
@@ -29,117 +32,23 @@
namespace MusicBrainz
{
-
- #region Enums
-
- public enum ReleaseType
- {
- None,
- Album,
- Single,
- EP,
- Compilation,
- Soundtrack,
- Spokenword,
- Interview,
- Audiobook,
- Live,
- Remix,
- Other
- }
-
- public enum ReleaseStatus
- {
- None,
- Official,
- Promotion,
- Bootleg,
- PsudoRelease
- }
-
- public enum ReleaseFormat
- {
- None,
- Cartridge,
- Cassette,
- CD,
- DAT,
- Digital,
- DualDisc,
- DVD,
- LaserDisc,
- MiniDisc,
- Other,
- ReelToReel,
- SACD,
- Vinyl
- }
-
- #endregion
-
- public sealed class ReleaseQueryParameters : ItemQueryParameters
- {
- string disc_id;
- public string DiscId {
- get { return disc_id; }
- set { disc_id = value; }
- }
-
- string date;
- public string Date {
- get { return date; }
- set { date = value; }
- }
-
- string asin;
- public string Asin {
- get { return asin; }
- set { asin = value; }
- }
-
- string language;
- public string Language {
- get { return language; }
- set { language = value; }
- }
-
- string script;
- public string Script {
- get { return script; }
- set { script = value; }
- }
-
- public override string ToString ()
- {
- StringBuilder builder = new StringBuilder ();
- if (disc_id != null) {
- builder.Append ("&discid=");
- builder.Append (disc_id);
- }
- if (date != null) {
- builder.Append ("&date=");
- Utils.PercentEncode (builder, date);
- }
- if (asin != null) {
- builder.Append ("&asin=");
- builder.Append (asin);
- }
- if (language != null) {
- builder.Append ("&lang=");
- builder.Append (language);
- }
- if (script != null) {
- builder.Append ("&script=");
- builder.Append (script);
- }
- AppendBaseToBuilder (builder);
- return builder.ToString ();
- }
- }
-
public sealed class Release : MusicBrainzItem
{
+
+ #region Private
+
const string EXTENSION = "release";
+ ReleaseType? type;
+ ReleaseStatus? status;
+ string language;
+ string script;
+ string asin;
+ ReadOnlyCollection<Disc> discs;
+ ReadOnlyCollection<Event> events;
+ ReadOnlyCollection<Track> tracks;
+ int? track_number;
+
+ #endregion
#region Constructors
@@ -276,55 +185,46 @@
get { return base.Title; }
}
- ReleaseType? type;
[Queryable]
public ReleaseType Type {
get { return GetPropertyOrDefault (ref type, ReleaseType.None); }
}
- ReleaseStatus? status;
[Queryable]
public ReleaseStatus Status {
get { return GetPropertyOrDefault (ref status, ReleaseStatus.None); }
}
- string language;
public string Language {
get { return GetPropertyOrNull (ref language); }
}
- string script;
[Queryable]
public string Script {
get { return GetPropertyOrNull (ref script); }
}
- string asin;
[Queryable]
public string Asin {
get { return GetPropertyOrNull (ref asin); }
}
- ReadOnlyCollection<Disc> discs;
[QueryableMember("Count", "discids")]
public ReadOnlyCollection<Disc> Discs {
get { return GetPropertyOrNew (ref discs); }
}
- ReadOnlyCollection<Event> events;
public ReadOnlyCollection<Event> Events {
get { return GetPropertyOrNew (ref events); }
}
- ReadOnlyCollection<Track> tracks;
[QueryableMember ("Count", "tracks")]
public ReadOnlyCollection<Track> Tracks {
get { return GetPropertyOrNew (ref tracks); }
}
- int? track_number;
internal int TrackNumber {
- get { return track_number != null ? track_number.Value : -1; }
+ get { return track_number ?? -1; }
}
#endregion
@@ -395,4 +295,112 @@
#endregion
}
+
+ #region Ancillary Types
+
+ public enum ReleaseType
+ {
+ None,
+ Album,
+ Single,
+ EP,
+ Compilation,
+ Soundtrack,
+ Spokenword,
+ Interview,
+ Audiobook,
+ Live,
+ Remix,
+ Other
+ }
+
+ public enum ReleaseStatus
+ {
+ None,
+ Official,
+ Promotion,
+ Bootleg,
+ PsudoRelease
+ }
+
+ public enum ReleaseFormat
+ {
+ None,
+ Cartridge,
+ Cassette,
+ CD,
+ DAT,
+ Digital,
+ DualDisc,
+ DVD,
+ LaserDisc,
+ MiniDisc,
+ Other,
+ ReelToReel,
+ SACD,
+ Vinyl
+ }
+
+ public sealed class ReleaseQueryParameters : ItemQueryParameters
+ {
+ string disc_id;
+ public string DiscId {
+ get { return disc_id; }
+ set { disc_id = value; }
+ }
+
+ string date;
+ public string Date {
+ get { return date; }
+ set { date = value; }
+ }
+
+ string asin;
+ public string Asin {
+ get { return asin; }
+ set { asin = value; }
+ }
+
+ string language;
+ public string Language {
+ get { return language; }
+ set { language = value; }
+ }
+
+ string script;
+ public string Script {
+ get { return script; }
+ set { script = value; }
+ }
+
+ public override string ToString ()
+ {
+ StringBuilder builder = new StringBuilder ();
+ if (disc_id != null) {
+ builder.Append ("&discid=");
+ builder.Append (disc_id);
+ }
+ if (date != null) {
+ builder.Append ("&date=");
+ Utils.PercentEncode (builder, date);
+ }
+ if (asin != null) {
+ builder.Append ("&asin=");
+ builder.Append (asin);
+ }
+ if (language != null) {
+ builder.Append ("&lang=");
+ builder.Append (language);
+ }
+ if (script != null) {
+ builder.Append ("&script=");
+ builder.Append (script);
+ }
+ AppendBaseToBuilder (builder);
+ return builder.ToString ();
+ }
+ }
+
+ #endregion
+
}
Modified: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Track.cs
==============================================================================
--- trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Track.cs (original)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Track.cs Sun Apr 6 03:38:28 2008
@@ -1,3 +1,5 @@
+#region License
+
// Track.cs
//
// Copyright (c) 2008 Scott Peterson <lunchtimemama gmail com>
@@ -19,7 +21,8 @@
// 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.
-//
+
+#endregion
using System;
using System.Collections.Generic;
@@ -29,69 +32,17 @@
namespace MusicBrainz
{
- public sealed class TrackQueryParameters : ItemQueryParameters
- {
- string release;
- public string Release {
- get { return release; }
- set { release = value; }
- }
-
- string release_id;
- public string ReleaseId {
- get { return release_id; }
- set { release_id = value; }
- }
-
- uint? duration;
- public uint? Duration {
- get { return duration; }
- set { duration = value; }
- }
-
- int? track_number;
- public int? TrackNumber {
- get { return track_number; }
- set { track_number = value; }
- }
-
- string puid;
- public string Puid {
- get { return puid; }
- set { puid = value; }
- }
-
- public override string ToString ()
- {
- StringBuilder builder = new StringBuilder ();
- if (release != null) {
- builder.Append ("&release=");
- Utils.PercentEncode (builder, release);
- }
- if (release_id != null) {
- builder.Append ("&releaseid=");
- builder.Append (release_id);
- }
- if (duration != null) {
- builder.Append ("&duration=");
- builder.Append (duration.Value);
- }
- if (track_number != null) {
- builder.Append ("&tracknumber=");
- builder.Append (track_number.Value);
- }
- if (puid != null) {
- builder.Append ("&puid=");
- builder.Append (puid);
- }
- AppendBaseToBuilder (builder);
- return builder.ToString ();
- }
- }
-
public sealed class Track : MusicBrainzItem
{
+
+ #region Private
+
const string EXTENSION = "track";
+ uint duration;
+ ReadOnlyCollection<Release> releases;
+ ReadOnlyCollection<string> puids;
+
+ #endregion
#region Constructors
@@ -192,20 +143,17 @@
get { return base.Title; }
}
- uint duration;
[Queryable ("dur")]
public uint Duration {
get { return duration; }
}
- ReadOnlyCollection<Release> releases;
[QueryableMember ("Contains", "release")]
public ReadOnlyCollection<Release> Releases {
get { return GetPropertyOrNew (ref releases); }
}
- ReadOnlyCollection<string> puids;
public ReadOnlyCollection<string> Puids {
get { return GetPropertyOrNew (ref puids); }
}
@@ -283,4 +231,69 @@
#endregion
}
+
+ #region Ancillary Types
+
+ public sealed class TrackQueryParameters : ItemQueryParameters
+ {
+ string release;
+ public string Release {
+ get { return release; }
+ set { release = value; }
+ }
+
+ string release_id;
+ public string ReleaseId {
+ get { return release_id; }
+ set { release_id = value; }
+ }
+
+ uint? duration;
+ public uint? Duration {
+ get { return duration; }
+ set { duration = value; }
+ }
+
+ int? track_number;
+ public int? TrackNumber {
+ get { return track_number; }
+ set { track_number = value; }
+ }
+
+ string puid;
+ public string Puid {
+ get { return puid; }
+ set { puid = value; }
+ }
+
+ public override string ToString ()
+ {
+ StringBuilder builder = new StringBuilder ();
+ if (release != null) {
+ builder.Append ("&release=");
+ Utils.PercentEncode (builder, release);
+ }
+ if (release_id != null) {
+ builder.Append ("&releaseid=");
+ builder.Append (release_id);
+ }
+ if (duration != null) {
+ builder.Append ("&duration=");
+ builder.Append (duration.Value);
+ }
+ if (track_number != null) {
+ builder.Append ("&tracknumber=");
+ builder.Append (track_number.Value);
+ }
+ if (puid != null) {
+ builder.Append ("&puid=");
+ builder.Append (puid);
+ }
+ AppendBaseToBuilder (builder);
+ return builder.ToString ();
+ }
+ }
+
+ #endregion
+
}
Modified: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Utils.cs
==============================================================================
--- trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Utils.cs (original)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Utils.cs Sun Apr 6 03:38:28 2008
@@ -1,3 +1,5 @@
+#region License
+
// Utils.cs
//
// Copyright (c) 2008 Scott Peterson <lunchtimemama gmail com>
@@ -19,7 +21,8 @@
// 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.
-//
+
+#endregion
using System;
using System.Text;
Added: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Win32Disc.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/Win32Disc.cs Sun Apr 6 03:38:28 2008
@@ -0,0 +1,118 @@
+#region License
+
+// Win32Disc.cs
+//
+// Copyright (c) 2008 Scott Peterson <lunchtimemama gmail com>
+//
+// 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.
+
+#endregion
+
+using System;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading;
+
+namespace MusicBrainz
+{
+ internal sealed class Win32Disc : LocalDisc
+ {
+ [DllImport ("winmm")]
+ static extern Int32 mciSendString (String command, StringBuilder buffer, Int32 bufferSize, IntPtr hwndCallback);
+
+ [DllImport ("winmm")]
+ static extern Int32 mciGetErrorString (Int32 errorCode, StringBuilder errorText, Int32 errorTextSize);
+
+ delegate void MciCall (string result);
+
+ internal Win32Disc (string device)
+ {
+ string device_string = device.Length == 0 ? "cdaudio" : string.Format ("{0} type cdaudio", device);
+
+ string alias = string.Format ("musicbrainz_cdio_{0}_{1}",
+ Environment.TickCount, Thread.CurrentThread.ManagedThreadId);
+
+ MciClosure (
+ "sysinfo cdaudio quantity wait",
+ "Could not get the list of CD audio devices",
+ delegate (string result) {
+ if (int.Parse (result.ToString ()) <= 0)
+ throw new Exception ("No CD audio devices present.");
+ });
+
+ MciClosure (
+ string.Format ("open {0} shareable alias {1} wait", device_string, alias),
+ string.Format ("Could not open device {0}", device),
+ null);
+
+ MciClosure (
+ string.Format ("status {0} number of tracks wait", alias),
+ "Could not read number of tracks",
+ delegate (string result) {
+ FirstTrack = 1;
+ LastTrack = byte.Parse (result);
+ });
+
+ MciClosure (
+ string.Format ("set {0} time format msf wait", alias),
+ "Could not set time format",
+ null);
+
+ for (int i = 1; i <= LastTrack; i++)
+ MciClosure (
+ string.Format ("status {0} position track {1} wait", alias, i),
+ string.Format ("Could not get position for track {0}", i),
+ delegate (string result) {
+ TrackOffsets [i] =
+ int.Parse (result.Substring (0,2)) * 4500 +
+ int.Parse (result.Substring (3,2)) * 75 +
+ int.Parse (result.Substring (6,2));
+ });
+
+ MciClosure (
+ string.Format ("status {0} length track {1} wait", alias, LastTrack),
+ "Could not read the length of the last track",
+ delegate (string result) {
+ TrackOffsets [0] =
+ int.Parse (result.Substring (0, 2)) * 4500 +
+ int.Parse (result.Substring (3, 2)) * 75 +
+ int.Parse (result.Substring (6, 2)) +
+ TrackOffsets [LastTrack] + 1;
+ });
+
+ MciClosure (
+ string.Format ("close {0} wait", alias),
+ string.Format ("Could not close device {0}", device),
+ null);
+
+ Init ();
+ }
+
+ static StringBuilder mci_result = new StringBuilder (128);
+ static StringBuilder mci_error = new StringBuilder (256);
+ static void MciClosure (string command, string failure_message, MciCall code)
+ {
+ int ret = mciSendString (command, mci_result, mci_result.Capacity, IntPtr.Zero);
+ if (ret != 0) {
+ mciGetErrorString (ret, mci_error, mci_error.Capacity);
+ throw new Exception (string.Format ("{0} : {1}", failure_message, mci_error.ToString ()));
+ } else if (code != null) code (mci_result.ToString ());
+ }
+ }
+}
Modified: trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/XmlRequestEventArgs.cs
==============================================================================
--- trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/XmlRequestEventArgs.cs (original)
+++ trunk/banshee/src/Libraries/MusicBrainz/MusicBrainz/XmlRequestEventArgs.cs Sun Apr 6 03:38:28 2008
@@ -1,3 +1,5 @@
+#region License
+
// XmlRequestEventArgs.cs
//
// Copyright (c) 2008 Scott Peterson <lunchtimemama gmail com>
@@ -19,7 +21,8 @@
// 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.
-//
+
+#endregion
using System;
@@ -30,7 +33,7 @@
public readonly string Uri;
public readonly bool FromCache;
- public XmlRequestEventArgs(string uri, bool fromCache)
+ public XmlRequestEventArgs (string uri, bool fromCache)
{
Uri = uri;
FromCache = fromCache;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]