You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/MediaBrowser.Controller/Entities/Extensions.cs

52 lines
1.5 KiB

using System;
6 years ago
using System.Linq;
using Jellyfin.Extensions;
using MediaBrowser.Model.Entities;
6 years ago
namespace MediaBrowser.Controller.Entities
{
/// <summary>
/// Class Extensions.
6 years ago
/// </summary>
public static class Extensions
{
/// <summary>
/// Adds the trailer URL.
/// </summary>
/// <param name="item">Media item.</param>
/// <param name="url">Trailer URL.</param>
6 years ago
public static void AddTrailerUrl(this BaseItem item, string url)
{
2 years ago
ArgumentNullException.ThrowIfNull(url, nameof(url));
if (url.Length == 0)
6 years ago
{
2 years ago
throw new ArgumentException("String can't be empty", nameof(url));
6 years ago
}
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)
6 years ago
{
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;
6 years ago
}
}
}
}
}