2013-09-11 10:54:59 -07:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2017-08-10 11:01:31 -07:00
|
|
|
|
using MediaBrowser.Model.Extensions;
|
2013-09-11 10:54:59 -07:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Entities
|
|
|
|
|
{
|
2013-09-13 08:04:19 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class Extensions
|
|
|
|
|
/// </summary>
|
2013-09-11 10:54:59 -07:00
|
|
|
|
public static class Extensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2013-09-13 08:04:19 -07:00
|
|
|
|
/// Adds the trailer URL.
|
2013-09-11 10:54:59 -07:00
|
|
|
|
/// </summary>
|
2017-08-10 11:01:31 -07:00
|
|
|
|
public static void AddTrailerUrl(this IHasTrailers item, string url)
|
2013-09-11 10:54:59 -07: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 14:56:54 -07:00
|
|
|
|
if (current == null)
|
2013-09-11 10:54:59 -07:00
|
|
|
|
{
|
2017-08-10 11:01:31 -07:00
|
|
|
|
var mediaUrl = new MediaUrl
|
2013-09-11 10:54:59 -07:00
|
|
|
|
{
|
2014-09-22 14:56:54 -07:00
|
|
|
|
Url = url
|
2017-08-10 11:01:31 -07: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 10:54:59 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|