2019-01-13 21:03:10 +01:00
|
|
|
using System.Collections.Generic;
|
2019-01-13 20:26:56 +01:00
|
|
|
using System.IO;
|
2019-08-18 19:54:07 +02:00
|
|
|
using System.Linq;
|
2019-01-13 20:26:56 +01:00
|
|
|
using System.Xml;
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2014-06-30 05:04:50 +02:00
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
using MediaBrowser.Controller.Library;
|
2015-05-15 17:46:20 +02:00
|
|
|
using MediaBrowser.Controller.Providers;
|
Sort embedded collections in Nfo files
Because the Nfo files emit the collections as they are in-memory, the
files are not stable in format, genres, tags, albums, people, etc. are emitted in random orders. Add ordering of the collections when emitting the Nfo files so the file remains stable (unchanged) when underlying media information doesn't change.
In the process of this, it became clear that most of the providers and probes don't trim the strings like people's names, genre names, etc. so did a pass of Trim cleanup too.
Specific ordering: (alphabetical/numeric ascending after trimming blanks and defaulting to zero for missing numbers)
BaseItem: Directors, Writers, Trailers (by Url), Production Locations, Genres, Studios, Tags, Custom Provider Data (by key), Linked Children (by Path>LibraryItemId), Backdrop Images (by path), Actors (by SortOrder>Name)
AlbumNfo: Artists, Album Artists, Tracks (by ParentIndexNumber>IndexNumber>Name)
ArtistNfo: Albums (by Production Year>SortName>Name)
MovieNfo: Artists
Fix Debug build lint
Fix CI debug build lint issue.
Fix review issues
Fixed debug-build lint issues.
Emits the `disc` number to NFO for tracks with a non-zero ParentIndexNumber and only emit `position` if non-zero.
Removed the exception filtering I put in for testing.
Don't emit actors for MusicAlbums or MusicArtists
Swap from String.Trimmed() to ?.Trim()
Addressing PR feedback
Can't use ReadOnlySpan in an async method
Removed now-unused namespace
2023-05-15 07:38:27 +02:00
|
|
|
using MediaBrowser.Controller.Sorting;
|
2014-06-30 05:04:50 +02:00
|
|
|
using MediaBrowser.Model.Entities;
|
2016-10-25 21:02:04 +02:00
|
|
|
using MediaBrowser.Model.IO;
|
2019-01-13 20:26:56 +01:00
|
|
|
using Microsoft.Extensions.Logging;
|
2014-06-30 05:04:50 +02:00
|
|
|
|
|
|
|
namespace MediaBrowser.XbmcMetadata.Savers
|
|
|
|
{
|
2020-02-23 12:11:43 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Nfo saver for movies.
|
|
|
|
/// </summary>
|
2014-07-09 02:46:11 +02:00
|
|
|
public class MovieNfoSaver : BaseNfoSaver
|
2014-06-30 05:04:50 +02:00
|
|
|
{
|
2020-02-23 12:11:43 +01:00
|
|
|
/// <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)
|
2019-08-18 19:54:07 +02:00
|
|
|
: base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
|
2014-06-30 05:04:50 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-08-18 19:54:07 +02:00
|
|
|
/// <inheritdoc />
|
|
|
|
protected override string GetLocalSavePath(BaseItem item)
|
2020-12-31 12:09:25 +01:00
|
|
|
=> GetMovieSavePaths(new ItemInfo(item)).FirstOrDefault() ?? Path.ChangeExtension(item.Path, ".nfo");
|
2014-06-30 05:04:50 +02:00
|
|
|
|
2020-02-23 12:11:43 +01:00
|
|
|
internal static IEnumerable<string> GetMovieSavePaths(ItemInfo item)
|
2019-08-18 19:54:07 +02:00
|
|
|
{
|
2015-10-08 18:22:14 +02:00
|
|
|
if (item.VideoType == VideoType.Dvd && !item.IsPlaceHolder)
|
2014-06-30 05:04:50 +02:00
|
|
|
{
|
|
|
|
var path = item.ContainingFolderPath;
|
|
|
|
|
2019-08-18 19:54:07 +02:00
|
|
|
yield return Path.Combine(path, "VIDEO_TS", "VIDEO_TS.nfo");
|
2014-06-30 05:04:50 +02:00
|
|
|
}
|
|
|
|
|
2017-08-07 22:36:41 +02:00
|
|
|
if (!item.IsPlaceHolder && (item.VideoType == VideoType.Dvd || item.VideoType == VideoType.BluRay))
|
2015-05-15 17:46:20 +02:00
|
|
|
{
|
|
|
|
var path = item.ContainingFolderPath;
|
|
|
|
|
2019-08-18 19:54:07 +02:00
|
|
|
yield return Path.Combine(path, Path.GetFileName(path) + ".nfo");
|
2015-05-15 17:46:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-02-26 20:35:00 +01:00
|
|
|
// only allow movie object to read movie.nfo, not owned videos (which will be itemtype video, not movie)
|
2023-02-27 19:01:29 +01:00
|
|
|
if (!item.IsInMixedFolder && item.ItemType == typeof(Movie))
|
2017-07-21 21:05:52 +02:00
|
|
|
{
|
2019-08-18 19:54:07 +02:00
|
|
|
yield return Path.Combine(item.ContainingFolderPath, "movie.nfo");
|
2017-07-21 21:05:52 +02:00
|
|
|
}
|
2023-10-05 05:19:52 +02:00
|
|
|
|
|
|
|
yield return Path.ChangeExtension(item.Path, ".nfo");
|
2015-05-15 17:46:20 +02:00
|
|
|
}
|
2014-06-30 05:04:50 +02:00
|
|
|
}
|
|
|
|
|
2019-08-18 19:54:07 +02:00
|
|
|
/// <inheritdoc />
|
2018-09-12 19:26:21 +02:00
|
|
|
protected override string GetRootElementName(BaseItem item)
|
2019-08-18 19:54:07 +02:00
|
|
|
=> item is MusicVideo ? "musicvideo" : "movie";
|
2014-06-30 05:04:50 +02:00
|
|
|
|
2019-08-18 19:54:07 +02:00
|
|
|
/// <inheritdoc />
|
2018-09-12 19:26:21 +02:00
|
|
|
public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
|
2014-07-09 02:46:11 +02:00
|
|
|
{
|
|
|
|
if (!item.SupportsLocalMetadata)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-30 05:04:50 +02:00
|
|
|
|
2014-07-09 02:46:11 +02:00
|
|
|
// Check parent for null to avoid running this against things like video backdrops
|
2021-08-29 00:32:50 +02:00
|
|
|
if (item is Video video && item is not Episode && !video.ExtraType.HasValue)
|
2014-07-09 02:46:11 +02:00
|
|
|
{
|
2015-01-04 06:55:34 +01:00
|
|
|
return updateType >= MinimumUpdateType;
|
2014-07-09 02:46:11 +02:00
|
|
|
}
|
2014-06-30 05:04:50 +02:00
|
|
|
|
2014-07-09 02:46:11 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-06-30 05:04:50 +02:00
|
|
|
|
2019-08-18 19:54:07 +02:00
|
|
|
/// <inheritdoc />
|
2018-09-12 19:26:21 +02:00
|
|
|
protected override void WriteCustomElements(BaseItem item, XmlWriter writer)
|
2014-07-09 02:46:11 +02:00
|
|
|
{
|
2020-06-06 21:17:49 +02:00
|
|
|
var imdb = item.GetProviderId(MetadataProvider.Imdb);
|
2014-06-30 05:04:50 +02:00
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(imdb))
|
|
|
|
{
|
2014-07-09 02:46:11 +02:00
|
|
|
writer.WriteElementString("id", imdb);
|
2014-06-30 05:04:50 +02:00
|
|
|
}
|
|
|
|
|
2019-08-18 19:54:07 +02:00
|
|
|
if (item is MusicVideo musicVideo)
|
2014-06-30 05:04:50 +02:00
|
|
|
{
|
Sort embedded collections in Nfo files
Because the Nfo files emit the collections as they are in-memory, the
files are not stable in format, genres, tags, albums, people, etc. are emitted in random orders. Add ordering of the collections when emitting the Nfo files so the file remains stable (unchanged) when underlying media information doesn't change.
In the process of this, it became clear that most of the providers and probes don't trim the strings like people's names, genre names, etc. so did a pass of Trim cleanup too.
Specific ordering: (alphabetical/numeric ascending after trimming blanks and defaulting to zero for missing numbers)
BaseItem: Directors, Writers, Trailers (by Url), Production Locations, Genres, Studios, Tags, Custom Provider Data (by key), Linked Children (by Path>LibraryItemId), Backdrop Images (by path), Actors (by SortOrder>Name)
AlbumNfo: Artists, Album Artists, Tracks (by ParentIndexNumber>IndexNumber>Name)
ArtistNfo: Albums (by Production Year>SortName>Name)
MovieNfo: Artists
Fix Debug build lint
Fix CI debug build lint issue.
Fix review issues
Fixed debug-build lint issues.
Emits the `disc` number to NFO for tracks with a non-zero ParentIndexNumber and only emit `position` if non-zero.
Removed the exception filtering I put in for testing.
Don't emit actors for MusicAlbums or MusicArtists
Swap from String.Trimmed() to ?.Trim()
Addressing PR feedback
Can't use ReadOnlySpan in an async method
Removed now-unused namespace
2023-05-15 07:38:27 +02:00
|
|
|
foreach (var artist in musicVideo.Artists.Trimmed().OrderBy(artist => artist))
|
2014-06-30 05:04:50 +02:00
|
|
|
{
|
2014-10-20 22:23:40 +02:00
|
|
|
writer.WriteElementString("artist", artist);
|
2014-06-30 05:04:50 +02:00
|
|
|
}
|
2020-02-23 12:11:43 +01:00
|
|
|
|
2014-06-30 05:04:50 +02:00
|
|
|
if (!string.IsNullOrEmpty(musicVideo.Album))
|
|
|
|
{
|
2014-07-09 02:46:11 +02:00
|
|
|
writer.WriteElementString("album", musicVideo.Album);
|
2014-06-30 05:04:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-18 19:54:07 +02:00
|
|
|
if (item is Movie movie)
|
2014-06-30 05:04:50 +02:00
|
|
|
{
|
2016-03-14 02:34:24 +01:00
|
|
|
if (!string.IsNullOrEmpty(movie.CollectionName))
|
2014-06-30 05:04:50 +02:00
|
|
|
{
|
2016-03-14 02:34:24 +01:00
|
|
|
writer.WriteElementString("set", movie.CollectionName);
|
2014-06-30 05:04:50 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-09 02:46:11 +02:00
|
|
|
}
|
2014-06-30 05:04:50 +02:00
|
|
|
|
2019-08-18 19:54:07 +02:00
|
|
|
/// <inheritdoc />
|
2021-03-09 03:04:47 +01:00
|
|
|
protected override IEnumerable<string> GetTagsUsed(BaseItem item)
|
2014-07-09 02:46:11 +02:00
|
|
|
{
|
2021-03-09 03:04:47 +01:00
|
|
|
foreach (var tag in base.GetTagsUsed(item))
|
2014-07-09 02:46:11 +02:00
|
|
|
{
|
2021-03-09 03:04:47 +01:00
|
|
|
yield return tag;
|
|
|
|
}
|
2016-10-26 04:53:47 +02:00
|
|
|
|
2021-03-09 03:04:47 +01:00
|
|
|
yield return "album";
|
|
|
|
yield return "artist";
|
|
|
|
yield return "set";
|
|
|
|
yield return "id";
|
2016-10-26 04:53:47 +02:00
|
|
|
}
|
2014-06-30 05:04:50 +02:00
|
|
|
}
|
|
|
|
}
|