2019-01-13 20:01:16 +00:00
|
|
|
using System;
|
2018-12-27 23:27:57 +00:00
|
|
|
using System.Linq;
|
2021-06-19 16:02:33 +00:00
|
|
|
using Jellyfin.Extensions;
|
2019-01-13 19:25:32 +00:00
|
|
|
using MediaBrowser.Model.Entities;
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Entities
|
|
|
|
{
|
|
|
|
/// <summary>
|
2020-06-15 22:37:52 +00:00
|
|
|
/// Class Extensions.
|
2018-12-27 23:27:57 +00:00
|
|
|
/// </summary>
|
|
|
|
public static class Extensions
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Adds the trailer URL.
|
|
|
|
/// </summary>
|
2021-08-14 03:34:36 +00:00
|
|
|
/// <param name="item">Media item.</param>
|
|
|
|
/// <param name="url">Trailer URL.</param>
|
2018-12-27 23:27:57 +00:00
|
|
|
public static void AddTrailerUrl(this BaseItem item, string url)
|
|
|
|
{
|
2022-10-06 18:39:22 +00:00
|
|
|
ArgumentNullException.ThrowIfNull(url);
|
2022-08-12 18:37:31 +00:00
|
|
|
|
|
|
|
if (url.Length == 0)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
2022-08-12 18:37:31 +00:00
|
|
|
throw new ArgumentException("String can't be empty", nameof(url));
|
2018-12-27 23:27:57 +00: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-02 06:19:29 +00:00
|
|
|
if (item.RemoteTrailers.Count == 0)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
item.RemoteTrailers = new[] { mediaUrl };
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-02 06:19:29 +00: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 23:27:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|