added IHasTrailers
This commit is contained in:
parent
317f411070
commit
cd279d98e0
|
@ -885,7 +885,19 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
|
||||
if (request.HasTrailer.HasValue)
|
||||
{
|
||||
items = items.Where(i => request.HasTrailer.Value ? i.LocalTrailerIds.Count > 0 : i.LocalTrailerIds.Count == 0);
|
||||
var val = request.HasTrailer.Value;
|
||||
items = items.Where(i =>
|
||||
{
|
||||
var trailerCount = 0;
|
||||
|
||||
var hasTrailers = i as IHasTrailers;
|
||||
if (hasTrailers != null)
|
||||
{
|
||||
trailerCount = hasTrailers.LocalTrailerIds.Count;
|
||||
}
|
||||
|
||||
return val ? trailerCount > 0 : trailerCount == 0;
|
||||
});
|
||||
}
|
||||
|
||||
if (request.HasThemeSong.HasValue)
|
||||
|
|
|
@ -489,7 +489,15 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
// Get everything
|
||||
var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)).ToList();
|
||||
|
||||
var dtos = item.LocalTrailerIds
|
||||
var trailerIds = new List<Guid>();
|
||||
|
||||
var hasTrailers = item as IHasTrailers;
|
||||
if (hasTrailers != null)
|
||||
{
|
||||
trailerIds = hasTrailers.LocalTrailerIds;
|
||||
}
|
||||
|
||||
var dtos = trailerIds
|
||||
.Select(_libraryManager.GetItemById)
|
||||
.OrderBy(i => i.SortName)
|
||||
.Select(i => _dtoService.GetBaseItemDto(i, fields, user, item));
|
||||
|
|
|
@ -37,10 +37,8 @@ namespace MediaBrowser.Controller.Entities
|
|||
Tags = new List<string>();
|
||||
ThemeSongIds = new List<Guid>();
|
||||
ThemeVideoIds = new List<Guid>();
|
||||
LocalTrailerIds = new List<Guid>();
|
||||
LockedFields = new List<MetadataFields>();
|
||||
Taglines = new List<string>();
|
||||
RemoteTrailers = new List<MediaUrl>();
|
||||
ImageSources = new List<ImageSourceInfo>();
|
||||
}
|
||||
|
||||
|
@ -92,12 +90,6 @@ namespace MediaBrowser.Controller.Entities
|
|||
/// <value>The taglines.</value>
|
||||
public List<string> Taglines { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the trailer URL.
|
||||
/// </summary>
|
||||
/// <value>The trailer URL.</value>
|
||||
public List<MediaUrl> RemoteTrailers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Return the id that should be used to key display prefs for this item.
|
||||
/// Default is based on the type for everything except actual generic folders.
|
||||
|
@ -654,7 +646,6 @@ namespace MediaBrowser.Controller.Entities
|
|||
|
||||
public List<Guid> ThemeSongIds { get; set; }
|
||||
public List<Guid> ThemeVideoIds { get; set; }
|
||||
public List<Guid> LocalTrailerIds { get; set; }
|
||||
|
||||
[IgnoreDataMember]
|
||||
public virtual string OfficialRatingForComparison
|
||||
|
@ -897,7 +888,11 @@ namespace MediaBrowser.Controller.Entities
|
|||
|
||||
themeVideosChanged = await RefreshThemeVideos(cancellationToken, forceSave, forceRefresh, allowSlowProviders).ConfigureAwait(false);
|
||||
|
||||
localTrailersChanged = await RefreshLocalTrailers(cancellationToken, forceSave, forceRefresh, allowSlowProviders).ConfigureAwait(false);
|
||||
var hasTrailers = this as IHasTrailers;
|
||||
if (hasTrailers != null)
|
||||
{
|
||||
localTrailersChanged = await RefreshLocalTrailers(hasTrailers, cancellationToken, forceSave, forceRefresh, allowSlowProviders).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
@ -917,18 +912,18 @@ namespace MediaBrowser.Controller.Entities
|
|||
return changed;
|
||||
}
|
||||
|
||||
private async Task<bool> RefreshLocalTrailers(CancellationToken cancellationToken, bool forceSave = false, bool forceRefresh = false, bool allowSlowProviders = true)
|
||||
private async Task<bool> RefreshLocalTrailers(IHasTrailers item, CancellationToken cancellationToken, bool forceSave = false, bool forceRefresh = false, bool allowSlowProviders = true)
|
||||
{
|
||||
var newItems = LoadLocalTrailers().ToList();
|
||||
var newItemIds = newItems.Select(i => i.Id).ToList();
|
||||
|
||||
var itemsChanged = !LocalTrailerIds.SequenceEqual(newItemIds);
|
||||
var itemsChanged = !item.LocalTrailerIds.SequenceEqual(newItemIds);
|
||||
|
||||
var tasks = newItems.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders, resetResolveArgs: false));
|
||||
|
||||
var results = await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
|
||||
LocalTrailerIds = newItemIds;
|
||||
item.LocalTrailerIds = newItemIds;
|
||||
|
||||
return itemsChanged || results.Contains(true);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
/// <param name="url">The URL.</param>
|
||||
/// <param name="isDirectLink">if set to <c>true</c> [is direct link].</param>
|
||||
/// <exception cref="System.ArgumentNullException">url</exception>
|
||||
public static void AddTrailerUrl(this BaseItem item, string url, bool isDirectLink)
|
||||
public static void AddTrailerUrl(this IHasTrailers item, string url, bool isDirectLink)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@ using System.Collections.Generic;
|
|||
|
||||
namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
public class Game : BaseItem, IHasSoundtracks
|
||||
public class Game : BaseItem, IHasSoundtracks, IHasTrailers
|
||||
{
|
||||
public List<Guid> SoundtrackIds { get; set; }
|
||||
|
||||
|
@ -12,8 +12,18 @@ namespace MediaBrowser.Controller.Entities
|
|||
{
|
||||
MultiPartGameFiles = new List<string>();
|
||||
SoundtrackIds = new List<Guid>();
|
||||
RemoteTrailers = new List<MediaUrl>();
|
||||
LocalTrailerIds = new List<Guid>();
|
||||
}
|
||||
|
||||
public List<Guid> LocalTrailerIds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the remote trailers.
|
||||
/// </summary>
|
||||
/// <value>The remote trailers.</value>
|
||||
public List<MediaUrl> RemoteTrailers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the media.
|
||||
/// </summary>
|
||||
|
|
21
MediaBrowser.Controller/Entities/IHasTrailers.cs
Normal file
21
MediaBrowser.Controller/Entities/IHasTrailers.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using MediaBrowser.Model.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
public interface IHasTrailers
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the remote trailers.
|
||||
/// </summary>
|
||||
/// <value>The remote trailers.</value>
|
||||
List<MediaUrl> RemoteTrailers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the local trailer ids.
|
||||
/// </summary>
|
||||
/// <value>The local trailer ids.</value>
|
||||
List<Guid> LocalTrailerIds { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,10 +1,26 @@
|
|||
|
||||
using System;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MediaBrowser.Controller.Entities.Movies
|
||||
{
|
||||
/// <summary>
|
||||
/// Class BoxSet
|
||||
/// </summary>
|
||||
public class BoxSet : Folder
|
||||
public class BoxSet : Folder, IHasTrailers
|
||||
{
|
||||
public BoxSet()
|
||||
{
|
||||
RemoteTrailers = new List<MediaUrl>();
|
||||
LocalTrailerIds = new List<Guid>();
|
||||
}
|
||||
|
||||
public List<Guid> LocalTrailerIds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the remote trailers.
|
||||
/// </summary>
|
||||
/// <value>The remote trailers.</value>
|
||||
public List<MediaUrl> RemoteTrailers { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace MediaBrowser.Controller.Entities.Movies
|
|||
/// <summary>
|
||||
/// Class Movie
|
||||
/// </summary>
|
||||
public class Movie : Video, IHasCriticRating, IHasSoundtracks, IHasBudget
|
||||
public class Movie : Video, IHasCriticRating, IHasSoundtracks, IHasBudget, IHasTrailers
|
||||
{
|
||||
public List<Guid> SpecialFeatureIds { get; set; }
|
||||
|
||||
|
@ -21,8 +21,14 @@ namespace MediaBrowser.Controller.Entities.Movies
|
|||
{
|
||||
SpecialFeatureIds = new List<Guid>();
|
||||
SoundtrackIds = new List<Guid>();
|
||||
RemoteTrailers = new List<MediaUrl>();
|
||||
LocalTrailerIds = new List<Guid>();
|
||||
}
|
||||
|
||||
public List<Guid> LocalTrailerIds { get; set; }
|
||||
|
||||
public List<MediaUrl> RemoteTrailers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the budget.
|
||||
/// </summary>
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace MediaBrowser.Controller.Entities.TV
|
|||
/// <summary>
|
||||
/// Class Series
|
||||
/// </summary>
|
||||
public class Series : Folder, IHasSoundtracks
|
||||
public class Series : Folder, IHasSoundtracks, IHasTrailers
|
||||
{
|
||||
public List<Guid> SpecialFeatureIds { get; set; }
|
||||
public List<Guid> SoundtrackIds { get; set; }
|
||||
|
@ -24,8 +24,14 @@ namespace MediaBrowser.Controller.Entities.TV
|
|||
|
||||
SpecialFeatureIds = new List<Guid>();
|
||||
SoundtrackIds = new List<Guid>();
|
||||
RemoteTrailers = new List<MediaUrl>();
|
||||
LocalTrailerIds = new List<Guid>();
|
||||
}
|
||||
|
||||
public List<Guid> LocalTrailerIds { get; set; }
|
||||
|
||||
public List<MediaUrl> RemoteTrailers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the status.
|
||||
/// </summary>
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
/// <summary>
|
||||
/// Class Trailer
|
||||
/// </summary>
|
||||
public class Trailer : Video, IHasCriticRating, IHasSoundtracks, IHasBudget
|
||||
public class Trailer : Video, IHasCriticRating, IHasSoundtracks, IHasBudget, IHasTrailers
|
||||
{
|
||||
public List<Guid> SoundtrackIds { get; set; }
|
||||
|
||||
|
@ -17,8 +17,13 @@ namespace MediaBrowser.Controller.Entities
|
|||
RemoteTrailers = new List<MediaUrl>();
|
||||
Taglines = new List<string>();
|
||||
SoundtrackIds = new List<Guid>();
|
||||
LocalTrailerIds = new List<Guid>();
|
||||
}
|
||||
|
||||
public List<Guid> LocalTrailerIds { get; set; }
|
||||
|
||||
public List<MediaUrl> RemoteTrailers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the budget.
|
||||
/// </summary>
|
||||
|
|
|
@ -93,6 +93,7 @@
|
|||
<Compile Include="Entities\IHasBudget.cs" />
|
||||
<Compile Include="Entities\IHasCriticRating.cs" />
|
||||
<Compile Include="Entities\IHasSoundtracks.cs" />
|
||||
<Compile Include="Entities\IHasTrailers.cs" />
|
||||
<Compile Include="Entities\IItemByName.cs" />
|
||||
<Compile Include="Entities\ILibraryItem.cs" />
|
||||
<Compile Include="Entities\ImageSourceInfo.cs" />
|
||||
|
|
|
@ -68,7 +68,12 @@ namespace MediaBrowser.Controller.Providers
|
|||
item.Genres.Clear();
|
||||
item.People.Clear();
|
||||
item.Tags.Clear();
|
||||
item.RemoteTrailers.Clear();
|
||||
|
||||
var hasTrailers = item as IHasTrailers;
|
||||
if (hasTrailers != null)
|
||||
{
|
||||
hasTrailers.RemoteTrailers.Clear();
|
||||
}
|
||||
|
||||
//Fetch(item, metadataFile, settings, Encoding.GetEncoding("ISO-8859-1"), cancellationToken);
|
||||
Fetch(item, metadataFile, settings, Encoding.UTF8, cancellationToken);
|
||||
|
@ -484,9 +489,13 @@ namespace MediaBrowser.Controller.Providers
|
|||
{
|
||||
var val = reader.ReadElementContentAsString();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(val))
|
||||
var hasTrailers = item as IHasTrailers;
|
||||
if (hasTrailers != null)
|
||||
{
|
||||
item.AddTrailerUrl(val, false);
|
||||
if (!string.IsNullOrWhiteSpace(val))
|
||||
{
|
||||
hasTrailers.AddTrailerUrl(val, false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -495,7 +504,11 @@ namespace MediaBrowser.Controller.Providers
|
|||
{
|
||||
using (var subtree = reader.ReadSubtree())
|
||||
{
|
||||
FetchDataFromTrailersNode(subtree, item);
|
||||
var hasTrailers = item as IHasTrailers;
|
||||
if (hasTrailers != null)
|
||||
{
|
||||
FetchDataFromTrailersNode(subtree, hasTrailers);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -940,7 +953,7 @@ namespace MediaBrowser.Controller.Providers
|
|||
}
|
||||
}
|
||||
|
||||
private void FetchDataFromTrailersNode(XmlReader reader, T item)
|
||||
private void FetchDataFromTrailersNode(XmlReader reader, IHasTrailers item)
|
||||
{
|
||||
reader.MoveToContent();
|
||||
|
||||
|
|
|
@ -874,14 +874,18 @@ namespace MediaBrowser.Providers.Movies
|
|||
if (movieData.trailers != null && movieData.trailers.youtube != null &&
|
||||
movieData.trailers.youtube.Count > 0)
|
||||
{
|
||||
movie.RemoteTrailers = movieData.trailers.youtube.Select(i => new MediaUrl
|
||||
var hasTrailers = movie as IHasTrailers;
|
||||
if (hasTrailers != null)
|
||||
{
|
||||
Url = string.Format("http://www.youtube.com/watch?v={0}", i.source),
|
||||
IsDirectLink = false,
|
||||
Name = i.name,
|
||||
VideoSize = string.Equals("hd", i.size, StringComparison.OrdinalIgnoreCase) ? VideoSize.HighDefinition : VideoSize.StandardDefinition
|
||||
hasTrailers.RemoteTrailers = movieData.trailers.youtube.Select(i => new MediaUrl
|
||||
{
|
||||
Url = string.Format("http://www.youtube.com/watch?v={0}", i.source),
|
||||
IsDirectLink = false,
|
||||
Name = i.name,
|
||||
VideoSize = string.Equals("hd", i.size, StringComparison.OrdinalIgnoreCase) ? VideoSize.HighDefinition : VideoSize.StandardDefinition
|
||||
|
||||
}).ToList();
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -268,16 +268,20 @@ namespace MediaBrowser.Providers.Savers
|
|||
}
|
||||
}
|
||||
|
||||
if (item.RemoteTrailers.Count > 0)
|
||||
var hasTrailers = item as IHasTrailers;
|
||||
if (hasTrailers != null)
|
||||
{
|
||||
builder.Append("<Trailers>");
|
||||
|
||||
foreach (var trailer in item.RemoteTrailers)
|
||||
if (hasTrailers.RemoteTrailers.Count > 0)
|
||||
{
|
||||
builder.Append("<Trailer>" + SecurityElement.Escape(trailer.Url) + "</Trailer>");
|
||||
}
|
||||
builder.Append("<Trailers>");
|
||||
|
||||
builder.Append("</Trailers>");
|
||||
foreach (var trailer in hasTrailers.RemoteTrailers)
|
||||
{
|
||||
builder.Append("<Trailer>" + SecurityElement.Escape(trailer.Url) + "</Trailer>");
|
||||
}
|
||||
|
||||
builder.Append("</Trailers>");
|
||||
}
|
||||
}
|
||||
|
||||
var hasBudget = item as IHasBudget;
|
||||
|
|
|
@ -808,11 +808,17 @@ namespace MediaBrowser.Server.Implementations.Dto
|
|||
}
|
||||
}
|
||||
|
||||
var localTrailerCount = item.LocalTrailerIds.Count;
|
||||
|
||||
if (localTrailerCount > 0)
|
||||
var hasTrailers = item as IHasTrailers;
|
||||
if (hasTrailers != null)
|
||||
{
|
||||
dto.LocalTrailerCount = localTrailerCount;
|
||||
dto.LocalTrailerCount = hasTrailers.LocalTrailerIds.Count;
|
||||
}
|
||||
|
||||
if (fields.Contains(ItemFields.RemoteTrailers))
|
||||
{
|
||||
dto.RemoteTrailers = hasTrailers != null ?
|
||||
hasTrailers.RemoteTrailers :
|
||||
new List<MediaUrl>();
|
||||
}
|
||||
|
||||
dto.Name = item.Name;
|
||||
|
@ -925,11 +931,6 @@ namespace MediaBrowser.Server.Implementations.Dto
|
|||
dto.Taglines = item.Taglines;
|
||||
}
|
||||
|
||||
if (fields.Contains(ItemFields.RemoteTrailers))
|
||||
{
|
||||
dto.RemoteTrailers = item.RemoteTrailers;
|
||||
}
|
||||
|
||||
dto.Type = item.GetClientTypeName();
|
||||
dto.CommunityRating = item.CommunityRating;
|
||||
dto.VoteCount = item.VoteCount;
|
||||
|
|
Loading…
Reference in New Issue
Block a user