Skip to content

Commit

Permalink
#77 Added field releaseStatus to Manga
Browse files Browse the repository at this point in the history
  • Loading branch information
C9Glax committed Nov 1, 2023
1 parent 425cf7e commit 6adbda2
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 9 deletions.
12 changes: 11 additions & 1 deletion Tranga/Manga.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public struct Manga
public string? originalLanguage { get; }
// ReSharper disable twice MemberCanBePrivate.Global
public string status { get; }
public ReleaseStatusByte releaseStatus { get; }
public enum ReleaseStatusByte : byte
{
Continuing = 0,
Completed = 1,
OnHiatus = 2,
Cancelled = 3,
Unreleased = 4
};
public string folderName { get; private set; }
public string publicationId { get; }
public string internalId { get; }
Expand All @@ -38,7 +47,7 @@ public struct Manga
private static readonly Regex LegalCharacters = new (@"[A-Z]*[a-z]*[0-9]* *\.*-*,*'*\'*\)*\(*~*!*");

[JsonConstructor]
public Manga(string sortName, List<string> authors, string? description, Dictionary<string,string> altTitles, string[] tags, string? coverUrl, string? coverFileNameInCache, Dictionary<string,string>? links, int? year, string? originalLanguage, string status, string publicationId, string? folderName = null, float? ignoreChaptersBelow = 0)
public Manga(string sortName, List<string> authors, string? description, Dictionary<string,string> altTitles, string[] tags, string? coverUrl, string? coverFileNameInCache, Dictionary<string,string>? links, int? year, string? originalLanguage, string status, string publicationId, ReleaseStatusByte releaseStatus = 0, string? folderName = null, float? ignoreChaptersBelow = 0)
{
this.sortName = sortName;
this.authors = authors;
Expand All @@ -60,6 +69,7 @@ public Manga(string sortName, List<string> authors, string? description, Diction
this.ignoreChaptersBelow = ignoreChaptersBelow ?? 0f;
this.latestChapterDownloaded = 0;
this.latestChapterAvailable = 0;
this.releaseStatus = releaseStatus;
}

public override string ToString()
Expand Down
11 changes: 10 additions & 1 deletion Tranga/MangaConnectors/Bato.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,18 @@ private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publi

string status = document.DocumentNode.SelectSingleNode("//span[text()='Original Publication:']/..")
.ChildNodes[2].InnerText;
Manga.ReleaseStatusByte releaseStatus = Manga.ReleaseStatusByte.Unreleased;
switch (status.ToLower())
{
case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break;
case "completed": releaseStatus = Manga.ReleaseStatusByte.Completed; break;
case "hiatus": releaseStatus = Manga.ReleaseStatusByte.OnHiatus; break;
case "cancelled": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break;
case "pending": releaseStatus = Manga.ReleaseStatusByte.Unreleased; break;
}

Manga manga = new (sortName, authors, description, altTitles, tags, posterUrl, coverFileNameInCache, new Dictionary<string, string>(),
year, originalLanguage, status, publicationId);
year, originalLanguage, status, publicationId, releaseStatus);
cachedPublications.Add(manga);
return manga;
}
Expand Down
11 changes: 10 additions & 1 deletion Tranga/MangaConnectors/MangaDex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ public override Manga[] GetManga(string publicationTitle = "")
if(!attributes.ContainsKey("status"))
return null;
string status = attributes["status"]!.GetValue<string>();
Manga.ReleaseStatusByte releaseStatus = Manga.ReleaseStatusByte.Unreleased;
switch (status.ToLower())
{
case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break;
case "completed": releaseStatus = Manga.ReleaseStatusByte.Completed; break;
case "hiatus": releaseStatus = Manga.ReleaseStatusByte.OnHiatus; break;
case "cancelled": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break;
}

Manga pub = new(
title,
Expand All @@ -183,7 +191,8 @@ public override Manga[] GetManga(string publicationTitle = "")
year,
originalLanguage,
status,
publicationId
publicationId,
releaseStatus
);
cachedPublications.Add(pub);
return pub;
Expand Down
8 changes: 7 additions & 1 deletion Tranga/MangaConnectors/MangaKatana.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ private Manga ParseSinglePublicationFromHtml(Stream html, string publicationId)
HashSet<string> tags = new();
string[] authors = Array.Empty<string>();
string originalLanguage = "";
Manga.ReleaseStatusByte releaseStatus = Manga.ReleaseStatusByte.Unreleased;

HtmlNode infoNode = document.DocumentNode.SelectSingleNode("//*[@id='single_book']");
string sortName = infoNode.Descendants("h1").First(n => n.HasClass("heading")).InnerText;
Expand All @@ -110,6 +111,11 @@ private Manga ParseSinglePublicationFromHtml(Stream html, string publicationId)
break;
case "status":
status = value;
switch (status.ToLower())
{
case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break;
case "completed": releaseStatus = Manga.ReleaseStatusByte.Completed; break;
}
break;
case "genres":
tags = row.SelectNodes("div").Last().Descendants("a").Select(a => a.InnerText).ToHashSet();
Expand All @@ -136,7 +142,7 @@ private Manga ParseSinglePublicationFromHtml(Stream html, string publicationId)
}

Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
year, originalLanguage, status, publicationId);
year, originalLanguage, status, publicationId, releaseStatus);
cachedPublications.Add(manga);
return manga;
}
Expand Down
12 changes: 10 additions & 2 deletions Tranga/MangaConnectors/MangaLife.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publi
string originalLanguage = "", status = "";
Dictionary<string, string> altTitles = new(), links = new();
HashSet<string> tags = new();
Manga.ReleaseStatusByte releaseStatus = Manga.ReleaseStatusByte.Unreleased;

HtmlNode posterNode = document.DocumentNode.SelectSingleNode("//div[@class='BoxBody']//div[@class='row']//img");
string posterUrl = posterNode.GetAttributeValue("src", "");
Expand Down Expand Up @@ -104,15 +105,22 @@ private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publi
foreach (HtmlNode statusNode in statusNodes)
if (statusNode.InnerText.Contains("publish", StringComparison.CurrentCultureIgnoreCase))
status = statusNode.InnerText.Split(' ')[0];
switch (status.ToLower())
{
case "cancelled": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break;
case "hiatus": releaseStatus = Manga.ReleaseStatusByte.OnHiatus; break;
case "discontinued": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break;
case "complete": releaseStatus = Manga.ReleaseStatusByte.Completed; break;
case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break;
}

HtmlNode descriptionNode = document.DocumentNode
.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Description:']/..")
.Descendants("div").First();
string description = descriptionNode.InnerText;

Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl,
coverFileNameInCache, links,
year, originalLanguage, status, publicationId);
coverFileNameInCache, links, year, originalLanguage, status, publicationId, releaseStatus);
cachedPublications.Add(manga);
return manga;
}
Expand Down
8 changes: 7 additions & 1 deletion Tranga/MangaConnectors/Manganato.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publi
HashSet<string> tags = new();
string[] authors = Array.Empty<string>();
string originalLanguage = "";
Manga.ReleaseStatusByte releaseStatus = Manga.ReleaseStatusByte.Unreleased;

HtmlNode infoNode = document.DocumentNode.Descendants("div").First(d => d.HasClass("story-info-right"));

Expand All @@ -99,6 +100,11 @@ private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publi
break;
case "status":
status = value;
switch (status.ToLower())
{
case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break;
case "completed": releaseStatus = Manga.ReleaseStatusByte.Completed; break;
}
break;
case "genres":
string[] genres = value.Split(" - ");
Expand All @@ -122,7 +128,7 @@ private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publi
int year = Convert.ToInt32(yearString.Split(',')[^1]) + 2000;

Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
year, originalLanguage, status, publicationId);
year, originalLanguage, status, publicationId, releaseStatus);
cachedPublications.Add(manga);
return manga;
}
Expand Down
11 changes: 10 additions & 1 deletion Tranga/MangaConnectors/Mangasee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publi
string originalLanguage = "", status = "";
Dictionary<string, string> altTitles = new(), links = new();
HashSet<string> tags = new();
Manga.ReleaseStatusByte releaseStatus = Manga.ReleaseStatusByte.Unreleased;

HtmlNode posterNode = document.DocumentNode.SelectSingleNode("//div[@class='BoxBody']//div[@class='row']//img");
string posterUrl = posterNode.GetAttributeValue("src", "");
Expand Down Expand Up @@ -159,6 +160,14 @@ private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publi
foreach (HtmlNode statusNode in statusNodes)
if (statusNode.InnerText.Contains("publish", StringComparison.CurrentCultureIgnoreCase))
status = statusNode.InnerText.Split(' ')[0];
switch (status.ToLower())
{
case "cancelled": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break;
case "hiatus": releaseStatus = Manga.ReleaseStatusByte.OnHiatus; break;
case "discontinued": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break;
case "complete": releaseStatus = Manga.ReleaseStatusByte.Completed; break;
case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break;
}

HtmlNode descriptionNode = document.DocumentNode
.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Description:']/..")
Expand All @@ -167,7 +176,7 @@ private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publi

Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl,
coverFileNameInCache, links,
year, originalLanguage, status, publicationId);
year, originalLanguage, status, publicationId, releaseStatus);
cachedPublications.Add(manga);
return manga;
}
Expand Down
12 changes: 11 additions & 1 deletion Tranga/MangaConnectors/Mangaworld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publi
Dictionary<string, string> altTitles = new();
Dictionary<string, string>? links = null;
string originalLanguage = "";
Manga.ReleaseStatusByte releaseStatus = Manga.ReleaseStatusByte.Unreleased;

HtmlNode infoNode = document.DocumentNode.Descendants("div").First(d => d.HasClass("info"));

Expand All @@ -94,6 +95,15 @@ private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publi
string[] authors = new[] { authorsNode.SelectNodes("a").First().InnerText };

string status = metadata.SelectSingleNode("//span[text()='Stato: ']/..").SelectNodes("a").First().InnerText;
// ReSharper disable 5 times StringLiteralTypo
switch (status.ToLower())
{
case "cancellato": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break;
case "in pausa": releaseStatus = Manga.ReleaseStatusByte.OnHiatus; break;
case "droppato": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break;
case "finito": releaseStatus = Manga.ReleaseStatusByte.Completed; break;
case "in corso": releaseStatus = Manga.ReleaseStatusByte.Continuing; break;
}

string posterUrl = document.DocumentNode.SelectSingleNode("//img[@class='rounded']").GetAttributeValue("src", "");

Expand All @@ -105,7 +115,7 @@ private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publi
int year = Convert.ToInt32(yearString);

Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
year, originalLanguage, status, publicationId);
year, originalLanguage, status, publicationId, releaseStatus);
cachedPublications.Add(manga);
return manga;
}
Expand Down

0 comments on commit 6adbda2

Please sign in to comment.