jellyfin/MediaBrowser.Controller/Entities/Extensions.cs

52 lines
1.5 KiB
C#
Raw Normal View History

using System;
2018-12-27 16:27:57 -07:00
using System.Linq;
using Jellyfin.Extensions;
using MediaBrowser.Model.Entities;
2018-12-27 16:27:57 -07:00
namespace MediaBrowser.Controller.Entities
{
/// <summary>
/// Class Extensions.
2018-12-27 16:27:57 -07:00
/// </summary>
public static class Extensions
{
/// <summary>
/// Adds the trailer URL.
/// </summary>
/// <param name="item">Media item.</param>
/// <param name="url">Trailer URL.</param>
2018-12-27 16:27:57 -07:00
public static void AddTrailerUrl(this BaseItem item, string url)
{
2022-10-06 11:39:22 -07:00
ArgumentNullException.ThrowIfNull(url);
2022-08-12 11:37:31 -07:00
if (url.Length == 0)
2018-12-27 16:27:57 -07:00
{
2022-08-12 11:37:31 -07:00
throw new ArgumentException("String can't be empty", 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
};
if (item.RemoteTrailers.Count == 0)
2018-12-27 16:27:57 -07:00
{
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;
2018-12-27 16:27:57 -07:00
}
}
}
}
}