aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Playlists
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2014-08-02 22:16:37 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2014-08-02 22:16:37 -0400
commit2714127d2b663b735048da6d9def08efa38f2b5f (patch)
treeb260b23486fddf75d2dfa292544c7e03c05a74ce /MediaBrowser.Server.Implementations/Playlists
parentf0464dfa17d146f34849e45097085b891e51ebc8 (diff)
fixes #791 - Support server-side playlists
Diffstat (limited to 'MediaBrowser.Server.Implementations/Playlists')
-rw-r--r--MediaBrowser.Server.Implementations/Playlists/ManualPlaylistsFolder.cs17
-rw-r--r--MediaBrowser.Server.Implementations/Playlists/PlaylistManager.cs105
2 files changed, 99 insertions, 23 deletions
diff --git a/MediaBrowser.Server.Implementations/Playlists/ManualPlaylistsFolder.cs b/MediaBrowser.Server.Implementations/Playlists/ManualPlaylistsFolder.cs
index 3b46191b1d..a87edde7ba 100644
--- a/MediaBrowser.Server.Implementations/Playlists/ManualPlaylistsFolder.cs
+++ b/MediaBrowser.Server.Implementations/Playlists/ManualPlaylistsFolder.cs
@@ -1,5 +1,7 @@
-using MediaBrowser.Common.Configuration;
+using System.Collections.Generic;
+using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Playlists;
using System.IO;
using System.Linq;
@@ -14,8 +16,15 @@ namespace MediaBrowser.Server.Implementations.Playlists
public override bool IsVisible(User user)
{
- return GetChildren(user, true).Any() &&
- base.IsVisible(user);
+ return base.IsVisible(user) && GetRecursiveChildren(user, false)
+ .OfType<Playlist>()
+ .Any(i => string.Equals(i.OwnerUserId, user.Id.ToString("N")));
+ }
+
+ protected override IEnumerable<BaseItem> GetEligibleChildrenForRecursiveChildren(User user)
+ {
+ return RecursiveChildren
+ .OfType<Playlist>();
}
public override bool IsHidden
@@ -48,7 +57,7 @@ namespace MediaBrowser.Server.Implementations.Playlists
public BasePluginFolder GetFolder()
{
- var path = Path.Combine(_appPaths.DataPath, "playlists");
+ var path = Path.Combine(_appPaths.CachePath, "playlists");
Directory.CreateDirectory(path);
diff --git a/MediaBrowser.Server.Implementations/Playlists/PlaylistManager.cs b/MediaBrowser.Server.Implementations/Playlists/PlaylistManager.cs
index 92f01305cb..79b673283d 100644
--- a/MediaBrowser.Server.Implementations/Playlists/PlaylistManager.cs
+++ b/MediaBrowser.Server.Implementations/Playlists/PlaylistManager.cs
@@ -1,8 +1,10 @@
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Playlists;
using MediaBrowser.Controller.Providers;
+using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
@@ -41,9 +43,6 @@ namespace MediaBrowser.Server.Implementations.Playlists
{
var name = options.Name;
- // Need to use the [boxset] suffix
- // If internet metadata is not found, or if xml saving is off there will be no collection.xml
- // This could cause it to get re-resolved as a plain folder
var folderName = _fileSystem.GetValidFilename(name) + " [playlist]";
var parentFolder = GetPlaylistsFolder(null);
@@ -53,7 +52,55 @@ namespace MediaBrowser.Server.Implementations.Playlists
throw new ArgumentException();
}
+ if (string.IsNullOrWhiteSpace(options.MediaType))
+ {
+ foreach (var itemId in options.ItemIdList)
+ {
+ var item = _libraryManager.GetItemById(itemId);
+
+ if (item == null)
+ {
+ throw new ArgumentException("No item exists with the supplied Id");
+ }
+
+ if (!string.IsNullOrWhiteSpace(item.MediaType))
+ {
+ options.MediaType = item.MediaType;
+ }
+ else if (item is MusicArtist || item is MusicAlbum || item is MusicGenre)
+ {
+ options.MediaType = MediaType.Audio;
+ }
+ else if (item is Genre)
+ {
+ options.MediaType = MediaType.Video;
+ }
+ else
+ {
+ var folder = item as Folder;
+ if (folder != null)
+ {
+ options.MediaType = folder.GetRecursiveChildren()
+ .Where(i => !i.IsFolder)
+ .Select(i => i.MediaType)
+ .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i));
+ }
+ }
+
+ if (!string.IsNullOrWhiteSpace(options.MediaType))
+ {
+ break;
+ }
+ }
+ }
+
+ if (string.IsNullOrWhiteSpace(options.MediaType))
+ {
+ throw new ArgumentException("A playlist media type is required.");
+ }
+
var path = Path.Combine(parentFolder.Path, folderName);
+ path = GetTargetPath(path);
_iLibraryMonitor.ReportFileSystemChangeBeginning(path);
@@ -61,24 +108,27 @@ namespace MediaBrowser.Server.Implementations.Playlists
{
Directory.CreateDirectory(path);
- var collection = new Playlist
+ var playlist = new Playlist
{
Name = name,
Parent = parentFolder,
- Path = path
+ Path = path,
+ OwnerUserId = options.UserId
};
- await parentFolder.AddChild(collection, CancellationToken.None).ConfigureAwait(false);
+ playlist.SetMediaType(options.MediaType);
+
+ await parentFolder.AddChild(playlist, CancellationToken.None).ConfigureAwait(false);
- await collection.RefreshMetadata(new MetadataRefreshOptions(), CancellationToken.None)
+ await playlist.RefreshMetadata(new MetadataRefreshOptions { ForceSave = true }, CancellationToken.None)
.ConfigureAwait(false);
if (options.ItemIdList.Count > 0)
{
- await AddToPlaylist(collection.Id.ToString("N"), options.ItemIdList);
+ await AddToPlaylist(playlist.Id.ToString("N"), options.ItemIdList);
}
- return collection;
+ return playlist;
}
finally
{
@@ -87,11 +137,28 @@ namespace MediaBrowser.Server.Implementations.Playlists
}
}
+ private string GetTargetPath(string path)
+ {
+ while (Directory.Exists(path))
+ {
+ path += "1";
+ }
+
+ return path;
+ }
+
+ private IEnumerable<BaseItem> GetPlaylistItems(IEnumerable<string> itemIds, string playlistMediaType, User user)
+ {
+ var items = itemIds.Select(i => _libraryManager.GetItemById(i)).Where(i => i != null);
+
+ return Playlist.GetPlaylistItems(playlistMediaType, items, user);
+ }
+
public async Task AddToPlaylist(string playlistId, IEnumerable<string> itemIds)
{
- var collection = _libraryManager.GetItemById(playlistId) as Playlist;
+ var playlist = _libraryManager.GetItemById(playlistId) as Playlist;
- if (collection == null)
+ if (playlist == null)
{
throw new ArgumentException("No Playlist exists with the supplied Id");
}
@@ -110,17 +177,17 @@ namespace MediaBrowser.Server.Implementations.Playlists
itemList.Add(item);
- list.Add(new LinkedChild
- {
- Type = LinkedChildType.Manual,
- ItemId = item.Id
- });
+ list.Add(LinkedChild.Create(item));
}
- collection.LinkedChildren.AddRange(list);
+ playlist.LinkedChildren.AddRange(list);
+
+ await playlist.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
+ await playlist.RefreshMetadata(new MetadataRefreshOptions{
+
+ ForceSave = true
- await collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
- await collection.RefreshMetadata(CancellationToken.None).ConfigureAwait(false);
+ }, CancellationToken.None).ConfigureAwait(false);
}
public Task RemoveFromPlaylist(string playlistId, IEnumerable<int> indeces)