2013-09-11 17:54:59 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2017-08-10 18:01:31 +00:00
|
|
|
|
using MediaBrowser.Model.Extensions;
|
2013-09-11 17:54:59 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Entities
|
|
|
|
|
{
|
2013-09-13 15:04:19 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class Extensions
|
|
|
|
|
/// </summary>
|
2013-09-11 17:54:59 +00:00
|
|
|
|
public static class Extensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2013-09-13 15:04:19 +00:00
|
|
|
|
/// Adds the trailer URL.
|
2013-09-11 17:54:59 +00:00
|
|
|
|
/// </summary>
|
2017-08-10 18:01:31 +00:00
|
|
|
|
public static void AddTrailerUrl(this IHasTrailers item, string url)
|
2013-09-11 17:54:59 +00:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(url))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("url");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var current = item.RemoteTrailers.FirstOrDefault(i => string.Equals(i.Url, url, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
2014-09-22 21:56:54 +00:00
|
|
|
|
if (current == null)
|
2013-09-11 17:54:59 +00:00
|
|
|
|
{
|
2017-08-10 18:01:31 +00:00
|
|
|
|
var mediaUrl = new MediaUrl
|
2013-09-11 17:54:59 +00:00
|
|
|
|
{
|
2014-09-22 21:56:54 +00:00
|
|
|
|
Url = url
|
2017-08-10 18:01:31 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (item.RemoteTrailers.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
item.RemoteTrailers = new[] { mediaUrl };
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var list = item.RemoteTrailers.ToArray(item.RemoteTrailers.Length + 1);
|
|
|
|
|
list[list.Length - 1] = mediaUrl;
|
|
|
|
|
|
|
|
|
|
item.RemoteTrailers = list;
|
|
|
|
|
}
|
2013-09-11 17:54:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|