using System;
using System.Linq;
using API.Entities.Enums;
using Kavita.Common.Extensions;
namespace API.Data.Metadata
{
///
/// A representation of a ComicInfo.xml file
///
/// See reference of the loose spec here: https://anansi-project.github.io/docs/comicinfo/documentation
public class ComicInfo
{
public string Summary { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public string Series { get; set; } = string.Empty;
///
/// Localized Series name. Not standard.
///
public string LocalizedSeries { get; set; } = string.Empty;
public string SeriesSort { get; set; } = string.Empty;
public string Number { get; set; } = string.Empty;
///
/// The total number of items in the series.
///
public int Count { get; set; } = 0;
public string Volume { get; set; } = string.Empty;
public string Notes { get; set; } = string.Empty;
public string Genre { get; set; } = string.Empty;
public int PageCount { get; set; }
// ReSharper disable once InconsistentNaming
///
/// IETF BCP 47 Code to represent the language of the content
///
public string LanguageISO { get; set; } = string.Empty;
///
/// This is the link to where the data was scraped from
///
public string Web { get; set; } = string.Empty;
public int Day { get; set; } = 0;
public int Month { get; set; } = 0;
public int Year { get; set; } = 0;
///
/// Rating based on the content. Think PG-13, R for movies. See for valid types
///
public string AgeRating { get; set; } = string.Empty;
///
/// User's rating of the content
///
public float UserRating { get; set; }
public string StoryArc { get; set; } = string.Empty;
public string SeriesGroup { get; set; } = string.Empty;
public string AlternateNumber { get; set; } = string.Empty;
public int AlternateCount { get; set; } = 0;
public string AlternateSeries { get; set; } = string.Empty;
///
/// This is Epub only: calibre:title_sort
/// Represents the sort order for the title
///
public string TitleSort { get; set; } = string.Empty;
///
/// The translator, can be comma separated. This is part of ComicInfo.xml draft v2.1
///
/// See https://github.com/anansi-project/comicinfo/issues/2 for information about this tag
public string Translator { get; set; } = string.Empty;
///
/// Misc tags. This is part of ComicInfo.xml draft v2.1
///
/// See https://github.com/anansi-project/comicinfo/issues/1 for information about this tag
public string Tags { get; set; } = string.Empty;
///
/// This is the Author. For Books, we map creator tag in OPF to this field. Comma separated if multiple.
///
public string Writer { get; set; } = string.Empty;
public string Penciller { get; set; } = string.Empty;
public string Inker { get; set; } = string.Empty;
public string Colorist { get; set; } = string.Empty;
public string Letterer { get; set; } = string.Empty;
public string CoverArtist { get; set; } = string.Empty;
public string Editor { get; set; } = string.Empty;
public string Publisher { get; set; } = string.Empty;
public string Characters { get; set; } = string.Empty;
public static AgeRating ConvertAgeRatingToEnum(string value)
{
if (string.IsNullOrEmpty(value)) return Entities.Enums.AgeRating.Unknown;
return Enum.GetValues()
.SingleOrDefault(t => t.ToDescription().ToUpperInvariant().Equals(value.ToUpperInvariant()), Entities.Enums.AgeRating.Unknown);
}
public static void CleanComicInfo(ComicInfo info)
{
if (info == null) return;
info.Series = info.Series.Trim();
info.SeriesSort = info.SeriesSort.Trim();
info.LocalizedSeries = info.LocalizedSeries.Trim();
info.Writer = Parser.Parser.CleanAuthor(info.Writer);
info.Colorist = Parser.Parser.CleanAuthor(info.Colorist);
info.Editor = Parser.Parser.CleanAuthor(info.Editor);
info.Inker = Parser.Parser.CleanAuthor(info.Inker);
info.Letterer = Parser.Parser.CleanAuthor(info.Letterer);
info.Penciller = Parser.Parser.CleanAuthor(info.Penciller);
info.Publisher = Parser.Parser.CleanAuthor(info.Publisher);
info.Characters = Parser.Parser.CleanAuthor(info.Characters);
info.Translator = Parser.Parser.CleanAuthor(info.Translator);
info.CoverArtist = Parser.Parser.CleanAuthor(info.CoverArtist);
}
}
}