jellyfin/MediaBrowser.Controller/Entities/Extensions.cs

43 lines
1.1 KiB
C#
Raw Normal View History

using System;
2018-12-27 23:27:57 +00:00
using System.Linq;
using Jellyfin.Extensions;
using MediaBrowser.Model.Entities;
2018-12-27 23:27:57 +00:00
namespace MediaBrowser.Controller.Entities
{
/// <summary>
/// Class Extensions.
2018-12-27 23:27:57 +00: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 23:27:57 +00:00
public static void AddTrailerUrl(this BaseItem item, string url)
{
ArgumentException.ThrowIfNullOrEmpty(url);
2018-12-27 23:27:57 +00:00
var current = item.RemoteTrailers.FirstOrDefault(i => string.Equals(i.Url, url, StringComparison.OrdinalIgnoreCase));
2022-12-05 14:00:20 +00:00
if (current is null)
2018-12-27 23:27:57 +00:00
{
var mediaUrl = new MediaUrl
{
Url = url
};
if (item.RemoteTrailers.Count == 0)
2018-12-27 23:27:57 +00:00
{
2024-04-30 19:32:59 +00:00
item.RemoteTrailers = [mediaUrl];
2018-12-27 23:27:57 +00:00
}
else
{
2024-04-30 19:32:59 +00:00
item.RemoteTrailers = [..item.RemoteTrailers, mediaUrl];
2018-12-27 23:27:57 +00:00
}
}
}
}
}