mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-22 01:54:42 +01:00
connect updates
This commit is contained in:
@@ -37,6 +37,8 @@ namespace MediaBrowser.Controller.Channels
|
||||
|
||||
public string Id { get; set; }
|
||||
|
||||
public bool ReadAtNativeFramerate { get; set; }
|
||||
|
||||
public ChannelMediaInfo()
|
||||
{
|
||||
RequiredHttpHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
@@ -59,7 +61,8 @@ namespace MediaBrowser.Controller.Channels
|
||||
RequiredHttpHeaders = RequiredHttpHeaders,
|
||||
RunTimeTicks = RunTimeTicks,
|
||||
Name = id,
|
||||
Id = id
|
||||
Id = id,
|
||||
ReadAtNativeFramerate = ReadAtNativeFramerate
|
||||
};
|
||||
|
||||
var bitrate = (AudioBitrate ?? 0) + (VideoBitrate ?? 0);
|
||||
|
||||
@@ -766,7 +766,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
public Task RefreshMetadata(CancellationToken cancellationToken)
|
||||
{
|
||||
return RefreshMetadata(new MetadataRefreshOptions(), cancellationToken);
|
||||
return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService()), cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -783,8 +783,6 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
if (IsFolder || Parent != null)
|
||||
{
|
||||
options.DirectoryService = options.DirectoryService ?? new DirectoryService(Logger);
|
||||
|
||||
try
|
||||
{
|
||||
var files = locationType != LocationType.Remote && locationType != LocationType.Virtual ?
|
||||
@@ -1360,10 +1358,12 @@ namespace MediaBrowser.Controller.Entities
|
||||
/// </summary>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <param name="datePlayed">The date played.</param>
|
||||
/// <param name="userManager">The user manager.</param>
|
||||
/// <param name="resetPosition">if set to <c>true</c> [reset position].</param>
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="System.ArgumentNullException"></exception>
|
||||
public virtual async Task MarkPlayed(User user, DateTime? datePlayed, IUserDataManager userManager)
|
||||
public virtual async Task MarkPlayed(User user,
|
||||
DateTime? datePlayed,
|
||||
bool resetPosition)
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
@@ -1372,7 +1372,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
var key = GetUserDataKey();
|
||||
|
||||
var data = userManager.GetUserData(user.Id, key);
|
||||
var data = UserDataManager.GetUserData(user.Id, key);
|
||||
|
||||
if (datePlayed.HasValue)
|
||||
{
|
||||
@@ -1383,20 +1383,24 @@ namespace MediaBrowser.Controller.Entities
|
||||
// Ensure it's at least one
|
||||
data.PlayCount = Math.Max(data.PlayCount, 1);
|
||||
|
||||
if (resetPosition)
|
||||
{
|
||||
data.PlaybackPositionTicks = 0;
|
||||
}
|
||||
|
||||
data.LastPlayedDate = datePlayed ?? data.LastPlayedDate;
|
||||
data.Played = true;
|
||||
|
||||
await userManager.SaveUserData(user.Id, this, data, UserDataSaveReason.TogglePlayed, CancellationToken.None).ConfigureAwait(false);
|
||||
await UserDataManager.SaveUserData(user.Id, this, data, UserDataSaveReason.TogglePlayed, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks the unplayed.
|
||||
/// </summary>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <param name="userManager">The user manager.</param>
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="System.ArgumentNullException"></exception>
|
||||
public virtual async Task MarkUnplayed(User user, IUserDataManager userManager)
|
||||
public virtual async Task MarkUnplayed(User user)
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
@@ -1405,7 +1409,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
var key = GetUserDataKey();
|
||||
|
||||
var data = userManager.GetUserData(user.Id, key);
|
||||
var data = UserDataManager.GetUserData(user.Id, key);
|
||||
|
||||
//I think it is okay to do this here.
|
||||
// if this is only called when a user is manually forcing something to un-played
|
||||
@@ -1415,7 +1419,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
data.LastPlayedDate = null;
|
||||
data.Played = false;
|
||||
|
||||
await userManager.SaveUserData(user.Id, this, data, UserDataSaveReason.TogglePlayed, CancellationToken.None).ConfigureAwait(false);
|
||||
await UserDataManager.SaveUserData(user.Id, this, data, UserDataSaveReason.TogglePlayed, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -319,7 +319,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
public Task ValidateChildren(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
return ValidateChildren(progress, cancellationToken, new MetadataRefreshOptions());
|
||||
return ValidateChildren(progress, cancellationToken, new MetadataRefreshOptions(new DirectoryService()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -332,8 +332,6 @@ namespace MediaBrowser.Controller.Entities
|
||||
/// <returns>Task.</returns>
|
||||
public Task ValidateChildren(IProgress<double> progress, CancellationToken cancellationToken, MetadataRefreshOptions metadataRefreshOptions, bool recursive = true)
|
||||
{
|
||||
metadataRefreshOptions.DirectoryService = metadataRefreshOptions.DirectoryService ?? new DirectoryService(Logger);
|
||||
|
||||
return ValidateChildrenWithCancellationSupport(progress, cancellationToken, recursive, true, metadataRefreshOptions, metadataRefreshOptions.DirectoryService);
|
||||
}
|
||||
|
||||
@@ -1141,12 +1139,16 @@ namespace MediaBrowser.Controller.Entities
|
||||
/// </summary>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <param name="datePlayed">The date played.</param>
|
||||
/// <param name="userManager">The user manager.</param>
|
||||
/// <param name="resetPosition">if set to <c>true</c> [reset position].</param>
|
||||
/// <returns>Task.</returns>
|
||||
public override async Task MarkPlayed(User user, DateTime? datePlayed, IUserDataManager userManager)
|
||||
public override async Task MarkPlayed(User user,
|
||||
DateTime? datePlayed,
|
||||
bool resetPosition)
|
||||
{
|
||||
// Sweep through recursively and update status
|
||||
var tasks = GetRecursiveChildren(user, true).Where(i => !i.IsFolder && i.LocationType != LocationType.Virtual).Select(c => c.MarkPlayed(user, datePlayed, userManager));
|
||||
var tasks = GetRecursiveChildren(user, true)
|
||||
.Where(i => !i.IsFolder && i.LocationType != LocationType.Virtual)
|
||||
.Select(c => c.MarkPlayed(user, datePlayed, resetPosition));
|
||||
|
||||
await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
}
|
||||
@@ -1155,12 +1157,13 @@ namespace MediaBrowser.Controller.Entities
|
||||
/// Marks the unplayed.
|
||||
/// </summary>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <param name="userManager">The user manager.</param>
|
||||
/// <returns>Task.</returns>
|
||||
public override async Task MarkUnplayed(User user, IUserDataManager userManager)
|
||||
public override async Task MarkUnplayed(User user)
|
||||
{
|
||||
// Sweep through recursively and update status
|
||||
var tasks = GetRecursiveChildren(user, true).Where(i => !i.IsFolder && i.LocationType != LocationType.Virtual).Select(c => c.MarkUnplayed(user, userManager));
|
||||
var tasks = GetRecursiveChildren(user, true)
|
||||
.Where(i => !i.IsFolder && i.LocationType != LocationType.Virtual)
|
||||
.Select(c => c.MarkUnplayed(user));
|
||||
|
||||
await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
}
|
||||
@@ -1195,14 +1198,14 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
public override bool IsPlayed(User user)
|
||||
{
|
||||
return GetRecursiveChildren(user).Where(i => !i.IsFolder && i.LocationType != LocationType.Virtual)
|
||||
return GetRecursiveChildren(user)
|
||||
.Where(i => !i.IsFolder && i.LocationType != LocationType.Virtual)
|
||||
.All(i => i.IsPlayed(user));
|
||||
}
|
||||
|
||||
public override bool IsUnplayed(User user)
|
||||
{
|
||||
return GetRecursiveChildren(user).Where(i => !i.IsFolder && i.LocationType != LocationType.Virtual)
|
||||
.All(i => i.IsUnplayed(user));
|
||||
return !IsPlayed(user);
|
||||
}
|
||||
|
||||
public override void FillUserDataDtoValues(UserItemDataDto dto, UserItemData userData, User user)
|
||||
|
||||
@@ -179,7 +179,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
Name = newName;
|
||||
|
||||
return RefreshMetadata(new MetadataRefreshOptions
|
||||
return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService())
|
||||
{
|
||||
ReplaceAllMetadata = true,
|
||||
ImageRefreshMode = ImageRefreshMode.FullRefresh,
|
||||
|
||||
@@ -398,9 +398,8 @@ namespace MediaBrowser.Controller.Entities
|
||||
var currentImagePath = video.GetImagePath(ImageType.Primary);
|
||||
var ownerImagePath = this.GetImagePath(ImageType.Primary);
|
||||
|
||||
var newOptions = new MetadataRefreshOptions
|
||||
var newOptions = new MetadataRefreshOptions(options.DirectoryService)
|
||||
{
|
||||
DirectoryService = options.DirectoryService,
|
||||
ImageRefreshMode = options.ImageRefreshMode,
|
||||
MetadataRefreshMode = options.MetadataRefreshMode,
|
||||
ReplaceAllMetadata = options.ReplaceAllMetadata
|
||||
|
||||
@@ -25,7 +25,13 @@ namespace MediaBrowser.Controller.IO
|
||||
/// <param name="resolveShortcuts">if set to <c>true</c> [resolve shortcuts].</param>
|
||||
/// <returns>Dictionary{System.StringFileSystemInfo}.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">path</exception>
|
||||
public static Dictionary<string, FileSystemInfo> GetFilteredFileSystemEntries(IDirectoryService directoryService, string path, IFileSystem fileSystem, ILogger logger, ItemResolveArgs args, int flattenFolderDepth = 0, bool resolveShortcuts = true)
|
||||
public static Dictionary<string, FileSystemInfo> GetFilteredFileSystemEntries(IDirectoryService directoryService,
|
||||
string path,
|
||||
IFileSystem fileSystem,
|
||||
ILogger logger,
|
||||
ItemResolveArgs args,
|
||||
int flattenFolderDepth = 0,
|
||||
bool resolveShortcuts = true)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
@@ -36,21 +42,13 @@ namespace MediaBrowser.Controller.IO
|
||||
throw new ArgumentNullException("args");
|
||||
}
|
||||
|
||||
var entries = directoryService.GetFileSystemEntries(path);
|
||||
|
||||
if (!resolveShortcuts && flattenFolderDepth == 0)
|
||||
{
|
||||
// Seeing dupes on some users file system for some reason
|
||||
var dictionary = new Dictionary<string, FileSystemInfo>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
foreach (var info in entries)
|
||||
{
|
||||
dictionary[info.FullName] = info;
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
return directoryService.GetFileSystemDictionary(path);
|
||||
}
|
||||
|
||||
var entries = directoryService.GetFileSystemEntries(path);
|
||||
|
||||
var dict = new Dictionary<string, FileSystemInfo>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
foreach (var entry in entries)
|
||||
|
||||
@@ -213,38 +213,38 @@ namespace MediaBrowser.Controller.Library
|
||||
return false;
|
||||
}
|
||||
|
||||
// It's a season folder if it's named as such and does not contain any audio files, apart from theme.mp3
|
||||
foreach (var fileSystemInfo in directoryService.GetFileSystemEntries(path))
|
||||
{
|
||||
var attributes = fileSystemInfo.Attributes;
|
||||
//// It's a season folder if it's named as such and does not contain any audio files, apart from theme.mp3
|
||||
//foreach (var fileSystemInfo in directoryService.GetFileSystemEntries(path))
|
||||
//{
|
||||
// var attributes = fileSystemInfo.Attributes;
|
||||
|
||||
if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// Can't enforce this because files saved by Bitcasa are always marked System
|
||||
//if ((attributes & FileAttributes.System) == FileAttributes.System)
|
||||
//{
|
||||
// continue;
|
||||
//}
|
||||
// // Can't enforce this because files saved by Bitcasa are always marked System
|
||||
// //if ((attributes & FileAttributes.System) == FileAttributes.System)
|
||||
// //{
|
||||
// // continue;
|
||||
// //}
|
||||
|
||||
if ((attributes & FileAttributes.Directory) == FileAttributes.Directory)
|
||||
{
|
||||
//if (IsBadFolder(fileSystemInfo.Name))
|
||||
//{
|
||||
// return false;
|
||||
//}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (EntityResolutionHelper.IsAudioFile(fileSystemInfo.FullName) &&
|
||||
!string.Equals(fileSystem.GetFileNameWithoutExtension(fileSystemInfo), BaseItem.ThemeSongFilename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// if ((attributes & FileAttributes.Directory) == FileAttributes.Directory)
|
||||
// {
|
||||
// //if (IsBadFolder(fileSystemInfo.Name))
|
||||
// //{
|
||||
// // return false;
|
||||
// //}
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (EntityResolutionHelper.IsAudioFile(fileSystemInfo.FullName) &&
|
||||
// !string.Equals(fileSystem.GetFileNameWithoutExtension(fileSystemInfo), BaseItem.ThemeSongFilename))
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -9,35 +9,47 @@ namespace MediaBrowser.Controller.Providers
|
||||
{
|
||||
public interface IDirectoryService
|
||||
{
|
||||
List<FileSystemInfo> GetFileSystemEntries(string path);
|
||||
IEnumerable<FileSystemInfo> GetFileSystemEntries(string path);
|
||||
IEnumerable<FileSystemInfo> GetFiles(string path);
|
||||
IEnumerable<FileSystemInfo> GetFiles(string path, bool clearCache);
|
||||
FileSystemInfo GetFile(string path);
|
||||
Dictionary<string, FileSystemInfo> GetFileSystemDictionary(string path);
|
||||
}
|
||||
|
||||
public class DirectoryService : IDirectoryService
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly ConcurrentDictionary<string, List<FileSystemInfo>> _cache = new ConcurrentDictionary<string, List<FileSystemInfo>>(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly ConcurrentDictionary<string, Dictionary<string,FileSystemInfo>> _cache =
|
||||
new ConcurrentDictionary<string, Dictionary<string, FileSystemInfo>>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public DirectoryService(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<FileSystemInfo> GetFileSystemEntries(string path)
|
||||
public DirectoryService()
|
||||
: this(new NullLogger())
|
||||
{
|
||||
}
|
||||
|
||||
public IEnumerable<FileSystemInfo> GetFileSystemEntries(string path)
|
||||
{
|
||||
return GetFileSystemEntries(path, false);
|
||||
}
|
||||
|
||||
private List<FileSystemInfo> GetFileSystemEntries(string path, bool clearCache)
|
||||
public Dictionary<string, FileSystemInfo> GetFileSystemDictionary(string path)
|
||||
{
|
||||
List<FileSystemInfo> entries;
|
||||
return GetFileSystemDictionary(path, false);
|
||||
}
|
||||
|
||||
private Dictionary<string, FileSystemInfo> GetFileSystemDictionary(string path, bool clearCache)
|
||||
{
|
||||
Dictionary<string, FileSystemInfo> entries;
|
||||
|
||||
if (clearCache)
|
||||
{
|
||||
List<FileSystemInfo> removed;
|
||||
Dictionary<string, FileSystemInfo> removed;
|
||||
|
||||
_cache.TryRemove(path, out removed);
|
||||
}
|
||||
@@ -46,21 +58,36 @@ namespace MediaBrowser.Controller.Providers
|
||||
{
|
||||
//_logger.Debug("Getting files for " + path);
|
||||
|
||||
entries = new Dictionary<string, FileSystemInfo>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
try
|
||||
{
|
||||
entries = new DirectoryInfo(path).EnumerateFileSystemInfos("*", SearchOption.TopDirectoryOnly).ToList();
|
||||
var list = new DirectoryInfo(path)
|
||||
.EnumerateFileSystemInfos("*", SearchOption.TopDirectoryOnly);
|
||||
|
||||
// Seeing dupes on some users file system for some reason
|
||||
foreach (var item in list)
|
||||
{
|
||||
entries[item.FullName] = item;
|
||||
}
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
entries = new List<FileSystemInfo>();
|
||||
}
|
||||
|
||||
//var group = entries.ToLookup(i => Path.GetDirectoryName(i.FullName)).ToList();
|
||||
|
||||
_cache.TryAdd(path, entries);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
private IEnumerable<FileSystemInfo> GetFileSystemEntries(string path, bool clearCache)
|
||||
{
|
||||
return GetFileSystemDictionary(path, clearCache).Values;
|
||||
}
|
||||
|
||||
public IEnumerable<FileSystemInfo> GetFiles(string path)
|
||||
{
|
||||
return GetFiles(path, false);
|
||||
@@ -74,9 +101,13 @@ namespace MediaBrowser.Controller.Providers
|
||||
public FileSystemInfo GetFile(string path)
|
||||
{
|
||||
var directory = Path.GetDirectoryName(path);
|
||||
var filename = Path.GetFileName(path);
|
||||
|
||||
return GetFiles(directory).FirstOrDefault(i => string.Equals(i.Name, filename, StringComparison.OrdinalIgnoreCase));
|
||||
var dict = GetFileSystemDictionary(directory, false);
|
||||
|
||||
FileSystemInfo entry;
|
||||
dict.TryGetValue(path, out entry);
|
||||
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,12 @@ namespace MediaBrowser.Controller.Providers
|
||||
/// Gets the metadata.
|
||||
/// </summary>
|
||||
/// <param name="info">The information.</param>
|
||||
/// <param name="directoryService">The directory service.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task{MetadataResult{`0}}.</returns>
|
||||
Task<LocalMetadataResult<TItemType>> GetMetadata(ItemInfo info, CancellationToken cancellationToken);
|
||||
Task<LocalMetadataResult<TItemType>> GetMetadata(ItemInfo info,
|
||||
IDirectoryService directoryService,
|
||||
CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
public class ItemInfo
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -17,18 +16,24 @@ namespace MediaBrowser.Controller.Providers
|
||||
public bool ForceSave { get; set; }
|
||||
|
||||
public MetadataRefreshOptions()
|
||||
: this(new DirectoryService())
|
||||
{
|
||||
}
|
||||
|
||||
public MetadataRefreshOptions(IDirectoryService directoryService)
|
||||
: base(directoryService)
|
||||
{
|
||||
MetadataRefreshMode = MetadataRefreshMode.Default;
|
||||
}
|
||||
|
||||
public MetadataRefreshOptions(MetadataRefreshOptions copy)
|
||||
public MetadataRefreshOptions( MetadataRefreshOptions copy)
|
||||
: base(copy.DirectoryService)
|
||||
{
|
||||
MetadataRefreshMode = copy.MetadataRefreshMode;
|
||||
ForceSave = copy.ForceSave;
|
||||
ReplaceAllMetadata = copy.ReplaceAllMetadata;
|
||||
|
||||
ImageRefreshMode = copy.ImageRefreshMode;
|
||||
DirectoryService = copy.DirectoryService;
|
||||
ReplaceAllImages = copy.ReplaceAllImages;
|
||||
ReplaceImages = copy.ReplaceImages.ToList();
|
||||
}
|
||||
@@ -37,15 +42,16 @@ namespace MediaBrowser.Controller.Providers
|
||||
public class ImageRefreshOptions
|
||||
{
|
||||
public ImageRefreshMode ImageRefreshMode { get; set; }
|
||||
public IDirectoryService DirectoryService { get; set; }
|
||||
public IDirectoryService DirectoryService { get; private set; }
|
||||
|
||||
public bool ReplaceAllImages { get; set; }
|
||||
|
||||
public List<ImageType> ReplaceImages { get; set; }
|
||||
|
||||
public ImageRefreshOptions()
|
||||
public ImageRefreshOptions(IDirectoryService directoryService)
|
||||
{
|
||||
ImageRefreshMode = ImageRefreshMode.Default;
|
||||
DirectoryService = directoryService;
|
||||
|
||||
ReplaceImages = new List<ImageType>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user