mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Enable nullable for MediaBrowser.XbmcMetadata project (#4612)
Co-authored-by: Cody Robibero <cody@robibe.ro> Co-authored-by: Stepan <ste.martinek+git@gmail.com>
This commit is contained in:
parent
1327bd9f7d
commit
cc92f7afe5
@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<!-- ProjectGuid is only included as a requirement for SonarQube analysis -->
|
<!-- ProjectGuid is only included as a requirement for SonarQube analysis -->
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
@ -5,17 +5,32 @@ namespace MediaBrowser.Model.Providers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ExternalIdInfo
|
public class ExternalIdInfo
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the external id information for serialization to the client.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Name of the external id provider (IE: IMDB, MusicBrainz, etc).</param>
|
||||||
|
/// <param name="key">Key for this id. This key should be unique across all providers.</param>
|
||||||
|
/// <param name="type">Specific media type for this id</param>
|
||||||
|
/// <param name="urlFormatString">URL format string.</param>
|
||||||
|
public ExternalIdInfo(string name, string key, ExternalIdMediaType? type, string urlFormatString)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Key = key;
|
||||||
|
Type = type;
|
||||||
|
UrlFormatString = urlFormatString;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the display name of the external id provider (IE: IMDB, MusicBrainz, etc).
|
/// Gets or sets the display name of the external id provider (IE: IMDB, MusicBrainz, etc).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// TODO: This should be renamed to ProviderName
|
// TODO: This should be renamed to ProviderName
|
||||||
public string? Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the unique key for this id. This key should be unique across all providers.
|
/// Gets or sets the unique key for this id. This key should be unique across all providers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// TODO: This property is not actually unique across the concrete types at the moment. It should be updated to be unique.
|
// TODO: This property is not actually unique across the concrete types at the moment. It should be updated to be unique.
|
||||||
public string? Key { get; set; }
|
public string Key { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the specific media type for this id. This is used to distinguish between the different
|
/// Gets or sets the specific media type for this id. This is used to distinguish between the different
|
||||||
@ -31,6 +46,6 @@ namespace MediaBrowser.Model.Providers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the URL format string.
|
/// Gets or sets the URL format string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? UrlFormatString { get; set; }
|
public string UrlFormatString { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -960,13 +960,11 @@ namespace MediaBrowser.Providers.Manager
|
|||||||
public IEnumerable<ExternalIdInfo> GetExternalIdInfos(IHasProviderIds item)
|
public IEnumerable<ExternalIdInfo> GetExternalIdInfos(IHasProviderIds item)
|
||||||
{
|
{
|
||||||
return GetExternalIds(item)
|
return GetExternalIds(item)
|
||||||
.Select(i => new ExternalIdInfo
|
.Select(i => new ExternalIdInfo(
|
||||||
{
|
name: i.ProviderName,
|
||||||
Name = i.ProviderName,
|
key: i.Key,
|
||||||
Key = i.Key,
|
type: i.Type,
|
||||||
Type = i.Type,
|
urlFormatString: i.UrlFormatString));
|
||||||
UrlFormatString = i.UrlFormatString
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
@ -41,7 +41,7 @@ namespace MediaBrowser.XbmcMetadata
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnUserDataSaved(object sender, UserDataSaveEventArgs e)
|
private void OnUserDataSaved(object? sender, UserDataSaveEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.SaveReason == UserDataSaveReason.PlaybackFinished || e.SaveReason == UserDataSaveReason.TogglePlayed || e.SaveReason == UserDataSaveReason.UpdateUserRating)
|
if (e.SaveReason == UserDataSaveReason.PlaybackFinished || e.SaveReason == UserDataSaveReason.TogglePlayed || e.SaveReason == UserDataSaveReason.UpdateUserRating)
|
||||||
{
|
{
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<!-- Code Analyzers-->
|
<!-- Code Analyzers-->
|
||||||
|
@ -37,6 +37,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
|||||||
Logger = logger;
|
Logger = logger;
|
||||||
_config = config;
|
_config = config;
|
||||||
ProviderManager = providerManager;
|
ProviderManager = providerManager;
|
||||||
|
_validProviderIds = new Dictionary<string, string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CultureInfo UsCulture { get; } = new CultureInfo("en-US");
|
protected CultureInfo UsCulture { get; } = new CultureInfo("en-US");
|
||||||
@ -72,7 +73,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
|||||||
throw new ArgumentException("The metadata file was empty or null.", nameof(metadataFile));
|
throw new ArgumentException("The metadata file was empty or null.", nameof(metadataFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
_validProviderIds = _validProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
_validProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
var idInfos = ProviderManager.GetExternalIdInfos(item.Item);
|
var idInfos = ProviderManager.GetExternalIdInfos(item.Item);
|
||||||
|
|
||||||
@ -376,7 +377,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
|||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}).Where(i => i.HasValue).Select(i => i.Value).ToArray();
|
}).OfType<MetadataField>().ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -711,10 +712,10 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
string readerName = reader.Name;
|
string readerName = reader.Name;
|
||||||
if (_validProviderIds.TryGetValue(readerName, out string providerIdValue))
|
if (_validProviderIds.TryGetValue(readerName, out string? providerIdValue))
|
||||||
{
|
{
|
||||||
var id = reader.ReadElementContentAsString();
|
var id = reader.ReadElementContentAsString();
|
||||||
if (!string.IsNullOrWhiteSpace(id))
|
if (!string.IsNullOrWhiteSpace(providerIdValue) && !string.IsNullOrWhiteSpace(id))
|
||||||
{
|
{
|
||||||
item.SetProviderId(providerIdValue, id);
|
item.SetProviderId(providerIdValue, id);
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,8 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
|||||||
{
|
{
|
||||||
case "id":
|
case "id":
|
||||||
{
|
{
|
||||||
string imdbId = reader.GetAttribute("IMDB");
|
string? imdbId = reader.GetAttribute("IMDB");
|
||||||
string tmdbId = reader.GetAttribute("TMDB");
|
string? tmdbId = reader.GetAttribute("TMDB");
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(imdbId))
|
if (string.IsNullOrWhiteSpace(imdbId))
|
||||||
{
|
{
|
||||||
|
@ -40,9 +40,9 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
|||||||
{
|
{
|
||||||
case "id":
|
case "id":
|
||||||
{
|
{
|
||||||
string imdbId = reader.GetAttribute("IMDB");
|
string? imdbId = reader.GetAttribute("IMDB");
|
||||||
string tmdbId = reader.GetAttribute("TMDB");
|
string? tmdbId = reader.GetAttribute("TMDB");
|
||||||
string tvdbId = reader.GetAttribute("TVDB");
|
string? tvdbId = reader.GetAttribute("TVDB");
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(tvdbId))
|
if (string.IsNullOrWhiteSpace(tvdbId))
|
||||||
{
|
{
|
||||||
|
@ -74,6 +74,6 @@ namespace MediaBrowser.XbmcMetadata.Providers
|
|||||||
|
|
||||||
protected abstract void Fetch(MetadataResult<T> result, string path, CancellationToken cancellationToken);
|
protected abstract void Fetch(MetadataResult<T> result, string path, CancellationToken cancellationToken);
|
||||||
|
|
||||||
protected abstract FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService);
|
protected abstract FileSystemMetadata? GetXmlFile(ItemInfo info, IDirectoryService directoryService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ namespace MediaBrowser.XbmcMetadata.Providers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)
|
protected override FileSystemMetadata? GetXmlFile(ItemInfo info, IDirectoryService directoryService)
|
||||||
{
|
{
|
||||||
return MovieNfoSaver.GetMovieSavePaths(info)
|
return MovieNfoSaver.GetMovieSavePaths(info)
|
||||||
.Select(directoryService.GetFile)
|
.Select(directoryService.GetFile)
|
||||||
|
@ -200,7 +200,8 @@ namespace MediaBrowser.XbmcMetadata.Savers
|
|||||||
|
|
||||||
private void SaveToFile(Stream stream, string path)
|
private void SaveToFile(Stream stream, string path)
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
var directory = Path.GetDirectoryName(path) ?? throw new ArgumentException($"Provided path ({path}) is not valid.", nameof(path));
|
||||||
|
Directory.CreateDirectory(directory);
|
||||||
|
|
||||||
// On Windows, savint the file will fail if the file is hidden or readonly
|
// On Windows, savint the file will fail if the file is hidden or readonly
|
||||||
FileSystem.SetAttributes(path, false, false);
|
FileSystem.SetAttributes(path, false, false);
|
||||||
|
@ -41,7 +41,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
|
|||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override string GetLocalSavePath(BaseItem item)
|
protected override string GetLocalSavePath(BaseItem item)
|
||||||
=> GetMovieSavePaths(new ItemInfo(item)).FirstOrDefault();
|
=> GetMovieSavePaths(new ItemInfo(item)).FirstOrDefault() ?? Path.ChangeExtension(item.Path, ".nfo");
|
||||||
|
|
||||||
internal static IEnumerable<string> GetMovieSavePaths(ItemInfo item)
|
internal static IEnumerable<string> GetMovieSavePaths(ItemInfo item)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user