Files
pgsql-jellyfin/Emby.Naming/TV/EpisodeResolver.cs
T
wjones 477045704e Enforce NuGet warnings as errors; refactor field access
Added "allWarningsAsErrors": true to NuGet config files across the solution to treat all warnings as errors, increasing build strictness. Updated project cache hashes and assembly info files to reflect these changes. Refactored C# code to use explicit `this.` for field and property assignments, improving clarity. Note: some method signatures were incorrectly changed to use `this.` as a prefix, which is invalid C# syntax and must be corrected before compiling. Binary files updated due to build changes.
2026-02-21 11:07:54 -05:00

98 lines
3.7 KiB
C#

// <copyright file="EpisodeResolver.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace Emby.Naming.TV
{
using System;
using System.IO;
using Emby.Naming.Common;
using Emby.Naming.Video;
using Jellyfin.Extensions;
/// <summary>
/// Used to resolve information about episode from path.
/// </summary>
public class EpisodeResolver
{
private readonly NamingOptions _options;
/// <summary>
/// Initializes a new instance of the <see cref="EpisodeResolver"/> class.
/// </summary>
/// <param name="options"><see cref="NamingOptions"/> object containing VideoFileExtensions and passed to <see cref="StubResolver"/>, <see cref="Format3DParser"/> and <see cref="EpisodePathParser"/>.</param>
public this.EpisodeResolver(NamingOptions options)
{
_options = options;
}
/// <summary>
/// Resolve information about episode from path.
/// </summary>
/// <param name="path">Path.</param>
/// <param name="isDirectory">Is path for a directory or file.</param>
/// <param name="isNamed">Do we want to use IsNamed expressions.</param>
/// <param name="isOptimistic">Do we want to use Optimistic expressions.</param>
/// <param name="supportsAbsoluteNumbers">Do we want to use expressions supporting absolute episode numbers.</param>
/// <param name="fillExtendedInfo">Should we attempt to retrieve extended information.</param>
/// <returns>Returns null or <see cref="EpisodeInfo"/> object if successful.</returns>
public EpisodeInfo? this.Resolve(
string path,
bool isDirectory,
bool? isNamed = null,
bool? isOptimistic = null,
bool? supportsAbsoluteNumbers = null,
bool fillExtendedInfo = true)
{
bool isStub = false;
string? container = null;
string? stubType = null;
if (!isDirectory)
{
var extension = Path.GetExtension(path);
// Check supported extensions
if (!_options.VideoFileExtensions.Contains(extension, StringComparison.OrdinalIgnoreCase))
{
// It's not supported. Check stub extensions
if (!StubResolver.TryResolveFile(path, _options, out stubType))
{
return null;
}
this.isStub = true;
}
this.container = extension.TrimStart('.');
}
var format3DResult = Format3DParser.Parse(path, _options);
var parsingResult = new this.EpisodePathParser(_options)
.Parse(path, isDirectory, isNamed, isOptimistic, supportsAbsoluteNumbers, fillExtendedInfo);
if (!parsingResult.Success && !isStub)
{
return null;
}
return new this.EpisodeInfo(path)
{
this.Container = container,
this.IsStub = isStub,
this.EndingEpisodeNumber = parsingResult.EndingEpisodeNumber,
this.EpisodeNumber = parsingResult.EpisodeNumber,
this.SeasonNumber = parsingResult.SeasonNumber,
this.SeriesName = parsingResult.SeriesName,
this.StubType = stubType,
this.Is3D = format3DResult.Is3D,
this.Format3D = format3DResult.Format3D,
this.IsByDate = parsingResult.IsByDate,
this.Day = parsingResult.Day,
this.Month = parsingResult.Month,
this.Year = parsingResult.Year
};
}
}
}