mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-16 10:29:01 -07:00
Miscellaneous code cleanup
This commit is contained in:
parent
add0a2088d
commit
e1958e3902
@ -305,9 +305,15 @@ namespace MediaBrowser.Api
|
|||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(fullCachePath));
|
Directory.CreateDirectory(Path.GetDirectoryName(fullCachePath));
|
||||||
using (var stream = result.Content)
|
using (var stream = result.Content)
|
||||||
using (var filestream = new FileStream(fullCachePath, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, true))
|
|
||||||
{
|
{
|
||||||
await stream.CopyToAsync(filestream).ConfigureAwait(false);
|
using var fileStream = new FileStream(fullCachePath,
|
||||||
|
FileMode.Create,
|
||||||
|
FileAccess.Write,
|
||||||
|
FileShare.Read,
|
||||||
|
IODefaults.FileStreamBufferSize,
|
||||||
|
true);
|
||||||
|
|
||||||
|
await stream.CopyToAsync(fileStream).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(pointerCachePath));
|
Directory.CreateDirectory(Path.GetDirectoryName(pointerCachePath));
|
||||||
|
@ -544,8 +544,7 @@ namespace MediaBrowser.Api.Library
|
|||||||
|
|
||||||
foreach (var type in types)
|
foreach (var type in types)
|
||||||
{
|
{
|
||||||
ImageOption[] defaultImageOptions = null;
|
TypeOptions.DefaultImageOptions.TryGetValue(type, out var defaultImageOptions);
|
||||||
TypeOptions.DefaultImageOptions.TryGetValue(type, out defaultImageOptions);
|
|
||||||
|
|
||||||
typeOptions.Add(new LibraryTypeOptions
|
typeOptions.Add(new LibraryTypeOptions
|
||||||
{
|
{
|
||||||
@ -592,8 +591,6 @@ namespace MediaBrowser.Api.Library
|
|||||||
|
|
||||||
public object Get(GetSimilarItems request)
|
public object Get(GetSimilarItems request)
|
||||||
{
|
{
|
||||||
var user = !request.UserId.Equals(Guid.Empty) ? _userManager.GetUserById(request.UserId) : null;
|
|
||||||
|
|
||||||
var item = string.IsNullOrEmpty(request.Id) ?
|
var item = string.IsNullOrEmpty(request.Id) ?
|
||||||
(!request.UserId.Equals(Guid.Empty) ? _libraryManager.GetUserRootFolder() :
|
(!request.UserId.Equals(Guid.Empty) ? _libraryManager.GetUserRootFolder() :
|
||||||
_libraryManager.RootFolder) : _libraryManager.GetItemById(request.Id);
|
_libraryManager.RootFolder) : _libraryManager.GetItemById(request.Id);
|
||||||
@ -651,7 +648,7 @@ namespace MediaBrowser.Api.Library
|
|||||||
// ExcludeArtistIds
|
// ExcludeArtistIds
|
||||||
if (!string.IsNullOrEmpty(request.ExcludeArtistIds))
|
if (!string.IsNullOrEmpty(request.ExcludeArtistIds))
|
||||||
{
|
{
|
||||||
query.ExcludeArtistIds = BaseApiService.GetGuids(request.ExcludeArtistIds);
|
query.ExcludeArtistIds = GetGuids(request.ExcludeArtistIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BaseItem> itemsResult;
|
List<BaseItem> itemsResult;
|
||||||
@ -672,7 +669,6 @@ namespace MediaBrowser.Api.Library
|
|||||||
var result = new QueryResult<BaseItemDto>
|
var result = new QueryResult<BaseItemDto>
|
||||||
{
|
{
|
||||||
Items = returnList,
|
Items = returnList,
|
||||||
|
|
||||||
TotalRecordCount = itemsResult.Count
|
TotalRecordCount = itemsResult.Count
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1075,36 +1071,18 @@ namespace MediaBrowser.Api.Library
|
|||||||
throw new ResourceNotFoundException("Item not found.");
|
throw new ResourceNotFoundException("Item not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseItem[] themeItems = Array.Empty<BaseItem>();
|
IEnumerable<BaseItem> themeItems = item.GetThemeSongs();
|
||||||
|
|
||||||
while (true)
|
while (!themeItems.Any() && request.InheritFromParent && item.GetParent() != null)
|
||||||
{
|
{
|
||||||
themeItems = item.GetThemeSongs().ToArray();
|
item = item.GetParent();
|
||||||
|
themeItems = item.GetThemeSongs();
|
||||||
if (themeItems.Length > 0)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!request.InheritFromParent)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
var parent = item.GetParent();
|
|
||||||
if (parent == null)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
item = parent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var dtoOptions = GetDtoOptions(_authContext, request);
|
var dtoOptions = GetDtoOptions(_authContext, request);
|
||||||
|
var items = themeItems
|
||||||
var dtos = themeItems
|
.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item))
|
||||||
.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item));
|
.ToArray();
|
||||||
|
|
||||||
var items = dtos.ToArray();
|
|
||||||
|
|
||||||
return new ThemeMediaResult
|
return new ThemeMediaResult
|
||||||
{
|
{
|
||||||
@ -1121,9 +1099,7 @@ namespace MediaBrowser.Api.Library
|
|||||||
/// <returns>System.Object.</returns>
|
/// <returns>System.Object.</returns>
|
||||||
public object Get(GetThemeVideos request)
|
public object Get(GetThemeVideos request)
|
||||||
{
|
{
|
||||||
var result = GetThemeVideos(request);
|
return ToOptimizedResult(GetThemeVideos(request));
|
||||||
|
|
||||||
return ToOptimizedResult(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ThemeMediaResult GetThemeVideos(GetThemeVideos request)
|
public ThemeMediaResult GetThemeVideos(GetThemeVideos request)
|
||||||
@ -1141,36 +1117,19 @@ namespace MediaBrowser.Api.Library
|
|||||||
throw new ResourceNotFoundException("Item not found.");
|
throw new ResourceNotFoundException("Item not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseItem[] themeItems = Array.Empty<BaseItem>();
|
IEnumerable<BaseItem> themeItems = item.GetThemeVideos();
|
||||||
|
|
||||||
while (true)
|
while (!themeItems.Any() && request.InheritFromParent && item.GetParent() != null)
|
||||||
{
|
{
|
||||||
themeItems = item.GetThemeVideos().ToArray();
|
item = item.GetParent();
|
||||||
|
themeItems = item.GetThemeVideos();
|
||||||
if (themeItems.Length > 0)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!request.InheritFromParent)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
var parent = item.GetParent();
|
|
||||||
if (parent == null)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
item = parent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var dtoOptions = GetDtoOptions(_authContext, request);
|
var dtoOptions = GetDtoOptions(_authContext, request);
|
||||||
|
|
||||||
var dtos = themeItems
|
var items = themeItems
|
||||||
.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item));
|
.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item))
|
||||||
|
.ToArray();
|
||||||
var items = dtos.ToArray();
|
|
||||||
|
|
||||||
return new ThemeMediaResult
|
return new ThemeMediaResult
|
||||||
{
|
{
|
||||||
|
@ -240,17 +240,12 @@ namespace MediaBrowser.Api.Playback.Hls
|
|||||||
|
|
||||||
protected Stream GetPlaylistFileStream(string path)
|
protected Stream GetPlaylistFileStream(string path)
|
||||||
{
|
{
|
||||||
var tmpPath = path + ".tmp";
|
return new FileStream(path,
|
||||||
tmpPath = path;
|
FileMode.Open,
|
||||||
|
FileAccess.Read,
|
||||||
try
|
FileShare.ReadWrite,
|
||||||
{
|
IODefaults.FileStreamBufferSize,
|
||||||
return new FileStream(tmpPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, IODefaults.FileStreamBufferSize, FileOptions.SequentialScan);
|
FileOptions.SequentialScan);
|
||||||
}
|
|
||||||
catch (IOException)
|
|
||||||
{
|
|
||||||
return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, IODefaults.FileStreamBufferSize, FileOptions.SequentialScan);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetCommandLineArguments(string outputPath, EncodingOptions encodingOptions, StreamState state, bool isEncoding)
|
protected override string GetCommandLineArguments(string outputPath, EncodingOptions encodingOptions, StreamState state, bool isEncoding)
|
||||||
|
@ -273,7 +273,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||||||
DtoOptions = dtoOptions
|
DtoOptions = dtoOptions
|
||||||
};
|
};
|
||||||
|
|
||||||
Func<BaseItem, bool> filter = i => FilterItem(request, i, excludeItemTypes, includeItemTypes, mediaTypes);
|
bool Filter(BaseItem i) => FilterItem(request, i, excludeItemTypes, includeItemTypes, mediaTypes);
|
||||||
|
|
||||||
if (parentItem.IsFolder)
|
if (parentItem.IsFolder)
|
||||||
{
|
{
|
||||||
@ -283,18 +283,18 @@ namespace MediaBrowser.Api.UserLibrary
|
|||||||
{
|
{
|
||||||
items = request.Recursive ?
|
items = request.Recursive ?
|
||||||
folder.GetRecursiveChildren(user, query).ToList() :
|
folder.GetRecursiveChildren(user, query).ToList() :
|
||||||
folder.GetChildren(user, true).Where(filter).ToList();
|
folder.GetChildren(user, true).Where(Filter).ToList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
items = request.Recursive ?
|
items = request.Recursive ?
|
||||||
folder.GetRecursiveChildren(filter) :
|
folder.GetRecursiveChildren(Filter) :
|
||||||
folder.Children.Where(filter).ToList();
|
folder.Children.Where(Filter).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
items = new[] { parentItem }.Where(filter).ToList();
|
items = new[] { parentItem }.Where(Filter).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
var extractedItems = GetAllItems(request, items);
|
var extractedItems = GetAllItems(request, items);
|
||||||
@ -345,30 +345,21 @@ namespace MediaBrowser.Api.UserLibrary
|
|||||||
private bool FilterItem(GetItemsByName request, BaseItem f, string[] excludeItemTypes, string[] includeItemTypes, string[] mediaTypes)
|
private bool FilterItem(GetItemsByName request, BaseItem f, string[] excludeItemTypes, string[] includeItemTypes, string[] mediaTypes)
|
||||||
{
|
{
|
||||||
// Exclude item types
|
// Exclude item types
|
||||||
if (excludeItemTypes.Length > 0)
|
if (excludeItemTypes.Length > 0 && excludeItemTypes.Contains(f.GetType().Name, StringComparer.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
if (excludeItemTypes.Contains(f.GetType().Name, StringComparer.OrdinalIgnoreCase))
|
return false;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include item types
|
// Include item types
|
||||||
if (includeItemTypes.Length > 0)
|
if (includeItemTypes.Length > 0 && !includeItemTypes.Contains(f.GetType().Name, StringComparer.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
if (!includeItemTypes.Contains(f.GetType().Name, StringComparer.OrdinalIgnoreCase))
|
return false;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include MediaTypes
|
// Include MediaTypes
|
||||||
if (mediaTypes.Length > 0)
|
if (mediaTypes.Length > 0 && !mediaTypes.Contains(f.MediaType ?? string.Empty, StringComparer.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
if (!mediaTypes.Contains(f.MediaType ?? string.Empty, StringComparer.OrdinalIgnoreCase))
|
return false;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -138,10 +138,8 @@ namespace MediaBrowser.Api
|
|||||||
var videosWithVersions = items.Where(i => i.MediaSourceCount > 1)
|
var videosWithVersions = items.Where(i => i.MediaSourceCount > 1)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var primaryVersion = videosWithVersions.FirstOrDefault() ?? items.OrderBy(i =>
|
var primaryVersion = videosWithVersions.FirstOrDefault() ?? items.OrderBy(i
|
||||||
{
|
=> (i.Video3DFormat.HasValue || i.VideoType != Model.Entities.VideoType.VideoFile) ? 1 : 0)
|
||||||
return (i.Video3DFormat.HasValue || i.VideoType != Model.Entities.VideoType.VideoFile) ? 1 : 0;
|
|
||||||
})
|
|
||||||
.ThenByDescending(i =>
|
.ThenByDescending(i =>
|
||||||
{
|
{
|
||||||
var stream = i.GetDefaultVideoStream();
|
var stream = i.GetDefaultVideoStream();
|
||||||
|
Loading…
Reference in New Issue
Block a user