mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-04 06:48:35 +01:00
added api methods for video backdrops
This commit is contained in:
@@ -39,6 +39,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
/// </summary>
|
||||
public const string TrailerFolderName = "trailers";
|
||||
public const string ThemeSongsFolderName = "theme-music";
|
||||
public const string VideoBackdropsFolderName = "backdrops";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name.
|
||||
@@ -702,6 +703,28 @@ namespace MediaBrowser.Controller.Entities
|
||||
}
|
||||
}
|
||||
|
||||
private List<Video> _videoBackdrops;
|
||||
private bool _videoBackdropsInitialized;
|
||||
private object _videoBackdropsSyncLock = new object();
|
||||
[IgnoreDataMember]
|
||||
public List<Video> VideoBackdrops
|
||||
{
|
||||
get
|
||||
{
|
||||
LazyInitializer.EnsureInitialized(ref _videoBackdrops, ref _videoBackdropsInitialized, ref _videoBackdropsSyncLock, LoadVideoBackdrops);
|
||||
return _videoBackdrops;
|
||||
}
|
||||
private set
|
||||
{
|
||||
_videoBackdrops = value;
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
_videoBackdropsInitialized = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads local trailers from the file system
|
||||
/// </summary>
|
||||
@@ -818,6 +841,64 @@ namespace MediaBrowser.Controller.Entities
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the video backdrops.
|
||||
/// </summary>
|
||||
/// <returns>List{Video}.</returns>
|
||||
private List<Video> LoadVideoBackdrops()
|
||||
{
|
||||
ItemResolveArgs resolveArgs;
|
||||
|
||||
try
|
||||
{
|
||||
resolveArgs = ResolveArgs;
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path);
|
||||
return new List<Video>();
|
||||
}
|
||||
|
||||
if (!resolveArgs.IsDirectory)
|
||||
{
|
||||
return new List<Video>();
|
||||
}
|
||||
|
||||
var folder = resolveArgs.GetFileSystemEntryByName(VideoBackdropsFolderName);
|
||||
|
||||
// Path doesn't exist. No biggie
|
||||
if (folder == null)
|
||||
{
|
||||
return new List<Video>();
|
||||
}
|
||||
|
||||
IEnumerable<FileSystemInfo> files;
|
||||
|
||||
try
|
||||
{
|
||||
files = new DirectoryInfo(folder.FullName).EnumerateFiles();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
Logger.ErrorException("Error loading video backdrops for {0}", ex, Name);
|
||||
return new List<Video>();
|
||||
}
|
||||
|
||||
return LibraryManager.ResolvePaths<Video>(files, null).Select(item =>
|
||||
{
|
||||
// Try to retrieve it from the db. If we don't find it, use the resolved version
|
||||
var dbItem = LibraryManager.RetrieveItem(item.Id) as Video;
|
||||
|
||||
if (dbItem != null)
|
||||
{
|
||||
dbItem.ResolveArgs = item.ResolveArgs;
|
||||
item = dbItem;
|
||||
}
|
||||
|
||||
return item;
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the base implementation to refresh metadata for local trailers
|
||||
/// </summary>
|
||||
@@ -837,6 +918,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
// Lazy load these again
|
||||
LocalTrailers = null;
|
||||
ThemeSongs = null;
|
||||
VideoBackdrops = null;
|
||||
|
||||
// Refresh for the item
|
||||
var itemRefreshTask = ProviderManager.ExecuteMetadataProviders(this, cancellationToken, forceRefresh, allowSlowProviders);
|
||||
@@ -847,12 +929,15 @@ namespace MediaBrowser.Controller.Entities
|
||||
var trailerTasks = LocalTrailers.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
|
||||
|
||||
var themeSongTasks = ThemeSongs.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
|
||||
|
||||
var videoBackdropTasks = VideoBackdrops.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
// Await the trailer tasks
|
||||
await Task.WhenAll(trailerTasks).ConfigureAwait(false);
|
||||
await Task.WhenAll(themeSongTasks).ConfigureAwait(false);
|
||||
await Task.WhenAll(videoBackdropTasks).ConfigureAwait(false);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
public override bool Supports(BaseItem item)
|
||||
{
|
||||
return item is MusicArtist;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected virtual bool SaveLocalMeta
|
||||
|
||||
@@ -55,13 +55,6 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
|
||||
private async Task<LastfmGetAlbumResult> GetAlbumResult(BaseItem item, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await GetAlbumResult(item.Parent.Name, item.Name, cancellationToken);
|
||||
|
||||
if (result != null && result.album != null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var folder = (Folder)item;
|
||||
|
||||
// Get each song, distinct by the combination of AlbumArtist and Album
|
||||
@@ -69,7 +62,7 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
|
||||
foreach (var song in songs.Where(song => !string.IsNullOrEmpty(song.Album) && !string.IsNullOrEmpty(song.AlbumArtist)))
|
||||
{
|
||||
result = await GetAlbumResult(song.AlbumArtist, song.Album, cancellationToken).ConfigureAwait(false);
|
||||
var result = await GetAlbumResult(song.AlbumArtist, song.Album, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result != null && result.album != null)
|
||||
{
|
||||
@@ -77,7 +70,8 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
// Try the folder name
|
||||
return await GetAlbumResult(item.Parent.Name, item.Name, cancellationToken);
|
||||
}
|
||||
|
||||
private async Task<LastfmGetAlbumResult> GetAlbumResult(string artist, string album, CancellationToken cancellationToken)
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
|
||||
public override bool Supports(BaseItem item)
|
||||
{
|
||||
return item is MusicArtist;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
|
||||
public override bool Supports(BaseItem item)
|
||||
{
|
||||
return item is MusicArtist;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool RequiresInternet
|
||||
|
||||
Reference in New Issue
Block a user