using System;
using System.Linq;
using Jellyfin.Extensions;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.Entities
{
///
/// Class Extensions.
///
public static class Extensions
{
///
/// Adds the trailer URL.
///
/// Media item.
/// Trailer URL.
public static void AddTrailerUrl(this BaseItem item, string url)
{
ArgumentNullException.ThrowIfNull(url);
if (url.Length == 0)
{
throw new ArgumentException("String can't be empty", nameof(url));
}
var current = item.RemoteTrailers.FirstOrDefault(i => string.Equals(i.Url, url, StringComparison.OrdinalIgnoreCase));
if (current is null)
{
var mediaUrl = new MediaUrl
{
Url = url
};
if (item.RemoteTrailers.Count == 0)
{
item.RemoteTrailers = new[] { mediaUrl };
}
else
{
var oldIds = item.RemoteTrailers;
var newIds = new MediaUrl[oldIds.Count + 1];
oldIds.CopyTo(newIds);
newIds[oldIds.Count] = mediaUrl;
item.RemoteTrailers = newIds;
}
}
}
}
}