Files
Arne Moerman ea58deab8c initial commit
2024-12-15 19:04:29 +01:00

59 lines
2.0 KiB
C#

namespace LetterBoxdUnwatchedGenerator
{
public class LocalMovie : IMovie
{
public string Title { get; }
public int Year { get; }
public string? Resolution { get; }
public string Directory { get; }
public LocalMovie(string title, int year, string? resolution, string directory)
{
Title = title;
Year = year;
Resolution = resolution;
Directory = directory;
}
public static LocalMovie FromDirectory(string directoryName, string directoryFullName)
{
string title;
int? year;
string? resolution;
var yearIndex = directoryName.LastIndexOf('(');
var resolutionIndex = directoryName.LastIndexOf('[');
if (yearIndex == -1)
{
year = null;
if (resolutionIndex == -1)
{
resolution = null;
title = directoryName;
}
else
{
resolution = directoryName.Substring(resolutionIndex + 1, directoryName.LastIndexOf(']') - resolutionIndex - 1);
title = directoryName[..(resolutionIndex - 1)].Trim();
}
}
else
{
if (int.TryParse(directoryName.AsSpan(yearIndex + 1, directoryName.LastIndexOf(')') - yearIndex - 1), out int yearConverted)) year = yearConverted;
else year = null;
if (resolutionIndex == -1)
{
resolution = null;
title = directoryName[..(yearIndex - 1)].Trim();
}
else
{
resolution = directoryName.Substring(resolutionIndex + 1, directoryName.LastIndexOf(']') - resolutionIndex - 1);
title = directoryName[..(yearIndex - 1)].Trim();
}
}
return new LocalMovie(title, year ?? 0, resolution, directoryFullName);
}
}
}