Front-load soundtrack links
This commit is contained in:
parent
d0f3262ba3
commit
e031694a99
|
@ -104,33 +104,9 @@ namespace MediaBrowser.Controller.Dto
|
|||
|
||||
if (fields.Contains(ItemFields.SoundtrackIds))
|
||||
{
|
||||
var series = item as Series;
|
||||
|
||||
if (series != null)
|
||||
{
|
||||
AttachSoundtrackIds(dto, series, user);
|
||||
}
|
||||
|
||||
var movie = item as Movie;
|
||||
|
||||
if (movie != null)
|
||||
{
|
||||
AttachSoundtrackIds(dto, movie, user);
|
||||
}
|
||||
|
||||
var album = item as MusicAlbum;
|
||||
|
||||
if (album != null)
|
||||
{
|
||||
AttachSoundtrackIds(dto, album, user);
|
||||
}
|
||||
|
||||
var game = item as Game;
|
||||
|
||||
if (game != null)
|
||||
{
|
||||
AttachSoundtrackIds(dto, game, user);
|
||||
}
|
||||
dto.SoundtrackIds = item.SoundtrackIds
|
||||
.Select(i => i.ToString("N"))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
// Make sure all the tasks we kicked off have completed.
|
||||
|
@ -142,132 +118,6 @@ namespace MediaBrowser.Controller.Dto
|
|||
return dto;
|
||||
}
|
||||
|
||||
private void AttachSoundtrackIds(BaseItemDto dto, Movie item, User user)
|
||||
{
|
||||
var tmdb = item.GetProviderId(MetadataProviders.Tmdb);
|
||||
|
||||
if (string.IsNullOrEmpty(tmdb))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var recursiveChildren = user == null
|
||||
? _libraryManager.RootFolder.RecursiveChildren
|
||||
: user.RootFolder.GetRecursiveChildren(user);
|
||||
|
||||
dto.SoundtrackIds = recursiveChildren
|
||||
.Where(i =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(tmdb) &&
|
||||
string.Equals(tmdb, i.GetProviderId(MetadataProviders.Tmdb), StringComparison.OrdinalIgnoreCase) &&
|
||||
i is MusicAlbum)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.Select(GetClientItemId)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private void AttachSoundtrackIds(BaseItemDto dto, Series item, User user)
|
||||
{
|
||||
var tvdb = item.GetProviderId(MetadataProviders.Tvdb);
|
||||
|
||||
if (string.IsNullOrEmpty(tvdb))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var recursiveChildren = user == null
|
||||
? _libraryManager.RootFolder.RecursiveChildren
|
||||
: user.RootFolder.GetRecursiveChildren(user);
|
||||
|
||||
dto.SoundtrackIds = recursiveChildren
|
||||
.Where(i =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(tvdb) &&
|
||||
string.Equals(tvdb, i.GetProviderId(MetadataProviders.Tvdb), StringComparison.OrdinalIgnoreCase) &&
|
||||
i is MusicAlbum)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.Select(GetClientItemId)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private void AttachSoundtrackIds(BaseItemDto dto, Game item, User user)
|
||||
{
|
||||
var gamesdb = item.GetProviderId(MetadataProviders.Gamesdb);
|
||||
|
||||
if (string.IsNullOrEmpty(gamesdb))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var recursiveChildren = user == null
|
||||
? _libraryManager.RootFolder.RecursiveChildren
|
||||
: user.RootFolder.GetRecursiveChildren(user);
|
||||
|
||||
dto.SoundtrackIds = recursiveChildren
|
||||
.Where(i =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(gamesdb) &&
|
||||
string.Equals(gamesdb, i.GetProviderId(MetadataProviders.Gamesdb), StringComparison.OrdinalIgnoreCase) &&
|
||||
i is MusicAlbum)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.Select(GetClientItemId)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private void AttachSoundtrackIds(BaseItemDto dto, MusicAlbum item, User user)
|
||||
{
|
||||
var tmdb = item.GetProviderId(MetadataProviders.Tmdb);
|
||||
var tvdb = item.GetProviderId(MetadataProviders.Tvdb);
|
||||
var gamesdb = item.GetProviderId(MetadataProviders.Gamesdb);
|
||||
|
||||
if (string.IsNullOrEmpty(tmdb) && string.IsNullOrEmpty(tvdb) && string.IsNullOrEmpty(gamesdb))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var recursiveChildren = user == null
|
||||
? _libraryManager.RootFolder.RecursiveChildren
|
||||
: user.RootFolder.GetRecursiveChildren(user);
|
||||
|
||||
dto.SoundtrackIds = recursiveChildren
|
||||
.Where(i =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(tmdb) &&
|
||||
string.Equals(tmdb, i.GetProviderId(MetadataProviders.Tmdb), StringComparison.OrdinalIgnoreCase) &&
|
||||
i is Movie)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(tvdb) &&
|
||||
string.Equals(tvdb, i.GetProviderId(MetadataProviders.Tvdb), StringComparison.OrdinalIgnoreCase) &&
|
||||
i is Series)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(gamesdb) &&
|
||||
string.Equals(gamesdb, i.GetProviderId(MetadataProviders.Gamesdb), StringComparison.OrdinalIgnoreCase) &&
|
||||
i is Game)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.Select(GetClientItemId)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attaches the user specific info.
|
||||
/// </summary>
|
||||
|
@ -716,8 +566,20 @@ namespace MediaBrowser.Controller.Dto
|
|||
{
|
||||
SetMusicVideoProperties(dto, musicVideo);
|
||||
}
|
||||
|
||||
var book = item as Book;
|
||||
|
||||
if (book != null)
|
||||
{
|
||||
SetBookProperties(dto, book);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetBookProperties(BaseItemDto dto, Book item)
|
||||
{
|
||||
dto.SeriesName = item.SeriesName;
|
||||
}
|
||||
|
||||
private void SetMusicVideoProperties(BaseItemDto dto, MusicVideo item)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(item.Album))
|
||||
|
|
|
@ -23,6 +23,11 @@ namespace MediaBrowser.Controller.Entities
|
|||
/// </summary>
|
||||
public abstract class BaseItem : IHasProviderIds
|
||||
{
|
||||
/// <summary>
|
||||
/// MusicAlbums in the library that are the soundtrack for this item
|
||||
/// </summary>
|
||||
public List<Guid> SoundtrackIds { get; set; }
|
||||
|
||||
protected BaseItem()
|
||||
{
|
||||
Genres = new List<string>();
|
||||
|
@ -38,6 +43,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
Tags = new List<string>();
|
||||
ThemeSongIds = new List<Guid>();
|
||||
ThemeVideoIds = new List<Guid>();
|
||||
SoundtrackIds = new List<Guid>();
|
||||
LocalTrailerIds = new List<Guid>();
|
||||
LockedFields = new List<MetadataFields>();
|
||||
}
|
||||
|
|
|
@ -81,6 +81,7 @@
|
|||
<Compile Include="Music\LastfmBaseProvider.cs" />
|
||||
<Compile Include="Music\LastfmHelper.cs" />
|
||||
<Compile Include="Music\MusicVideoXmlParser.cs" />
|
||||
<Compile Include="Music\SoundtrackPostScanTask.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Savers\AlbumXmlSaver.cs" />
|
||||
<Compile Include="Savers\ArtistXmlSaver.cs" />
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace MediaBrowser.Providers.Movies
|
|||
{
|
||||
case "Chapters":
|
||||
|
||||
_chaptersTask = FetchChaptersFromXmlNode(item, reader.ReadSubtree(), _itemRepo, CancellationToken.None);
|
||||
//_chaptersTask = FetchChaptersFromXmlNode(item, reader.ReadSubtree(), _itemRepo, CancellationToken.None);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
159
MediaBrowser.Providers/Music/SoundtrackPostScanTask.cs
Normal file
159
MediaBrowser.Providers/Music/SoundtrackPostScanTask.cs
Normal file
|
@ -0,0 +1,159 @@
|
|||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Providers.Music
|
||||
{
|
||||
public class SoundtrackPostScanTask : ILibraryPostScanTask
|
||||
{
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
|
||||
public SoundtrackPostScanTask(ILibraryManager libraryManager)
|
||||
{
|
||||
_libraryManager = libraryManager;
|
||||
}
|
||||
|
||||
public Task Run(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.Run(() => RunInternal(progress, cancellationToken));
|
||||
}
|
||||
|
||||
private void RunInternal(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
var allItems = _libraryManager.RootFolder
|
||||
.RecursiveChildren
|
||||
.ToList();
|
||||
|
||||
var musicAlbums = allItems
|
||||
.OfType<MusicAlbum>()
|
||||
.ToList();
|
||||
|
||||
AttachMovieSoundtracks(allItems, musicAlbums, cancellationToken);
|
||||
|
||||
progress.Report(25);
|
||||
|
||||
AttachTvSoundtracks(allItems, musicAlbums, cancellationToken);
|
||||
|
||||
progress.Report(50);
|
||||
|
||||
AttachGameSoundtracks(allItems, musicAlbums, cancellationToken);
|
||||
|
||||
progress.Report(75);
|
||||
|
||||
AttachAlbumLinks(allItems, musicAlbums, cancellationToken);
|
||||
|
||||
progress.Report(100);
|
||||
}
|
||||
|
||||
private void AttachMovieSoundtracks(IEnumerable<BaseItem> allItems, List<MusicAlbum> allAlbums, CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (var movie in allItems
|
||||
.Where(i => (i is Movie) || (i is Trailer)))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var tmdbId = movie.GetProviderId(MetadataProviders.Tmdb);
|
||||
|
||||
if (string.IsNullOrEmpty(tmdbId))
|
||||
{
|
||||
movie.SoundtrackIds = new List<Guid>();
|
||||
continue;
|
||||
}
|
||||
|
||||
movie.SoundtrackIds = allAlbums
|
||||
.Where(i => string.Equals(tmdbId, i.GetProviderId(MetadataProviders.Tmdb), StringComparison.OrdinalIgnoreCase))
|
||||
.Select(i => i.Id)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
private void AttachTvSoundtracks(IEnumerable<BaseItem> allItems, List<MusicAlbum> allAlbums, CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (var series in allItems.OfType<Series>())
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var tvdbId = series.GetProviderId(MetadataProviders.Tvdb);
|
||||
|
||||
if (string.IsNullOrEmpty(tvdbId))
|
||||
{
|
||||
series.SoundtrackIds = new List<Guid>();
|
||||
continue;
|
||||
}
|
||||
|
||||
series.SoundtrackIds = allAlbums
|
||||
.Where(i => string.Equals(tvdbId, i.GetProviderId(MetadataProviders.Tvdb), StringComparison.OrdinalIgnoreCase))
|
||||
.Select(i => i.Id)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
private void AttachGameSoundtracks(IEnumerable<BaseItem> allItems, List<MusicAlbum> allAlbums, CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (var game in allItems.OfType<Game>())
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var gamesdb = game.GetProviderId(MetadataProviders.Gamesdb);
|
||||
|
||||
if (string.IsNullOrEmpty(gamesdb))
|
||||
{
|
||||
game.SoundtrackIds = new List<Guid>();
|
||||
continue;
|
||||
}
|
||||
|
||||
game.SoundtrackIds = allAlbums
|
||||
.Where(i => string.Equals(gamesdb, i.GetProviderId(MetadataProviders.Gamesdb), StringComparison.OrdinalIgnoreCase))
|
||||
.Select(i => i.Id)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
private void AttachAlbumLinks(List<BaseItem> allItems, IEnumerable<MusicAlbum> allAlbums, CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (var album in allAlbums)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var tmdb = album.GetProviderId(MetadataProviders.Tmdb);
|
||||
var tvdb = album.GetProviderId(MetadataProviders.Tvdb);
|
||||
var gamesdb = album.GetProviderId(MetadataProviders.Gamesdb);
|
||||
|
||||
if (string.IsNullOrEmpty(tmdb) && string.IsNullOrEmpty(tvdb) && string.IsNullOrEmpty(gamesdb))
|
||||
{
|
||||
album.SoundtrackIds = new List<Guid>();
|
||||
continue;
|
||||
}
|
||||
|
||||
album.SoundtrackIds = allItems.
|
||||
Where(i =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(tmdb) && string.Equals(tmdb, i.GetProviderId(MetadataProviders.Tmdb), StringComparison.OrdinalIgnoreCase) && i is Movie)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(tmdb) && string.Equals(tmdb, i.GetProviderId(MetadataProviders.Tmdb), StringComparison.OrdinalIgnoreCase) && i is Trailer)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(tvdb) && string.Equals(tvdb, i.GetProviderId(MetadataProviders.Tvdb), StringComparison.OrdinalIgnoreCase) && i is Series)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return !string.IsNullOrEmpty(gamesdb) && string.Equals(gamesdb, i.GetProviderId(MetadataProviders.Gamesdb), StringComparison.OrdinalIgnoreCase) && i is Game;
|
||||
})
|
||||
.Select(i => i.Id)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -81,8 +81,7 @@ namespace MediaBrowser.Providers.Savers
|
|||
}
|
||||
|
||||
XmlSaverHelpers.AddCommonNodes(item, builder);
|
||||
XmlSaverHelpers.AddMediaInfo(episode, builder);
|
||||
XmlSaverHelpers.AddChapters((Video)item, builder, _itemRepository);
|
||||
XmlSaverHelpers.AddMediaInfo(episode, builder, _itemRepository);
|
||||
|
||||
builder.Append("</Item>");
|
||||
|
||||
|
|
|
@ -97,9 +97,7 @@ namespace MediaBrowser.Providers.Savers
|
|||
|
||||
var video = (Video)item;
|
||||
|
||||
XmlSaverHelpers.AddMediaInfo(video, builder);
|
||||
|
||||
XmlSaverHelpers.AddChapters(video, builder, _itemRepository);
|
||||
XmlSaverHelpers.AddMediaInfo(video, builder, _itemRepository);
|
||||
|
||||
builder.Append("</Title>");
|
||||
|
||||
|
|
|
@ -451,9 +451,11 @@ namespace MediaBrowser.Providers.Savers
|
|||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="builder">The builder.</param>
|
||||
public static void AddMediaInfo<T>(T item, StringBuilder builder)
|
||||
public static void AddMediaInfo<T>(T item, StringBuilder builder, IItemRepository itemRepository)
|
||||
where T : BaseItem, IHasMediaStreams
|
||||
{
|
||||
var video = item as Video;
|
||||
|
||||
builder.Append("<MediaInfo>");
|
||||
|
||||
foreach (var stream in item.MediaStreams)
|
||||
|
@ -526,8 +528,6 @@ namespace MediaBrowser.Providers.Savers
|
|||
builder.Append("<DurationSeconds>" + Convert.ToInt32(timespan.TotalSeconds).ToString(UsCulture) + "</DurationSeconds>");
|
||||
}
|
||||
|
||||
var video = item as Video;
|
||||
|
||||
if (video != null && video.Video3DFormat.HasValue)
|
||||
{
|
||||
switch (video.Video3DFormat.Value)
|
||||
|
@ -552,6 +552,11 @@ namespace MediaBrowser.Providers.Savers
|
|||
}
|
||||
|
||||
builder.Append("</MediaInfo>");
|
||||
|
||||
if (video != null)
|
||||
{
|
||||
AddChapters(video, builder, itemRepository);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ namespace MediaBrowser.Providers.TV
|
|||
{
|
||||
case "Chapters":
|
||||
|
||||
_chaptersTask = FetchChaptersFromXmlNode(item, reader.ReadSubtree(), _itemRepo, CancellationToken.None);
|
||||
//_chaptersTask = FetchChaptersFromXmlNode(item, reader.ReadSubtree(), _itemRepo, CancellationToken.None);
|
||||
break;
|
||||
|
||||
case "Episode":
|
||||
|
|
Loading…
Reference in New Issue
Block a user