[banshee: 6/57] Add found music tracks in content directory to UPnPSource
- From: Bertrand Lorentz <blorentz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee: 6/57] Add found music tracks in content directory to UPnPSource
- Date: Mon, 13 Feb 2012 20:28:19 +0000 (UTC)
commit 33110aed95844f3f095f5838b7f1b33279763c76
Author: Tobias Arrskog <topfs2 xbmc org>
Date: Mon Jun 6 13:58:06 2011 +0200
Add found music tracks in content directory to UPnPSource
.../Banshee.UPnPClient/UPnPSource.cs | 44 +++++++++++++++++++-
.../Banshee.UPnPClient/UPnPTrackInfo.cs | 17 +++++--
2 files changed, 54 insertions(+), 7 deletions(-)
---
diff --git a/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPSource.cs b/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPSource.cs
index c3fe8f5..6b914a4 100644
--- a/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPSource.cs
+++ b/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPSource.cs
@@ -63,8 +63,28 @@ namespace Banshee.UPnPClient
AfterInitialized ();
- UPnPTrackInfo track = new UPnPTrackInfo (this);
- track.Save();
+ try
+ {
+ Container root = contentDirectory.GetRootObject();
+
+ if (root.IsSearchable)
+ {
+ Hyena.Log.Debug("UPnPSource: " + this.UniqueId + " have searchable root");
+
+ foreach (MusicTrack track in contentDirectory.Search<MusicTrack>(root, visitor => visitor.VisitAllResults(), new ResultsSettings()))
+ AddTrack(track);
+ }
+ else
+ {
+ Hyena.Log.Debug("UPnPSource: " + this.UniqueId + " does not contain a searchable root, need to recursive browse");
+
+ ParseContainer(contentDirectory, root, 0);
+ }
+ }
+ catch (Exception exception)
+ {
+ Hyena.Log.DebugException(exception);
+ }
}
~UPnPSource()
@@ -100,5 +120,25 @@ namespace Banshee.UPnPClient
{
get { return false; }
}
+
+ private void ParseContainer(RemoteContentDirectory contentDirectory, Container container, int depth)
+ {
+ if (depth > 10 || container.ChildCount == 0)
+ return;
+
+ foreach (var item in contentDirectory.GetChildren<Mono.Upnp.Dcp.MediaServer1.ContentDirectory1.Object>(container))
+ {
+ if (item is MusicTrack)
+ AddTrack(item as MusicTrack);
+ else if (item is Container)
+ ParseContainer(contentDirectory, item as Container, depth + 1);
+ }
+ }
+
+ private void AddTrack(MusicTrack basetrack)
+ {
+ UPnPTrackInfo track = new UPnPTrackInfo (basetrack, this);
+ track.Save();
+ }
}
}
diff --git a/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPTrackInfo.cs b/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPTrackInfo.cs
index 926d1ba..e4984f5 100644
--- a/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPTrackInfo.cs
+++ b/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPTrackInfo.cs
@@ -28,6 +28,8 @@
using System;
using Mono.Unix;
+using Mono.Upnp.Dcp.MediaServer1.ContentDirectory1.AV;
+
using Hyena;
using Banshee.Collection;
@@ -37,13 +39,18 @@ namespace Banshee.UPnPClient
{
public class UPnPTrackInfo : DatabaseTrackInfo
{
- public UPnPTrackInfo (UPnPSource source) : base()
+ static long id = 0;
+
+ public UPnPTrackInfo (MusicTrack track, UPnPSource source) : base()
{
- ArtistName = "Artist";
- AlbumTitle = "Album";
- TrackTitle = "Song";
+ if (track != null)
+ {
+ ArtistName = track.Artists.Count > 0 ? track.Artists[0].Name : "";
+ AlbumTitle = track.Albums.Count > 0 ? track.Albums[0] : "";
+ TrackTitle = track.Title;
+ }
- ExternalId = 1;
+ ExternalId = ++id;
PrimarySource = source;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]