Merge pull request #2105 from softworkz/ProviderrIdPersistence

Programmatic provider id handling for xml and nfo persistence
This commit is contained in:
Luke 2016-09-02 18:19:15 -04:00 committed by GitHub
commit adeb944c61
37 changed files with 195 additions and 438 deletions

View File

@ -23,14 +23,18 @@ namespace MediaBrowser.Controller.Providers
/// The logger
/// </summary>
protected ILogger Logger { get; private set; }
protected IProviderManager ProviderManager { get; private set; }
private Dictionary<string, string> _validProviderIds;
/// <summary>
/// Initializes a new instance of the <see cref="BaseItemXmlParser{T}" /> class.
/// </summary>
/// <param name="logger">The logger.</param>
public BaseItemXmlParser(ILogger logger)
public BaseItemXmlParser(ILogger logger, IProviderManager providerManager)
{
Logger = logger;
ProviderManager = providerManager;
}
/// <summary>
@ -60,6 +64,22 @@ namespace MediaBrowser.Controller.Providers
ValidationType = ValidationType.None
};
_validProviderIds = _validProviderIds = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
var idInfos = ProviderManager.GetExternalIdInfos(item.Item);
foreach (var info in idInfos)
{
var id = info.Key + "Id";
if (!_validProviderIds.ContainsKey(id))
{
_validProviderIds.Add(id, info.Key);
}
}
//Additional Mappings
_validProviderIds.Add("IMDB", "Imdb");
//Fetch(item, metadataFile, settings, Encoding.GetEncoding("ISO-8859-1"), cancellationToken);
Fetch(item, metadataFile, settings, Encoding.UTF8, cancellationToken);
}
@ -657,14 +677,6 @@ namespace MediaBrowser.Controller.Providers
break;
}
case "TvDbId":
var tvdbId = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(tvdbId))
{
item.SetProviderId(MetadataProviders.Tvdb, tvdbId);
}
break;
case "VoteCount":
{
var val = reader.ReadElementContentAsString();
@ -679,95 +691,6 @@ namespace MediaBrowser.Controller.Providers
}
break;
}
case "MusicBrainzAlbumId":
{
var mbz = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(mbz))
{
item.SetProviderId(MetadataProviders.MusicBrainzAlbum, mbz);
}
break;
}
case "MusicBrainzAlbumArtistId":
{
var mbz = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(mbz))
{
item.SetProviderId(MetadataProviders.MusicBrainzAlbumArtist, mbz);
}
break;
}
case "MusicBrainzArtistId":
{
var mbz = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(mbz))
{
item.SetProviderId(MetadataProviders.MusicBrainzArtist, mbz);
}
break;
}
case "MusicBrainzReleaseGroupId":
{
var mbz = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(mbz))
{
item.SetProviderId(MetadataProviders.MusicBrainzReleaseGroup, mbz);
}
break;
}
case "TVRageId":
{
var id = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(id))
{
item.SetProviderId(MetadataProviders.TvRage, id);
}
break;
}
case "TvMazeId":
{
var id = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(id))
{
item.SetProviderId(MetadataProviders.TvMaze, id);
}
break;
}
case "AudioDbArtistId":
{
var id = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(id))
{
item.SetProviderId(MetadataProviders.AudioDbArtist, id);
}
break;
}
case "AudioDbAlbumId":
{
var id = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(id))
{
item.SetProviderId(MetadataProviders.AudioDbAlbum, id);
}
break;
}
case "RottenTomatoesId":
var rtId = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(rtId))
{
item.SetProviderId(MetadataProviders.RottenTomatoes, rtId);
}
break;
case "TMDbId":
var tmdb = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(tmdb))
{
item.SetProviderId(MetadataProviders.Tmdb, tmdb);
}
break;
case "TMDbCollectionId":
case "CollectionNumber":
var tmdbCollection = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(tmdbCollection))
@ -776,30 +699,6 @@ namespace MediaBrowser.Controller.Providers
}
break;
case "TVcomId":
var TVcomId = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(TVcomId))
{
item.SetProviderId(MetadataProviders.Tvcom, TVcomId);
}
break;
case "Zap2ItId":
var zap2ItId = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(zap2ItId))
{
item.SetProviderId(MetadataProviders.Zap2It, zap2ItId);
}
break;
case "IMDB":
var imDbId = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(imDbId))
{
item.SetProviderId(MetadataProviders.Imdb, imDbId);
}
break;
case "Genres":
{
using (var subtree = reader.ReadSubtree())
@ -891,7 +790,19 @@ namespace MediaBrowser.Controller.Providers
}
default:
reader.Skip();
if (_validProviderIds.ContainsKey(reader.Name))
{
var id = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(id))
{
item.SetProviderId(_validProviderIds[reader.Name], id);
}
}
else
{
reader.Skip();
}
break;
}
}

View File

@ -9,8 +9,8 @@ namespace MediaBrowser.LocalMetadata.Parsers
{
public class BoxSetXmlParser : BaseItemXmlParser<BoxSet>
{
public BoxSetXmlParser(ILogger logger)
: base(logger)
public BoxSetXmlParser(ILogger logger, IProviderManager providerManager)
: base(logger, providerManager)
{
}

View File

@ -20,8 +20,8 @@ namespace MediaBrowser.LocalMetadata.Parsers
private List<LocalImageInfo> _imagesFound;
private readonly IFileSystem _fileSystem;
public EpisodeXmlParser(ILogger logger, IFileSystem fileSystem)
: base(logger)
public EpisodeXmlParser(ILogger logger, IFileSystem fileSystem, IProviderManager providerManager)
: base(logger, providerManager)
{
_fileSystem = fileSystem;
}

View File

@ -10,8 +10,8 @@ namespace MediaBrowser.LocalMetadata.Parsers
{
public class GameSystemXmlParser : BaseItemXmlParser<GameSystem>
{
public GameSystemXmlParser(ILogger logger)
: base(logger)
public GameSystemXmlParser(ILogger logger, IProviderManager providerManager)
: base(logger, providerManager)
{
}

View File

@ -16,8 +16,8 @@ namespace MediaBrowser.LocalMetadata.Parsers
{
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
public GameXmlParser(ILogger logger)
: base(logger)
public GameXmlParser(ILogger logger, IProviderManager providerManager)
: base(logger, providerManager)
{
}

View File

@ -12,8 +12,8 @@ namespace MediaBrowser.LocalMetadata.Parsers
public class BaseVideoXmlParser<T> : BaseItemXmlParser<T>
where T : Video
{
public BaseVideoXmlParser(ILogger logger)
: base(logger)
public BaseVideoXmlParser(ILogger logger, IProviderManager providerManager)
: base(logger, providerManager)
{
}
@ -50,15 +50,15 @@ namespace MediaBrowser.LocalMetadata.Parsers
public class MovieXmlParser : BaseVideoXmlParser<Movie>
{
public MovieXmlParser(ILogger logger) : base(logger)
public MovieXmlParser(ILogger logger, IProviderManager providerManager) : base(logger, providerManager)
{
}
}
public class VideoXmlParser : BaseVideoXmlParser<Video>
{
public VideoXmlParser(ILogger logger)
: base(logger)
public VideoXmlParser(ILogger logger, IProviderManager providerManager)
: base(logger, providerManager)
{
}
}

View File

@ -12,8 +12,8 @@ namespace MediaBrowser.LocalMetadata.Parsers
/// Initializes a new instance of the <see cref="BaseItemXmlParser{T}" /> class.
/// </summary>
/// <param name="logger">The logger.</param>
public MusicVideoXmlParser(ILogger logger)
: base(logger)
public MusicVideoXmlParser(ILogger logger, IProviderManager providerManager)
: base(logger, providerManager)
{
}

View File

@ -11,8 +11,8 @@ namespace MediaBrowser.LocalMetadata.Parsers
{
public class PlaylistXmlParser : BaseItemXmlParser<Playlist>
{
public PlaylistXmlParser(ILogger logger)
: base(logger)
public PlaylistXmlParser(ILogger logger, IProviderManager providerManager)
: base(logger, providerManager)
{
}

View File

@ -7,8 +7,8 @@ namespace MediaBrowser.LocalMetadata.Parsers
{
public class SeasonXmlParser : BaseItemXmlParser<Season>
{
public SeasonXmlParser(ILogger logger)
: base(logger)
public SeasonXmlParser(ILogger logger, IProviderManager providerManager)
: base(logger, providerManager)
{
}

View File

@ -17,8 +17,8 @@ namespace MediaBrowser.LocalMetadata.Parsers
/// Initializes a new instance of the <see cref="BaseItemXmlParser{T}" /> class.
/// </summary>
/// <param name="logger">The logger.</param>
public SeriesXmlParser(ILogger logger)
: base(logger)
public SeriesXmlParser(ILogger logger, IProviderManager providerManager)
: base(logger, providerManager)
{
}

View File

@ -14,16 +14,18 @@ namespace MediaBrowser.LocalMetadata.Providers
public class BoxSetXmlProvider : BaseXmlProvider<BoxSet>
{
private readonly ILogger _logger;
private readonly IProviderManager _providerManager;
public BoxSetXmlProvider(IFileSystem fileSystem, ILogger logger)
public BoxSetXmlProvider(IFileSystem fileSystem, ILogger logger, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<BoxSet> result, string path, CancellationToken cancellationToken)
{
new BoxSetXmlParser(_logger).Fetch(result, path, cancellationToken);
new BoxSetXmlParser(_logger, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -13,11 +13,13 @@ namespace MediaBrowser.LocalMetadata.Providers
public class EpisodeXmlProvider : BaseXmlProvider<Episode>
{
private readonly ILogger _logger;
private readonly IProviderManager _providerManager;
public EpisodeXmlProvider(IFileSystem fileSystem, ILogger logger)
public EpisodeXmlProvider(IFileSystem fileSystem, ILogger logger, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<Episode> result, string path, CancellationToken cancellationToken)
@ -25,7 +27,7 @@ namespace MediaBrowser.LocalMetadata.Providers
var images = new List<LocalImageInfo>();
var chapters = new List<ChapterInfo>();
new EpisodeXmlParser(_logger, FileSystem).Fetch(result, images, path, cancellationToken);
new EpisodeXmlParser(_logger, FileSystem, _providerManager).Fetch(result, images, path, cancellationToken);
result.Images = images;
}

View File

@ -13,16 +13,18 @@ namespace MediaBrowser.LocalMetadata.Providers
public class FolderXmlProvider : BaseXmlProvider<Folder>
{
private readonly ILogger _logger;
private readonly IProviderManager _providerManager;
public FolderXmlProvider(IFileSystem fileSystem, ILogger logger)
public FolderXmlProvider(IFileSystem fileSystem, ILogger logger, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<Folder> result, string path, CancellationToken cancellationToken)
{
new BaseItemXmlParser<Folder>(_logger).Fetch(result, path, cancellationToken);
new BaseItemXmlParser<Folder>(_logger, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -11,16 +11,18 @@ namespace MediaBrowser.LocalMetadata.Providers
public class GameSystemXmlProvider : BaseXmlProvider<GameSystem>
{
private readonly ILogger _logger;
private readonly IProviderManager _providerManager;
public GameSystemXmlProvider(IFileSystem fileSystem, ILogger logger)
public GameSystemXmlProvider(IFileSystem fileSystem, ILogger logger, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<GameSystem> result, string path, CancellationToken cancellationToken)
{
new GameSystemXmlParser(_logger).Fetch(result, path, cancellationToken);
new GameSystemXmlParser(_logger, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -11,16 +11,18 @@ namespace MediaBrowser.LocalMetadata.Providers
public class GameXmlProvider : BaseXmlProvider<Game>
{
private readonly ILogger _logger;
private readonly IProviderManager _providerManager;
public GameXmlProvider(IFileSystem fileSystem, ILogger logger)
public GameXmlProvider(IFileSystem fileSystem, ILogger logger, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<Game> result, string path, CancellationToken cancellationToken)
{
new GameXmlParser(_logger).Fetch(result, path, cancellationToken);
new GameXmlParser(_logger, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -11,16 +11,18 @@ namespace MediaBrowser.LocalMetadata.Providers
public class MovieXmlProvider : BaseXmlProvider<Movie>
{
private readonly ILogger _logger;
private readonly IProviderManager _providerManager;
public MovieXmlProvider(IFileSystem fileSystem, ILogger logger)
public MovieXmlProvider(IFileSystem fileSystem, ILogger logger, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<Movie> result, string path, CancellationToken cancellationToken)
{
new MovieXmlParser(_logger).Fetch(result, path, cancellationToken);
new MovieXmlParser(_logger, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -10,16 +10,18 @@ namespace MediaBrowser.LocalMetadata.Providers
class MusicVideoXmlProvider : BaseXmlProvider<MusicVideo>
{
private readonly ILogger _logger;
private readonly IProviderManager _providerManager;
public MusicVideoXmlProvider(IFileSystem fileSystem, ILogger logger)
public MusicVideoXmlProvider(IFileSystem fileSystem, ILogger logger, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<MusicVideo> result, string path, CancellationToken cancellationToken)
{
new MusicVideoXmlParser(_logger).Fetch(result, path, cancellationToken);
new MusicVideoXmlParser(_logger, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -10,16 +10,18 @@ namespace MediaBrowser.LocalMetadata.Providers
public class PersonXmlProvider : BaseXmlProvider<Person>
{
private readonly ILogger _logger;
private readonly IProviderManager _providerManager;
public PersonXmlProvider(IFileSystem fileSystem, ILogger logger)
public PersonXmlProvider(IFileSystem fileSystem, ILogger logger, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<Person> result, string path, CancellationToken cancellationToken)
{
new BaseItemXmlParser<Person>(_logger).Fetch(result, path, cancellationToken);
new BaseItemXmlParser<Person>(_logger, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -11,16 +11,18 @@ namespace MediaBrowser.LocalMetadata.Providers
class PlaylistXmlProvider : BaseXmlProvider<Playlist>
{
private readonly ILogger _logger;
private readonly IProviderManager _providerManager;
public PlaylistXmlProvider(IFileSystem fileSystem, ILogger logger)
public PlaylistXmlProvider(IFileSystem fileSystem, ILogger logger, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<Playlist> result, string path, CancellationToken cancellationToken)
{
new PlaylistXmlParser(_logger).Fetch(result, path, cancellationToken);
new PlaylistXmlParser(_logger, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -14,16 +14,18 @@ namespace MediaBrowser.LocalMetadata.Providers
public class SeasonXmlProvider : BaseXmlProvider<Season>, IHasOrder
{
private readonly ILogger _logger;
private readonly IProviderManager _providerManager;
public SeasonXmlProvider(IFileSystem fileSystem, ILogger logger)
public SeasonXmlProvider(IFileSystem fileSystem, ILogger logger, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<Season> result, string path, CancellationToken cancellationToken)
{
new SeasonXmlParser(_logger).Fetch(result, path, cancellationToken);
new SeasonXmlParser(_logger, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -14,16 +14,18 @@ namespace MediaBrowser.LocalMetadata.Providers
public class SeriesXmlProvider : BaseXmlProvider<Series>, IHasOrder
{
private readonly ILogger _logger;
private readonly IProviderManager _providerManager;
public SeriesXmlProvider(IFileSystem fileSystem, ILogger logger)
public SeriesXmlProvider(IFileSystem fileSystem, ILogger logger, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<Series> result, string path, CancellationToken cancellationToken)
{
new SeriesXmlParser(_logger).Fetch(result, path, cancellationToken);
new SeriesXmlParser(_logger, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -10,16 +10,18 @@ namespace MediaBrowser.LocalMetadata.Providers
class VideoXmlProvider : BaseXmlProvider<Video>
{
private readonly ILogger _logger;
private readonly IProviderManager _providerManager;
public VideoXmlProvider(IFileSystem fileSystem, ILogger logger)
public VideoXmlProvider(IFileSystem fileSystem, ILogger logger, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<Video> result, string path, CancellationToken cancellationToken)
{
new VideoXmlParser(_logger).Fetch(result, path, cancellationToken);
new VideoXmlParser(_logger, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -133,7 +133,7 @@ namespace MediaBrowser.LocalMetadata.Savers
/// <param name="xmlTagsUsed">The XML tags used.</param>
public static void Save(StringBuilder xml, string path, List<string> xmlTagsUsed, IServerConfigurationManager config, IFileSystem fileSystem)
{
if (fileSystem.FileExists(path))
if (fileSystem.FileExists(path))
{
var position = xml.ToString().LastIndexOf("</", StringComparison.OrdinalIgnoreCase);
xml.Insert(position, GetCustomTags(path, xmlTagsUsed));
@ -145,7 +145,7 @@ namespace MediaBrowser.LocalMetadata.Savers
//Add the new node to the document.
xmlDocument.InsertBefore(xmlDocument.CreateXmlDeclaration("1.0", "UTF-8", "yes"), xmlDocument.DocumentElement);
fileSystem.CreateDirectory(Path.GetDirectoryName(path));
fileSystem.CreateDirectory(Path.GetDirectoryName(path));
var wasHidden = false;
@ -445,121 +445,18 @@ namespace MediaBrowser.LocalMetadata.Savers
builder.Append("<RunningTime>" + Convert.ToInt32(timespan.TotalMinutes).ToString(UsCulture) + "</RunningTime>");
}
var imdb = item.GetProviderId(MetadataProviders.Imdb);
if (!string.IsNullOrEmpty(imdb))
if (item.ProviderIds != null)
{
builder.Append("<IMDB>" + SecurityElement.Escape(imdb) + "</IMDB>");
}
var tmdb = item.GetProviderId(MetadataProviders.Tmdb);
if (!string.IsNullOrEmpty(tmdb))
{
builder.Append("<TMDbId>" + SecurityElement.Escape(tmdb) + "</TMDbId>");
}
if (!(item is Series))
{
var tvdb = item.GetProviderId(MetadataProviders.Tvdb);
if (!string.IsNullOrEmpty(tvdb))
foreach (var providerKey in item.ProviderIds.Keys)
{
builder.Append("<TvDbId>" + SecurityElement.Escape(tvdb) + "</TvDbId>");
var providerId = item.ProviderIds[providerKey];
if (!string.IsNullOrEmpty(providerId))
{
builder.Append(string.Format("<{0}>{1}</{0}>", providerKey + "Id", SecurityElement.Escape(providerId)));
}
}
}
var externalId = item.GetProviderId(MetadataProviders.Tvcom);
if (!string.IsNullOrEmpty(externalId))
{
builder.Append("<TVcomId>" + SecurityElement.Escape(externalId) + "</TVcomId>");
}
externalId = item.GetProviderId(MetadataProviders.RottenTomatoes);
if (!string.IsNullOrEmpty(externalId))
{
builder.Append("<RottenTomatoesId>" + SecurityElement.Escape(externalId) + "</RottenTomatoesId>");
}
externalId = item.GetProviderId(MetadataProviders.Zap2It);
if (!string.IsNullOrEmpty(externalId))
{
builder.Append("<Zap2ItId>" + SecurityElement.Escape(externalId) + "</Zap2ItId>");
}
externalId = item.GetProviderId(MetadataProviders.MusicBrainzAlbum);
if (!string.IsNullOrEmpty(externalId))
{
builder.Append("<MusicBrainzAlbumId>" + SecurityElement.Escape(externalId) + "</MusicBrainzAlbumId>");
}
externalId = item.GetProviderId(MetadataProviders.MusicBrainzAlbumArtist);
if (!string.IsNullOrEmpty(externalId))
{
builder.Append("<MusicBrainzAlbumArtistId>" + SecurityElement.Escape(externalId) + "</MusicBrainzAlbumArtistId>");
}
externalId = item.GetProviderId(MetadataProviders.MusicBrainzArtist);
if (!string.IsNullOrEmpty(externalId))
{
builder.Append("<MusicBrainzArtistId>" + SecurityElement.Escape(externalId) + "</MusicBrainzArtistId>");
}
externalId = item.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup);
if (!string.IsNullOrEmpty(externalId))
{
builder.Append("<MusicBrainzReleaseGroupId>" + SecurityElement.Escape(externalId) + "</MusicBrainzReleaseGroupId>");
}
externalId = item.GetProviderId(MetadataProviders.Gamesdb);
if (!string.IsNullOrEmpty(externalId))
{
builder.Append("<GamesDbId>" + SecurityElement.Escape(externalId) + "</GamesDbId>");
}
externalId = item.GetProviderId(MetadataProviders.TmdbCollection);
if (!string.IsNullOrEmpty(externalId))
{
builder.Append("<TMDbCollectionId>" + SecurityElement.Escape(externalId) + "</TMDbCollectionId>");
}
externalId = item.GetProviderId(MetadataProviders.AudioDbArtist);
if (!string.IsNullOrEmpty(externalId))
{
builder.Append("<AudioDbArtistId>" + SecurityElement.Escape(externalId) + "</AudioDbArtistId>");
}
externalId = item.GetProviderId(MetadataProviders.AudioDbAlbum);
if (!string.IsNullOrEmpty(externalId))
{
builder.Append("<AudioDbAlbumId>" + SecurityElement.Escape(externalId) + "</AudioDbAlbumId>");
}
externalId = item.GetProviderId(MetadataProviders.TvRage);
if (!string.IsNullOrEmpty(externalId))
{
builder.Append("<TVRageId>" + SecurityElement.Escape(externalId) + "</TVRageId>");
}
externalId = item.GetProviderId(MetadataProviders.TvMaze);
if (!string.IsNullOrEmpty(externalId))
{
builder.Append("<TvMazeId>" + SecurityElement.Escape(externalId) + "</TvMazeId>");
}
var hasTagline = item as IHasTaglines;
if (hasTagline != null)
{

View File

@ -25,19 +25,22 @@ namespace MediaBrowser.XbmcMetadata.Parsers
/// The logger
/// </summary>
protected ILogger Logger { get; private set; }
protected IProviderManager ProviderManager { get; private set; }
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private readonly IConfigurationManager _config;
private Dictionary<string, string> _validProviderIds;
/// <summary>
/// Initializes a new instance of the <see cref="BaseNfoParser{T}" /> class.
/// </summary>
/// <param name="logger">The logger.</param>
/// <param name="config">The configuration.</param>
public BaseNfoParser(ILogger logger, IConfigurationManager config)
public BaseNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager)
{
Logger = logger;
_config = config;
ProviderManager = providerManager;
}
/// <summary>
@ -68,6 +71,24 @@ namespace MediaBrowser.XbmcMetadata.Parsers
ValidationType = ValidationType.None
};
_validProviderIds = _validProviderIds = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
var idInfos = ProviderManager.GetExternalIdInfos(item.Item);
foreach (var info in idInfos)
{
var id = info.Key + "Id";
if (!_validProviderIds.ContainsKey(id))
{
_validProviderIds.Add(id, info.Key);
}
}
//Additional Mappings
_validProviderIds.Add("collectionnumber", "TmdbCollection");
_validProviderIds.Add("tmdbcolid", "TmdbCollection");
_validProviderIds.Add("imdb_id", "Imdb");
Fetch(item, metadataFile, settings, cancellationToken);
}
@ -760,14 +781,6 @@ namespace MediaBrowser.XbmcMetadata.Parsers
break;
}
case "tvdbid":
var tvdbId = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(tvdbId))
{
item.SetProviderId(MetadataProviders.Tvdb, tvdbId);
}
break;
case "votes":
{
var val = reader.ReadElementContentAsString();
@ -782,127 +795,6 @@ namespace MediaBrowser.XbmcMetadata.Parsers
}
break;
}
case "musicbrainzalbumid":
{
var mbz = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(mbz))
{
item.SetProviderId(MetadataProviders.MusicBrainzAlbum, mbz);
}
break;
}
case "musicbrainzalbumartistid":
{
var mbz = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(mbz))
{
item.SetProviderId(MetadataProviders.MusicBrainzAlbumArtist, mbz);
}
break;
}
case "musicbrainzartistid":
{
var mbz = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(mbz))
{
item.SetProviderId(MetadataProviders.MusicBrainzArtist, mbz);
}
break;
}
case "musicbrainzreleasegroupid":
{
var mbz = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(mbz))
{
item.SetProviderId(MetadataProviders.MusicBrainzReleaseGroup, mbz);
}
break;
}
case "tvrageid":
{
var id = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(id))
{
item.SetProviderId(MetadataProviders.TvRage, id);
}
break;
}
case "tvmazeid":
{
var id = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(id))
{
item.SetProviderId(MetadataProviders.TvMaze, id);
}
break;
}
case "audiodbartistid":
{
var id = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(id))
{
item.SetProviderId(MetadataProviders.AudioDbArtist, id);
}
break;
}
case "audiodbalbumid":
{
var id = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(id))
{
item.SetProviderId(MetadataProviders.AudioDbAlbum, id);
}
break;
}
case "rottentomatoesid":
var rtId = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(rtId))
{
item.SetProviderId(MetadataProviders.RottenTomatoes, rtId);
}
break;
case "tmdbid":
var tmdb = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(tmdb))
{
item.SetProviderId(MetadataProviders.Tmdb, tmdb);
}
break;
case "collectionnumber":
case "tmdbcolid":
var tmdbCollection = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(tmdbCollection))
{
item.SetProviderId(MetadataProviders.TmdbCollection, tmdbCollection);
}
break;
case "tvcomid":
var TVcomId = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(TVcomId))
{
item.SetProviderId(MetadataProviders.Tvcom, TVcomId);
}
break;
case "zap2itid":
var zap2ItId = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(zap2ItId))
{
item.SetProviderId(MetadataProviders.Zap2It, zap2ItId);
}
break;
case "imdb_id":
case "imdbid":
var imDbId = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(imDbId))
{
item.SetProviderId(MetadataProviders.Imdb, imDbId);
}
break;
case "genre":
{

View File

@ -12,7 +12,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{
public class EpisodeNfoParser : BaseNfoParser<Episode>
{
public EpisodeNfoParser(ILogger logger, IConfigurationManager config) : base(logger, config)
public EpisodeNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager) : base(logger, config, providerManager)
{
}

View File

@ -10,8 +10,8 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{
class MovieNfoParser : BaseNfoParser<Video>
{
public MovieNfoParser(ILogger logger, IConfigurationManager config)
: base(logger, config)
public MovieNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager)
: base(logger, config, providerManager)
{
}

View File

@ -9,7 +9,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{
public class SeasonNfoParser : BaseNfoParser<Season>
{
public SeasonNfoParser(ILogger logger, IConfigurationManager config) : base(logger, config)
public SeasonNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager) : base(logger, config, providerManager)
{
}

View File

@ -11,7 +11,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{
public class SeriesNfoParser : BaseNfoParser<Series>
{
public SeriesNfoParser(ILogger logger, IConfigurationManager config) : base(logger, config)
public SeriesNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager) : base(logger, config, providerManager)
{
}

View File

@ -13,17 +13,19 @@ namespace MediaBrowser.XbmcMetadata.Providers
{
private readonly ILogger _logger;
private readonly IConfigurationManager _config;
private readonly IProviderManager _providerManager;
public AlbumNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config)
public AlbumNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_config = config;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<MusicAlbum> result, string path, CancellationToken cancellationToken)
{
new BaseNfoParser<MusicAlbum>(_logger, _config).Fetch(result, path, cancellationToken);
new BaseNfoParser<MusicAlbum>(_logger, _config, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -13,17 +13,19 @@ namespace MediaBrowser.XbmcMetadata.Providers
{
private readonly ILogger _logger;
private readonly IConfigurationManager _config;
private readonly IProviderManager _providerManager;
public ArtistNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config)
public ArtistNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_config = config;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<MusicArtist> result, string path, CancellationToken cancellationToken)
{
new BaseNfoParser<MusicArtist>(_logger, _config).Fetch(result, path, cancellationToken);
new BaseNfoParser<MusicArtist>(_logger, _config, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -15,12 +15,14 @@ namespace MediaBrowser.XbmcMetadata.Providers
{
private readonly ILogger _logger;
private readonly IConfigurationManager _config;
private readonly IProviderManager _providerManager;
public BaseVideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config)
public BaseVideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_config = config;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<T> result, string path, CancellationToken cancellationToken)
@ -29,7 +31,7 @@ namespace MediaBrowser.XbmcMetadata.Providers
{
Item = result.Item
};
new MovieNfoParser(_logger, _config).Fetch(tmpItem, path, cancellationToken);
new MovieNfoParser(_logger, _config, _providerManager).Fetch(tmpItem, path, cancellationToken);
result.Item = (T)tmpItem.Item;
result.People = tmpItem.People;

View File

@ -14,19 +14,21 @@ namespace MediaBrowser.XbmcMetadata.Providers
{
private readonly ILogger _logger;
private readonly IConfigurationManager _config;
private readonly IProviderManager _providerManager;
public EpisodeNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config)
public EpisodeNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_config = config;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<Episode> result, string path, CancellationToken cancellationToken)
{
var images = new List<LocalImageInfo>();
new EpisodeNfoParser(_logger, _config).Fetch(result, images, path, cancellationToken);
new EpisodeNfoParser(_logger, _config, _providerManager).Fetch(result, images, path, cancellationToken);
result.Images = images;
}

View File

@ -2,27 +2,28 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Logging;
namespace MediaBrowser.XbmcMetadata.Providers
{
public class MovieNfoProvider : BaseVideoNfoProvider<Movie>
{
public MovieNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config) : base(fileSystem, logger, config)
public MovieNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager) : base(fileSystem, logger, config, providerManager)
{
}
}
public class MusicVideoNfoProvider : BaseVideoNfoProvider<MusicVideo>
{
public MusicVideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config) : base(fileSystem, logger, config)
public MusicVideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager) : base(fileSystem, logger, config, providerManager)
{
}
}
public class VideoNfoProvider : BaseVideoNfoProvider<Video>
{
public VideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config) : base(fileSystem, logger, config)
public VideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager) : base(fileSystem, logger, config, providerManager)
{
}
}

View File

@ -13,17 +13,19 @@ namespace MediaBrowser.XbmcMetadata.Providers
{
private readonly ILogger _logger;
private readonly IConfigurationManager _config;
private readonly IProviderManager _providerManager;
public SeasonNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config)
public SeasonNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_config = config;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<Season> result, string path, CancellationToken cancellationToken)
{
new SeasonNfoParser(_logger, _config).Fetch(result, path, cancellationToken);
new SeasonNfoParser(_logger, _config, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -13,17 +13,19 @@ namespace MediaBrowser.XbmcMetadata.Providers
{
private readonly ILogger _logger;
private readonly IConfigurationManager _config;
private readonly IProviderManager _providerManager;
public SeriesNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config)
public SeriesNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_config = config;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<Series> result, string path, CancellationToken cancellationToken)
{
new SeriesNfoParser(_logger, _config).Fetch(result, path, cancellationToken);
new SeriesNfoParser(_logger, _config, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -27,8 +27,8 @@ namespace MediaBrowser.XbmcMetadata.Savers
{
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
private static readonly Dictionary<string, string> CommonTags = new[] {
private static readonly Dictionary<string, string> CommonTags = new[] {
"plot",
"customrating",
"lockdata",
@ -428,6 +428,8 @@ namespace MediaBrowser.XbmcMetadata.Savers
/// <returns>Task.</returns>
public static void AddCommonNodes(BaseItem item, XmlWriter writer, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataRepo, IFileSystem fileSystem, IServerConfigurationManager config)
{
var writtenProviderIds = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
var overview = (item.Overview ?? string.Empty)
.StripHtml()
.Replace("&quot;", "'");
@ -572,6 +574,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
if (!string.IsNullOrEmpty(rt))
{
writer.WriteElementString("rottentomatoesid", rt);
writtenProviderIds.Add(MetadataProviders.RottenTomatoes.ToString());
}
var tmdbCollection = item.GetProviderId(MetadataProviders.TmdbCollection);
@ -579,6 +582,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
if (!string.IsNullOrEmpty(tmdbCollection))
{
writer.WriteElementString("collectionnumber", tmdbCollection);
writtenProviderIds.Add(MetadataProviders.TmdbCollection.ToString());
}
var imdb = item.GetProviderId(MetadataProviders.Imdb);
@ -592,6 +596,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
{
writer.WriteElementString("imdbid", imdb);
}
writtenProviderIds.Add(MetadataProviders.Imdb.ToString());
}
// Series xml saver already saves this
@ -601,6 +606,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
if (!string.IsNullOrEmpty(tvdb))
{
writer.WriteElementString("tvdbid", tvdb);
writtenProviderIds.Add(MetadataProviders.Tvdb.ToString());
}
}
@ -608,12 +614,14 @@ namespace MediaBrowser.XbmcMetadata.Savers
if (!string.IsNullOrEmpty(tmdb))
{
writer.WriteElementString("tmdbid", tmdb);
writtenProviderIds.Add(MetadataProviders.Tmdb.ToString());
}
var tvcom = item.GetProviderId(MetadataProviders.Tvcom);
if (!string.IsNullOrEmpty(tvcom))
{
writer.WriteElementString("tvcomid", tvcom);
writtenProviderIds.Add(MetadataProviders.Tvcom.ToString());
}
if (!string.IsNullOrEmpty(item.PreferredMetadataLanguage))
@ -766,6 +774,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
if (!string.IsNullOrEmpty(externalId))
{
writer.WriteElementString("audiodbartistid", externalId);
writtenProviderIds.Add(MetadataProviders.AudioDbArtist.ToString());
}
externalId = item.GetProviderId(MetadataProviders.AudioDbAlbum);
@ -773,6 +782,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
if (!string.IsNullOrEmpty(externalId))
{
writer.WriteElementString("audiodbalbumid", externalId);
writtenProviderIds.Add(MetadataProviders.AudioDbAlbum.ToString());
}
externalId = item.GetProviderId(MetadataProviders.Zap2It);
@ -780,6 +790,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
if (!string.IsNullOrEmpty(externalId))
{
writer.WriteElementString("zap2itid", externalId);
writtenProviderIds.Add(MetadataProviders.Zap2It.ToString());
}
externalId = item.GetProviderId(MetadataProviders.MusicBrainzAlbum);
@ -787,6 +798,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
if (!string.IsNullOrEmpty(externalId))
{
writer.WriteElementString("musicbrainzalbumid", externalId);
writtenProviderIds.Add(MetadataProviders.MusicBrainzAlbum.ToString());
}
externalId = item.GetProviderId(MetadataProviders.MusicBrainzAlbumArtist);
@ -794,6 +806,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
if (!string.IsNullOrEmpty(externalId))
{
writer.WriteElementString("musicbrainzalbumartistid", externalId);
writtenProviderIds.Add(MetadataProviders.MusicBrainzAlbumArtist.ToString());
}
externalId = item.GetProviderId(MetadataProviders.MusicBrainzArtist);
@ -801,6 +814,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
if (!string.IsNullOrEmpty(externalId))
{
writer.WriteElementString("musicbrainzartistid", externalId);
writtenProviderIds.Add(MetadataProviders.MusicBrainzArtist.ToString());
}
externalId = item.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup);
@ -808,24 +822,33 @@ namespace MediaBrowser.XbmcMetadata.Savers
if (!string.IsNullOrEmpty(externalId))
{
writer.WriteElementString("musicbrainzreleasegroupid", externalId);
writtenProviderIds.Add(MetadataProviders.MusicBrainzReleaseGroup.ToString());
}
externalId = item.GetProviderId(MetadataProviders.Gamesdb);
if (!string.IsNullOrEmpty(externalId))
{
writer.WriteElementString("gamesdbid", externalId);
writtenProviderIds.Add(MetadataProviders.Gamesdb.ToString());
}
externalId = item.GetProviderId(MetadataProviders.TvRage);
if (!string.IsNullOrEmpty(externalId))
{
writer.WriteElementString("tvrageid", externalId);
writtenProviderIds.Add(MetadataProviders.TvRage.ToString());
}
externalId = item.GetProviderId(MetadataProviders.TvMaze);
if (!string.IsNullOrEmpty(externalId))
if (item.ProviderIds != null)
{
writer.WriteElementString("tvmazeid", externalId);
foreach (var providerKey in item.ProviderIds.Keys)
{
var providerId = item.ProviderIds[providerKey];
if (!string.IsNullOrEmpty(providerId) && !writtenProviderIds.Contains(providerKey))
{
writer.WriteElementString(providerKey.ToLower() + "id", providerId);
}
}
}
if (options.SaveImagePathsInNfo)

View File

@ -65,9 +65,6 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Emby.Drawing", "Emby.Drawing\Emby.Drawing.csproj", "{08FFF49B-F175-4807-A2B5-73B0EBD9F716}"
EndProject
Global
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms