added IHasTrailers

This commit is contained in:
Luke Pulverenti 2013-12-02 11:46:25 -05:00
parent 317f411070
commit cd279d98e0
15 changed files with 151 additions and 49 deletions

View File

@ -885,7 +885,19 @@ namespace MediaBrowser.Api.UserLibrary
if (request.HasTrailer.HasValue) 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) if (request.HasThemeSong.HasValue)

View File

@ -489,7 +489,15 @@ namespace MediaBrowser.Api.UserLibrary
// Get everything // Get everything
var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)).ToList(); 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) .Select(_libraryManager.GetItemById)
.OrderBy(i => i.SortName) .OrderBy(i => i.SortName)
.Select(i => _dtoService.GetBaseItemDto(i, fields, user, item)); .Select(i => _dtoService.GetBaseItemDto(i, fields, user, item));

View File

@ -37,10 +37,8 @@ namespace MediaBrowser.Controller.Entities
Tags = new List<string>(); Tags = new List<string>();
ThemeSongIds = new List<Guid>(); ThemeSongIds = new List<Guid>();
ThemeVideoIds = new List<Guid>(); ThemeVideoIds = new List<Guid>();
LocalTrailerIds = new List<Guid>();
LockedFields = new List<MetadataFields>(); LockedFields = new List<MetadataFields>();
Taglines = new List<string>(); Taglines = new List<string>();
RemoteTrailers = new List<MediaUrl>();
ImageSources = new List<ImageSourceInfo>(); ImageSources = new List<ImageSourceInfo>();
} }
@ -92,12 +90,6 @@ namespace MediaBrowser.Controller.Entities
/// <value>The taglines.</value> /// <value>The taglines.</value>
public List<string> Taglines { get; set; } 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> /// <summary>
/// Return the id that should be used to key display prefs for this item. /// 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. /// 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> ThemeSongIds { get; set; }
public List<Guid> ThemeVideoIds { get; set; } public List<Guid> ThemeVideoIds { get; set; }
public List<Guid> LocalTrailerIds { get; set; }
[IgnoreDataMember] [IgnoreDataMember]
public virtual string OfficialRatingForComparison public virtual string OfficialRatingForComparison
@ -897,7 +888,11 @@ namespace MediaBrowser.Controller.Entities
themeVideosChanged = await RefreshThemeVideos(cancellationToken, forceSave, forceRefresh, allowSlowProviders).ConfigureAwait(false); 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(); cancellationToken.ThrowIfCancellationRequested();
@ -917,18 +912,18 @@ namespace MediaBrowser.Controller.Entities
return changed; 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 newItems = LoadLocalTrailers().ToList();
var newItemIds = newItems.Select(i => i.Id).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 tasks = newItems.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders, resetResolveArgs: false));
var results = await Task.WhenAll(tasks).ConfigureAwait(false); var results = await Task.WhenAll(tasks).ConfigureAwait(false);
LocalTrailerIds = newItemIds; item.LocalTrailerIds = newItemIds;
return itemsChanged || results.Contains(true); return itemsChanged || results.Contains(true);
} }

View File

@ -16,7 +16,7 @@ namespace MediaBrowser.Controller.Entities
/// <param name="url">The URL.</param> /// <param name="url">The URL.</param>
/// <param name="isDirectLink">if set to <c>true</c> [is direct link].</param> /// <param name="isDirectLink">if set to <c>true</c> [is direct link].</param>
/// <exception cref="System.ArgumentNullException">url</exception> /// <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)) if (string.IsNullOrWhiteSpace(url))
{ {

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
namespace MediaBrowser.Controller.Entities namespace MediaBrowser.Controller.Entities
{ {
public class Game : BaseItem, IHasSoundtracks public class Game : BaseItem, IHasSoundtracks, IHasTrailers
{ {
public List<Guid> SoundtrackIds { get; set; } public List<Guid> SoundtrackIds { get; set; }
@ -12,8 +12,18 @@ namespace MediaBrowser.Controller.Entities
{ {
MultiPartGameFiles = new List<string>(); MultiPartGameFiles = new List<string>();
SoundtrackIds = new List<Guid>(); 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> /// <summary>
/// Gets the type of the media. /// Gets the type of the media.
/// </summary> /// </summary>

View 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; }
}
}

View File

@ -1,10 +1,26 @@
 using System;
using MediaBrowser.Model.Entities;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Entities.Movies namespace MediaBrowser.Controller.Entities.Movies
{ {
/// <summary> /// <summary>
/// Class BoxSet /// Class BoxSet
/// </summary> /// </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; }
} }
} }

View File

@ -11,7 +11,7 @@ namespace MediaBrowser.Controller.Entities.Movies
/// <summary> /// <summary>
/// Class Movie /// Class Movie
/// </summary> /// </summary>
public class Movie : Video, IHasCriticRating, IHasSoundtracks, IHasBudget public class Movie : Video, IHasCriticRating, IHasSoundtracks, IHasBudget, IHasTrailers
{ {
public List<Guid> SpecialFeatureIds { get; set; } public List<Guid> SpecialFeatureIds { get; set; }
@ -21,8 +21,14 @@ namespace MediaBrowser.Controller.Entities.Movies
{ {
SpecialFeatureIds = new List<Guid>(); SpecialFeatureIds = new List<Guid>();
SoundtrackIds = 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> /// <summary>
/// Gets or sets the budget. /// Gets or sets the budget.
/// </summary> /// </summary>

View File

@ -11,7 +11,7 @@ namespace MediaBrowser.Controller.Entities.TV
/// <summary> /// <summary>
/// Class Series /// Class Series
/// </summary> /// </summary>
public class Series : Folder, IHasSoundtracks public class Series : Folder, IHasSoundtracks, IHasTrailers
{ {
public List<Guid> SpecialFeatureIds { get; set; } public List<Guid> SpecialFeatureIds { get; set; }
public List<Guid> SoundtrackIds { get; set; } public List<Guid> SoundtrackIds { get; set; }
@ -24,8 +24,14 @@ namespace MediaBrowser.Controller.Entities.TV
SpecialFeatureIds = new List<Guid>(); SpecialFeatureIds = new List<Guid>();
SoundtrackIds = 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> /// <summary>
/// Gets or sets the status. /// Gets or sets the status.
/// </summary> /// </summary>

View File

@ -8,7 +8,7 @@ namespace MediaBrowser.Controller.Entities
/// <summary> /// <summary>
/// Class Trailer /// Class Trailer
/// </summary> /// </summary>
public class Trailer : Video, IHasCriticRating, IHasSoundtracks, IHasBudget public class Trailer : Video, IHasCriticRating, IHasSoundtracks, IHasBudget, IHasTrailers
{ {
public List<Guid> SoundtrackIds { get; set; } public List<Guid> SoundtrackIds { get; set; }
@ -17,8 +17,13 @@ namespace MediaBrowser.Controller.Entities
RemoteTrailers = new List<MediaUrl>(); RemoteTrailers = new List<MediaUrl>();
Taglines = new List<string>(); Taglines = new List<string>();
SoundtrackIds = new List<Guid>(); SoundtrackIds = new List<Guid>();
LocalTrailerIds = new List<Guid>();
} }
public List<Guid> LocalTrailerIds { get; set; }
public List<MediaUrl> RemoteTrailers { get; set; }
/// <summary> /// <summary>
/// Gets or sets the budget. /// Gets or sets the budget.
/// </summary> /// </summary>

View File

@ -93,6 +93,7 @@
<Compile Include="Entities\IHasBudget.cs" /> <Compile Include="Entities\IHasBudget.cs" />
<Compile Include="Entities\IHasCriticRating.cs" /> <Compile Include="Entities\IHasCriticRating.cs" />
<Compile Include="Entities\IHasSoundtracks.cs" /> <Compile Include="Entities\IHasSoundtracks.cs" />
<Compile Include="Entities\IHasTrailers.cs" />
<Compile Include="Entities\IItemByName.cs" /> <Compile Include="Entities\IItemByName.cs" />
<Compile Include="Entities\ILibraryItem.cs" /> <Compile Include="Entities\ILibraryItem.cs" />
<Compile Include="Entities\ImageSourceInfo.cs" /> <Compile Include="Entities\ImageSourceInfo.cs" />

View File

@ -68,7 +68,12 @@ namespace MediaBrowser.Controller.Providers
item.Genres.Clear(); item.Genres.Clear();
item.People.Clear(); item.People.Clear();
item.Tags.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.GetEncoding("ISO-8859-1"), cancellationToken);
Fetch(item, metadataFile, settings, Encoding.UTF8, cancellationToken); Fetch(item, metadataFile, settings, Encoding.UTF8, cancellationToken);
@ -484,9 +489,13 @@ namespace MediaBrowser.Controller.Providers
{ {
var val = reader.ReadElementContentAsString(); var val = reader.ReadElementContentAsString();
var hasTrailers = item as IHasTrailers;
if (hasTrailers != null)
{
if (!string.IsNullOrWhiteSpace(val)) if (!string.IsNullOrWhiteSpace(val))
{ {
item.AddTrailerUrl(val, false); hasTrailers.AddTrailerUrl(val, false);
}
} }
break; break;
} }
@ -495,7 +504,11 @@ namespace MediaBrowser.Controller.Providers
{ {
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
FetchDataFromTrailersNode(subtree, item); var hasTrailers = item as IHasTrailers;
if (hasTrailers != null)
{
FetchDataFromTrailersNode(subtree, hasTrailers);
}
} }
break; 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(); reader.MoveToContent();

View File

@ -874,7 +874,10 @@ namespace MediaBrowser.Providers.Movies
if (movieData.trailers != null && movieData.trailers.youtube != null && if (movieData.trailers != null && movieData.trailers.youtube != null &&
movieData.trailers.youtube.Count > 0) movieData.trailers.youtube.Count > 0)
{ {
movie.RemoteTrailers = movieData.trailers.youtube.Select(i => new MediaUrl var hasTrailers = movie as IHasTrailers;
if (hasTrailers != null)
{
hasTrailers.RemoteTrailers = movieData.trailers.youtube.Select(i => new MediaUrl
{ {
Url = string.Format("http://www.youtube.com/watch?v={0}", i.source), Url = string.Format("http://www.youtube.com/watch?v={0}", i.source),
IsDirectLink = false, IsDirectLink = false,
@ -884,6 +887,7 @@ namespace MediaBrowser.Providers.Movies
}).ToList(); }).ToList();
} }
} }
}
private DateTime _lastRequestDate = DateTime.MinValue; private DateTime _lastRequestDate = DateTime.MinValue;

View File

@ -268,17 +268,21 @@ namespace MediaBrowser.Providers.Savers
} }
} }
if (item.RemoteTrailers.Count > 0) var hasTrailers = item as IHasTrailers;
if (hasTrailers != null)
{
if (hasTrailers.RemoteTrailers.Count > 0)
{ {
builder.Append("<Trailers>"); builder.Append("<Trailers>");
foreach (var trailer in item.RemoteTrailers) foreach (var trailer in hasTrailers.RemoteTrailers)
{ {
builder.Append("<Trailer>" + SecurityElement.Escape(trailer.Url) + "</Trailer>"); builder.Append("<Trailer>" + SecurityElement.Escape(trailer.Url) + "</Trailer>");
} }
builder.Append("</Trailers>"); builder.Append("</Trailers>");
} }
}
var hasBudget = item as IHasBudget; var hasBudget = item as IHasBudget;
if (hasBudget != null) if (hasBudget != null)

View File

@ -808,11 +808,17 @@ namespace MediaBrowser.Server.Implementations.Dto
} }
} }
var localTrailerCount = item.LocalTrailerIds.Count; var hasTrailers = item as IHasTrailers;
if (hasTrailers != null)
if (localTrailerCount > 0)
{ {
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; dto.Name = item.Name;
@ -925,11 +931,6 @@ namespace MediaBrowser.Server.Implementations.Dto
dto.Taglines = item.Taglines; dto.Taglines = item.Taglines;
} }
if (fields.Contains(ItemFields.RemoteTrailers))
{
dto.RemoteTrailers = item.RemoteTrailers;
}
dto.Type = item.GetClientTypeName(); dto.Type = item.GetClientTypeName();
dto.CommunityRating = item.CommunityRating; dto.CommunityRating = item.CommunityRating;
dto.VoteCount = item.VoteCount; dto.VoteCount = item.VoteCount;