From 5782d9084db2e3b4f2b5d4dfc8d5dfef02498906 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 27 Jun 2013 12:36:41 -0400 Subject: [PATCH] fixes #299 - Add trailer urls to MovieDbProvider --- MediaBrowser.Controller/Dto/DtoBuilder.cs | 4 +-- MediaBrowser.Controller/Entities/BaseItem.cs | 24 ++++++++++------- .../Providers/BaseItemXmlParser.cs | 2 +- .../MediaBrowser.Model.net35.csproj | 3 +++ MediaBrowser.Model/Dto/BaseItemDto.cs | 12 +-------- MediaBrowser.Model/Entities/MediaUrl.cs | 11 ++++++++ MediaBrowser.Model/MediaBrowser.Model.csproj | 1 + MediaBrowser.Model/Querying/ItemFields.cs | 2 +- .../Movies/MovieDbProvider.cs | 26 +++++++++++++++++++ 9 files changed, 61 insertions(+), 24 deletions(-) create mode 100644 MediaBrowser.Model/Entities/MediaUrl.cs diff --git a/MediaBrowser.Controller/Dto/DtoBuilder.cs b/MediaBrowser.Controller/Dto/DtoBuilder.cs index 77559958a8..e27b364221 100644 --- a/MediaBrowser.Controller/Dto/DtoBuilder.cs +++ b/MediaBrowser.Controller/Dto/DtoBuilder.cs @@ -399,9 +399,9 @@ namespace MediaBrowser.Controller.Dto dto.Taglines = item.Taglines; } - if (fields.Contains(ItemFields.TrailerUrls)) + if (fields.Contains(ItemFields.RemoteTrailers)) { - dto.TrailerUrls = item.TrailerUrls; + dto.RemoteTrailers = item.RemoteTrailers; } dto.Type = item.GetType().Name; diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index d13e69fce0..3202250314 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -27,7 +27,7 @@ namespace MediaBrowser.Controller.Entities protected BaseItem() { Genres = new List(); - TrailerUrls = new List(); + RemoteTrailers = new List(); Studios = new List(); People = new List(); Taglines = new List(); @@ -903,7 +903,7 @@ namespace MediaBrowser.Controller.Entities /// Gets or sets the trailer URL. /// /// The trailer URL. - public List TrailerUrls { get; set; } + public List RemoteTrailers { get; set; } /// /// Gets or sets the provider ids. @@ -1180,22 +1180,28 @@ namespace MediaBrowser.Controller.Entities /// Adds a TrailerUrl to the item /// /// The URL. - /// - public void AddTrailerUrl(string url) + /// if set to true [is direct link]. + /// url + public void AddTrailerUrl(string url, bool isDirectLink) { if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentNullException("url"); } - if (TrailerUrls == null) + var current = RemoteTrailers.FirstOrDefault(i => string.Equals(i.Url, url, StringComparison.OrdinalIgnoreCase)); + + if (current != null) { - TrailerUrls = new List(); + current.IsDirectLink = isDirectLink; } - - if (!TrailerUrls.Contains(url, StringComparer.OrdinalIgnoreCase)) + else { - TrailerUrls.Add(url); + RemoteTrailers.Add(new MediaUrl + { + Url = url, + IsDirectLink = isDirectLink + }); } } diff --git a/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs b/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs index cb2bf68774..1c7e667a23 100644 --- a/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs +++ b/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs @@ -406,7 +406,7 @@ namespace MediaBrowser.Controller.Providers if (!string.IsNullOrWhiteSpace(val)) { - //item.AddTrailerUrl(val); + item.AddTrailerUrl(val, false); } break; } diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj index 7061c4277a..6bce2a8337 100644 --- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj +++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj @@ -133,6 +133,9 @@ Entities\MediaType.cs + + Entities\MediaUrl.cs + Entities\MetadataFields.cs diff --git a/MediaBrowser.Model/Dto/BaseItemDto.cs b/MediaBrowser.Model/Dto/BaseItemDto.cs index f5398ddd5f..149029b597 100644 --- a/MediaBrowser.Model/Dto/BaseItemDto.cs +++ b/MediaBrowser.Model/Dto/BaseItemDto.cs @@ -160,7 +160,7 @@ namespace MediaBrowser.Model.Dto /// Gets or sets the trailer urls. /// /// The trailer urls. - public List TrailerUrls { get; set; } + public List RemoteTrailers { get; set; } /// /// Gets or sets the provider ids. @@ -614,16 +614,6 @@ namespace MediaBrowser.Model.Dto get { return ImageTags != null && ImageTags.ContainsKey(ImageType.Menu); } } - /// - /// Gets a value indicating whether this instance is video. - /// - /// true if this instance is video; otherwise, false. - [IgnoreDataMember] - public bool HasTrailer - { - get { return LocalTrailerCount > 0 || (TrailerUrls != null && TrailerUrls.Count > 0); } - } - /// /// Gets a value indicating whether this instance is video. /// diff --git a/MediaBrowser.Model/Entities/MediaUrl.cs b/MediaBrowser.Model/Entities/MediaUrl.cs new file mode 100644 index 0000000000..b998796502 --- /dev/null +++ b/MediaBrowser.Model/Entities/MediaUrl.cs @@ -0,0 +1,11 @@ + +namespace MediaBrowser.Model.Entities +{ + public class MediaUrl + { + public string Url { get; set; } + public string Name { get; set; } + public bool? IsHD { get; set; } + public bool IsDirectLink { get; set; } + } +} diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index 06dfa776d3..6b1c728e28 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -52,6 +52,7 @@ + diff --git a/MediaBrowser.Model/Querying/ItemFields.cs b/MediaBrowser.Model/Querying/ItemFields.cs index a8a58d6a64..b6f452d7cf 100644 --- a/MediaBrowser.Model/Querying/ItemFields.cs +++ b/MediaBrowser.Model/Querying/ItemFields.cs @@ -154,7 +154,7 @@ namespace MediaBrowser.Model.Querying /// /// The trailer url of the item /// - TrailerUrls, + RemoteTrailers, /// /// The user data of the item diff --git a/MediaBrowser.Providers/Movies/MovieDbProvider.cs b/MediaBrowser.Providers/Movies/MovieDbProvider.cs index 1ebae94186..7a22a4d197 100644 --- a/MediaBrowser.Providers/Movies/MovieDbProvider.cs +++ b/MediaBrowser.Providers/Movies/MovieDbProvider.cs @@ -793,6 +793,19 @@ namespace MediaBrowser.Providers.Movies { movie.Tags = movieData.keywords.keywords.Select(i => i.name).ToList(); } + + if (movieData.trailers != null && movieData.trailers.youtube != null && + movieData.trailers.youtube.Count > 0) + { + movie.RemoteTrailers = movieData.trailers.youtube.Select(i => new MediaUrl + { + Url = string.Format("http://www.youtube.com/watch?{0}", i.source), + IsDirectLink = false, + Name = i.name, + IsHD = string.Equals("hd", i.size, StringComparison.OrdinalIgnoreCase) + + }).ToList(); + } } } @@ -1179,6 +1192,19 @@ namespace MediaBrowser.Providers.Movies public Casts casts { get; set; } public Releases releases { get; set; } public Keywords keywords { get; set; } + public Trailers trailers { get; set; } + } + + public class Trailers + { + public List youtube { get; set; } + } + + public class Youtube + { + public string name { get; set; } + public string size { get; set; } + public string source { get; set; } } public class TmdbImageSettings