[banshee] MassStorage: Support reading playlists from multiple folders



commit f8331c40cf8371dc70707d8f86aeae9cc0648ca9
Author: Bertrand Lorentz <bertrand lorentz gmail com>
Date:   Sat May 5 18:59:21 2012 +0200

    MassStorage: Support reading playlists from multiple folders
    
    The PlaylistPath property in media-player-info files can in fact contain
    a list of folders. So we now parse it as a list, and look for playlists
    in all those folders.
    
    Playlists are written only to the first folder in that list, similar to
    what we do with AudioFolders. As we systematically regenerate all
    playlists, that means we might move playlists from other folders to that
    first folder. That should probably be improved in the future.
    
    The playlist_path property for our .is_audio_player file still contains
    a single value. Same thing for custom device support, which only has to
    provide a single DefaultPlaylistPath.

 .../DeviceMediaCapabilities.cs                     |   10 ++--
 .../Banshee.Hardware/IDeviceMediaCapabilities.cs   |    2 +-
 .../Banshee.Dap.MassStorage/MassStorageDevice.cs   |    8 +-
 .../Banshee.Dap.MassStorage/MassStorageSource.cs   |   65 ++++++++++++++------
 4 files changed, 56 insertions(+), 29 deletions(-)
---
diff --git a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/DeviceMediaCapabilities.cs b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/DeviceMediaCapabilities.cs
index 5b84be1..5a1b5a3 100644
--- a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/DeviceMediaCapabilities.cs
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/DeviceMediaCapabilities.cs
@@ -120,9 +120,9 @@ namespace Banshee.Hardware.Gio
         }
 
 
-        public string PlaylistPath {
+        public string[] PlaylistPaths {
             get {
-                return mpi.PlaylistPath;
+                return mpi.PlaylistPaths;
             }
         }
 
@@ -162,7 +162,7 @@ namespace Banshee.Hardware.Gio
                 LoadProperties ();
             }
 
-            public string PlaylistPath {
+            public string[] PlaylistPaths {
                 get; private set;
             }
 
@@ -206,7 +206,7 @@ namespace Banshee.Hardware.Gio
                     }
 
                     if (mpi_file.HasKey (StorageGroup, "PlaylistPath")) {
-                        PlaylistPath = mpi_file.GetString (StorageGroup, "PlaylistPath");
+                        PlaylistPaths = mpi_file.GetStringList (StorageGroup, "PlaylistPath");
                     }
 
                     if (mpi_file.HasKey (StorageGroup, "AudioFolders")) {
@@ -245,7 +245,7 @@ namespace Banshee.Hardware.Gio
             private void InitDefaults ()
             {
                 FolderDepth = 0;
-                PlaylistPath = "";
+                PlaylistPaths = new string[] {};
                 AudioFolders = new string[] {};
                 InputFormats = new string[] {};
                 OutputFormats = new string[] {};
diff --git a/src/Core/Banshee.Services/Banshee.Hardware/IDeviceMediaCapabilities.cs b/src/Core/Banshee.Services/Banshee.Hardware/IDeviceMediaCapabilities.cs
index 874ff6e..5a610ed 100644
--- a/src/Core/Banshee.Services/Banshee.Hardware/IDeviceMediaCapabilities.cs
+++ b/src/Core/Banshee.Services/Banshee.Hardware/IDeviceMediaCapabilities.cs
@@ -40,7 +40,7 @@ namespace Banshee.Hardware
         string CoverArtFileType { get; }
         string CoverArtFileName { get; }
         string [] PlaylistFormats { get; }
-        string PlaylistPath { get; }
+        string [] PlaylistPaths { get; }
         string [] PlaybackMimeTypes { get; }
         char FolderSeparator { get; }
         bool IsType (string type);
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs
index 9ac3fc3..617c691 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs
@@ -121,7 +121,7 @@ namespace Banshee.Dap.MassStorage
             video_folders = MergeValues ("video_folders", config, DefaultVideoFolders);
             playback_mime_types = MergeValues ("output_formats", config, DefaultPlaybackMimeTypes);
             playlist_formats = MergeValues ("playlist_formats", config, DefaultPlaylistFormats);
-            playlist_path = GetPreferredValue ("playlist_path", config, DefaultPlaylistPath);
+            playlist_paths = new string [] { GetPreferredValue ("playlist_path", config, DefaultPlaylistPath) };
             folder_depth = GetPreferredValue ("folder_depth", config, DefaultFolderDepth);
 
             string preferred_folder_separator = GetPreferredValue ("folder_separator", config, DefaultFolderSeparator);
@@ -266,9 +266,9 @@ namespace Banshee.Dap.MassStorage
             get { return null; }
         }
 
-        private string playlist_path;
-        public virtual string PlaylistPath {
-            get { return playlist_path; }
+        private string [] playlist_paths;
+        public virtual string [] PlaylistPaths {
+            get { return playlist_paths; }
         }
 
         protected virtual string[] DefaultPlaybackMimeTypes {
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
index bcbe342..79c1e3e 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
@@ -166,7 +166,10 @@ namespace Banshee.Dap.MassStorage
                 var insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand (
                     "INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES (?, ?)");
                 foreach (string playlist_path in PlaylistFiles) {
-                    IPlaylistFormat loaded_playlist = PlaylistFileUtil.Load (playlist_path, new Uri (PlaylistsPath));
+                    // playlist_path has a file:// prefix, and GetDirectoryName messes it up,
+                    // so we need to convert it to a regular path
+                    string base_folder = System.IO.Path.GetDirectoryName (SafeUri.UriToFilename (playlist_path));
+                    IPlaylistFormat loaded_playlist = PlaylistFileUtil.Load (playlist_path, new Uri (base_folder));
                     if (loaded_playlist == null)
                         continue;
 
@@ -235,22 +238,41 @@ namespace Banshee.Dap.MassStorage
 
 #region Properties and Methods for Supporting Syncing of Playlists
 
-        private string playlists_path;
-        private string PlaylistsPath {
+        private string [] playlists_paths;
+        private string [] PlaylistsPaths {
             get {
-                if (playlists_path == null) {
-                    if (MediaCapabilities == null || MediaCapabilities.PlaylistPath == null) {
-                        playlists_path = WritePath;
+                if (playlists_paths == null) {
+                    if (MediaCapabilities == null || MediaCapabilities.PlaylistPaths == null
+                        || MediaCapabilities.PlaylistPaths.Length == 0) {
+                        playlists_paths = new string [] { WritePath };
                     } else {
-                        playlists_path = System.IO.Path.Combine (BaseDirectory, MediaCapabilities.PlaylistPath);
-                        playlists_path = playlists_path.Replace ("%File", String.Empty);
+                        playlists_paths = new string [MediaCapabilities.PlaylistPaths.Length];
+                        for (int i = 0; i < MediaCapabilities.PlaylistPaths.Length; i++) {
+                            playlists_paths[i] = Paths.Combine (BaseDirectory, MediaCapabilities.PlaylistPaths[i]);
+                            playlists_paths[i] = playlists_paths[i].Replace ("%File", String.Empty);
+                        }
                     }
+                }
+                return playlists_paths;
+            }
+        }
 
-                    if (!Directory.Exists (playlists_path)) {
-                        Directory.Create (playlists_path);
+        private string playlists_write_path;
+        private string PlaylistsWritePath {
+            get {
+                if (playlists_write_path == null) {
+                    playlists_write_path = WritePath;
+                    // We write playlists to the first folder listed in the PlaylistsPath property
+                    if (PlaylistsPaths.Length > 0) {
+                        playlists_write_path = PlaylistsPaths[0];
                     }
+
+                    if (!Directory.Exists (playlists_write_path)) {
+                        Directory.Create (playlists_write_path);
+                    }
+
                 }
-                return playlists_path;
+                return playlists_write_path;
             }
         }
 
@@ -289,11 +311,16 @@ namespace Banshee.Dap.MassStorage
 
         private IEnumerable<string> PlaylistFiles {
             get {
-                foreach (string file_name in Directory.GetFiles (PlaylistsPath)) {
-                    foreach (PlaylistFormatDescription desc in playlist_types) {
-                        if (file_name.EndsWith (desc.FileExtension)) {
-                            yield return file_name;
-                            break;
+                foreach (string folder_name in PlaylistsPaths) {
+                    if (!Directory.Exists (folder_name)) {
+                        continue;
+                    }
+                    foreach (string file_name in Directory.GetFiles (folder_name)) {
+                        foreach (PlaylistFormatDescription desc in playlist_types) {
+                            if (file_name.EndsWith (desc.FileExtension)) {
+                                yield return file_name;
+                                break;
+                            }
                         }
                     }
                 }
@@ -302,7 +329,7 @@ namespace Banshee.Dap.MassStorage
 
         private bool CanSyncPlaylists {
             get {
-                return PlaylistsPath != null && playlist_types.Count > 0;
+                return PlaylistsWritePath != null && playlist_types.Count > 0;
             }
         }
 
@@ -334,12 +361,12 @@ namespace Banshee.Dap.MassStorage
                     }
 
                     SafeUri playlist_path = new SafeUri (System.IO.Path.Combine (
-                        PlaylistsPath, String.Format ("{0}.{1}", escaped_name, PlaylistTypes[0].FileExtension)));
+                        PlaylistsWritePath, String.Format ("{0}.{1}", escaped_name, PlaylistTypes[0].FileExtension)));
 
                     System.IO.Stream stream = null;
                     try {
                         stream = Banshee.IO.File.OpenWrite (playlist_path, true);
-                        playlist_format.BaseUri = new Uri (PlaylistsPath);
+                        playlist_format.BaseUri = new Uri (PlaylistsWritePath);
 
                         playlist_format.Save (stream, from);
                     } catch (Exception e) {



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