2021-05-06 15:39:20 -07:00
|
|
|
#nullable disable
|
|
|
|
|
2019-01-13 13:01:16 -07:00
|
|
|
using System;
|
2018-12-27 16:27:57 -07:00
|
|
|
using System.Linq;
|
2021-06-19 09:02:33 -07:00
|
|
|
using Jellyfin.Extensions;
|
2019-01-13 12:25:32 -07:00
|
|
|
using MediaBrowser.Model.Entities;
|
2018-12-27 16:27:57 -07:00
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Entities
|
|
|
|
{
|
|
|
|
/// <summary>
|
2020-06-15 15:37:52 -07:00
|
|
|
/// Class Extensions.
|
2018-12-27 16:27:57 -07:00
|
|
|
/// </summary>
|
|
|
|
public static class Extensions
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Adds the trailer URL.
|
|
|
|
/// </summary>
|
|
|
|
public static void AddTrailerUrl(this BaseItem item, string url)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(url))
|
|
|
|
{
|
2019-01-06 13:50:43 -07:00
|
|
|
throw new ArgumentNullException(nameof(url));
|
2018-12-27 16:27:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var current = item.RemoteTrailers.FirstOrDefault(i => string.Equals(i.Url, url, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
if (current == null)
|
|
|
|
{
|
|
|
|
var mediaUrl = new MediaUrl
|
|
|
|
{
|
|
|
|
Url = url
|
|
|
|
};
|
|
|
|
|
2019-09-01 23:19:29 -07:00
|
|
|
if (item.RemoteTrailers.Count == 0)
|
2018-12-27 16:27:57 -07:00
|
|
|
{
|
|
|
|
item.RemoteTrailers = new[] { mediaUrl };
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-01 23:19:29 -07:00
|
|
|
var oldIds = item.RemoteTrailers;
|
|
|
|
var newIds = new MediaUrl[oldIds.Count + 1];
|
|
|
|
oldIds.CopyTo(newIds);
|
|
|
|
newIds[oldIds.Count] = mediaUrl;
|
|
|
|
item.RemoteTrailers = newIds;
|
2018-12-27 16:27:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|