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.XbmcMetadata/Savers/MovieNfoSaver.cs

141 lines
4.8 KiB

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.XbmcMetadata.Savers
{
/// <summary>
/// Nfo saver for movies.
/// </summary>
11 years ago
public class MovieNfoSaver : BaseNfoSaver
{
/// <summary>
/// Initializes a new instance of the <see cref="MovieNfoSaver"/> class.
/// </summary>
/// <param name="fileSystem">The file system.</param>
/// <param name="configurationManager">the server configuration manager.</param>
/// <param name="libraryManager">The library manager.</param>
/// <param name="userManager">The user manager.</param>
/// <param name="userDataManager">The user data manager.</param>
/// <param name="logger">The logger.</param>
public MovieNfoSaver(
IFileSystem fileSystem,
IServerConfigurationManager configurationManager,
ILibraryManager libraryManager,
IUserManager userManager,
IUserDataManager userDataManager,
ILogger<MovieNfoSaver> logger)
: base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
{
}
/// <inheritdoc />
protected override string GetLocalSavePath(BaseItem item)
=> GetMovieSavePaths(new ItemInfo(item)).FirstOrDefault() ?? Path.ChangeExtension(item.Path, ".nfo");
internal static IEnumerable<string> GetMovieSavePaths(ItemInfo item)
{
if (item.VideoType == VideoType.Dvd && !item.IsPlaceHolder)
{
var path = item.ContainingFolderPath;
yield return Path.Combine(path, "VIDEO_TS", "VIDEO_TS.nfo");
}
if (!item.IsPlaceHolder && (item.VideoType == VideoType.Dvd || item.VideoType == VideoType.BluRay))
{
var path = item.ContainingFolderPath;
yield return Path.Combine(path, Path.GetFileName(path) + ".nfo");
}
else
{
yield return Path.ChangeExtension(item.Path, ".nfo");
// only allow movie object to read movie.nfo, not owned videos (which will be itemtype video, not movie)
if (!item.IsInMixedFolder && item.ItemType == typeof(Movie))
{
yield return Path.Combine(item.ContainingFolderPath, "movie.nfo");
}
}
}
/// <inheritdoc />
protected override string GetRootElementName(BaseItem item)
=> item is MusicVideo ? "musicvideo" : "movie";
/// <inheritdoc />
public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
11 years ago
{
if (!item.SupportsLocalMetadata)
{
return false;
}
11 years ago
// Check parent for null to avoid running this against things like video backdrops
if (item is Video video && item is not Episode && !video.ExtraType.HasValue)
11 years ago
{
return updateType >= MinimumUpdateType;
11 years ago
}
11 years ago
return false;
}
/// <inheritdoc />
protected override void WriteCustomElements(BaseItem item, XmlWriter writer)
11 years ago
{
var imdb = item.GetProviderId(MetadataProvider.Imdb);
if (!string.IsNullOrEmpty(imdb))
{
11 years ago
writer.WriteElementString("id", imdb);
}
if (item is MusicVideo musicVideo)
{
10 years ago
foreach (var artist in musicVideo.Artists)
{
10 years ago
writer.WriteElementString("artist", artist);
}
if (!string.IsNullOrEmpty(musicVideo.Album))
{
11 years ago
writer.WriteElementString("album", musicVideo.Album);
}
}
if (item is Movie movie)
{
if (!string.IsNullOrEmpty(movie.CollectionName))
{
writer.WriteElementString("set", movie.CollectionName);
}
}
11 years ago
}
/// <inheritdoc />
protected override IEnumerable<string> GetTagsUsed(BaseItem item)
11 years ago
{
foreach (var tag in base.GetTagsUsed(item))
11 years ago
{
yield return tag;
}
yield return "album";
yield return "artist";
yield return "set";
yield return "id";
}
}
}