|
|
|
@ -59,6 +59,11 @@ namespace Emby.Server.Implementations.Playlists
|
|
|
|
|
_appConfig = appConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Playlist GetPlaylist(Guid userId, Guid playlistId)
|
|
|
|
|
{
|
|
|
|
|
return GetPlaylists(userId).Where(p => p.Id.Equals(playlistId)).FirstOrDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Playlist> GetPlaylists(Guid userId)
|
|
|
|
|
{
|
|
|
|
|
var user = _userManager.GetUserById(userId);
|
|
|
|
@ -160,7 +165,7 @@ namespace Emby.Server.Implementations.Playlists
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetTargetPath(string path)
|
|
|
|
|
private static string GetTargetPath(string path)
|
|
|
|
|
{
|
|
|
|
|
while (Directory.Exists(path))
|
|
|
|
|
{
|
|
|
|
@ -231,13 +236,8 @@ namespace Emby.Server.Implementations.Playlists
|
|
|
|
|
|
|
|
|
|
// Update the playlist in the repository
|
|
|
|
|
playlist.LinkedChildren = newLinkedChildren;
|
|
|
|
|
await playlist.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
// Update the playlist on disk
|
|
|
|
|
if (playlist.IsFile)
|
|
|
|
|
{
|
|
|
|
|
SavePlaylistFile(playlist);
|
|
|
|
|
}
|
|
|
|
|
await UpdatePlaylist(playlist).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
// Refresh playlist metadata
|
|
|
|
|
_providerManager.QueueRefresh(
|
|
|
|
@ -266,12 +266,7 @@ namespace Emby.Server.Implementations.Playlists
|
|
|
|
|
.Select(i => i.Item1)
|
|
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
|
|
await playlist.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
if (playlist.IsFile)
|
|
|
|
|
{
|
|
|
|
|
SavePlaylistFile(playlist);
|
|
|
|
|
}
|
|
|
|
|
await UpdatePlaylist(playlist).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
_providerManager.QueueRefresh(
|
|
|
|
|
playlist.Id,
|
|
|
|
@ -313,14 +308,9 @@ namespace Emby.Server.Implementations.Playlists
|
|
|
|
|
newList.Insert(newIndex, item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
playlist.LinkedChildren = newList.ToArray();
|
|
|
|
|
|
|
|
|
|
await playlist.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
|
playlist.LinkedChildren = [.. newList];
|
|
|
|
|
|
|
|
|
|
if (playlist.IsFile)
|
|
|
|
|
{
|
|
|
|
|
SavePlaylistFile(playlist);
|
|
|
|
|
}
|
|
|
|
|
await UpdatePlaylist(playlist).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
@ -430,8 +420,11 @@ namespace Emby.Server.Implementations.Playlists
|
|
|
|
|
}
|
|
|
|
|
else if (extension.Equals(".m3u8", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
var playlist = new M3uPlaylist();
|
|
|
|
|
playlist.IsExtended = true;
|
|
|
|
|
var playlist = new M3uPlaylist
|
|
|
|
|
{
|
|
|
|
|
IsExtended = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
foreach (var child in item.GetLinkedChildren())
|
|
|
|
|
{
|
|
|
|
|
var entry = new M3uPlaylistEntry()
|
|
|
|
@ -481,7 +474,7 @@ namespace Emby.Server.Implementations.Playlists
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string NormalizeItemPath(string playlistPath, string itemPath)
|
|
|
|
|
private static string NormalizeItemPath(string playlistPath, string itemPath)
|
|
|
|
|
{
|
|
|
|
|
return MakeRelativePath(Path.GetDirectoryName(playlistPath), itemPath);
|
|
|
|
|
}
|
|
|
|
@ -541,12 +534,7 @@ namespace Emby.Server.Implementations.Playlists
|
|
|
|
|
{
|
|
|
|
|
playlist.OwnerUserId = guid;
|
|
|
|
|
playlist.Shares = rankedShares.Skip(1).ToArray();
|
|
|
|
|
await playlist.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
if (playlist.IsFile)
|
|
|
|
|
{
|
|
|
|
|
SavePlaylistFile(playlist);
|
|
|
|
|
}
|
|
|
|
|
await UpdatePlaylist(playlist).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else if (!playlist.OpenAccess)
|
|
|
|
|
{
|
|
|
|
@ -563,5 +551,47 @@ namespace Emby.Server.Implementations.Playlists
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task ToggleOpenAccess(Guid playlistId, Guid userId)
|
|
|
|
|
{
|
|
|
|
|
var playlist = GetPlaylist(userId, playlistId);
|
|
|
|
|
playlist.OpenAccess = !playlist.OpenAccess;
|
|
|
|
|
|
|
|
|
|
await UpdatePlaylist(playlist).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task AddToShares(Guid playlistId, Guid userId, Share share)
|
|
|
|
|
{
|
|
|
|
|
var playlist = GetPlaylist(userId, playlistId);
|
|
|
|
|
var shares = playlist.Shares.ToList();
|
|
|
|
|
var existingUserShare = shares.FirstOrDefault(s => s.UserId?.Equals(share.UserId, StringComparison.OrdinalIgnoreCase) ?? false);
|
|
|
|
|
if (existingUserShare is not null)
|
|
|
|
|
{
|
|
|
|
|
shares.Remove(existingUserShare);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shares.Add(share);
|
|
|
|
|
playlist.Shares = shares;
|
|
|
|
|
await UpdatePlaylist(playlist).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task RemoveFromShares(Guid playlistId, Guid userId, Share share)
|
|
|
|
|
{
|
|
|
|
|
var playlist = GetPlaylist(userId, playlistId);
|
|
|
|
|
var shares = playlist.Shares.ToList();
|
|
|
|
|
shares.Remove(share);
|
|
|
|
|
playlist.Shares = shares;
|
|
|
|
|
await UpdatePlaylist(playlist).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task UpdatePlaylist(Playlist playlist)
|
|
|
|
|
{
|
|
|
|
|
await playlist.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
if (playlist.IsFile)
|
|
|
|
|
{
|
|
|
|
|
SavePlaylistFile(playlist);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|