Hack to resolve #60 Website-URL.
Field will have same name, just acquisition will be better.
This commit is contained in:
parent
f729c44f88
commit
5bdbd9e2e4
@ -43,11 +43,13 @@ public struct Manga
|
||||
public float ignoreChaptersBelow { get; set; }
|
||||
public float latestChapterDownloaded { get; set; }
|
||||
public float latestChapterAvailable { get; set; }
|
||||
|
||||
public string websiteUrl { get; private set; }
|
||||
|
||||
private static readonly Regex LegalCharacters = new (@"[A-Za-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, ReleaseStatusByte releaseStatus = 0, string? websiteUrl = null, 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 publicationId, ReleaseStatusByte releaseStatus, string? websiteUrl, string? folderName = null, float? ignoreChaptersBelow = 0)
|
||||
{
|
||||
this.sortName = sortName;
|
||||
this.authors = authors;
|
||||
@ -59,7 +61,6 @@ public struct Manga
|
||||
this.links = links ?? new Dictionary<string, string>();
|
||||
this.year = year;
|
||||
this.originalLanguage = originalLanguage;
|
||||
this.status = status;
|
||||
this.publicationId = publicationId;
|
||||
this.folderName = folderName ?? string.Concat(LegalCharacters.Matches(sortName));
|
||||
while (this.folderName.EndsWith('.'))
|
||||
@ -70,6 +71,7 @@ public struct Manga
|
||||
this.latestChapterDownloaded = 0;
|
||||
this.latestChapterAvailable = 0;
|
||||
this.releaseStatus = releaseStatus;
|
||||
this.websiteUrl = websiteUrl;
|
||||
}
|
||||
|
||||
public void UpdateMetadata(Manga newManga)
|
||||
@ -171,38 +173,22 @@ public struct Manga
|
||||
[JsonRequired]public string year { get; }
|
||||
[JsonRequired]public string status { get; }
|
||||
[JsonRequired]public string description_text { get; }
|
||||
[JsonIgnore] public static string[] continuing = new[]
|
||||
{
|
||||
"ongoing",
|
||||
"hiatus",
|
||||
"in corso",
|
||||
"in pausa"
|
||||
};
|
||||
[JsonIgnore] public static string[] ended = new[]
|
||||
{
|
||||
"completed",
|
||||
"cancelled",
|
||||
"discontinued",
|
||||
"finito",
|
||||
"cancellato",
|
||||
"droppato"
|
||||
};
|
||||
|
||||
public Metadata(Manga manga) : this(manga.sortName, manga.year.ToString() ?? string.Empty, manga.status, manga.description ?? "")
|
||||
public Metadata(Manga manga) : this(manga.sortName, manga.year.ToString() ?? string.Empty, manga.releaseStatus, manga.description ?? "")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Metadata(string name, string year, string status, string description_text)
|
||||
public Metadata(string name, string year, ReleaseStatusByte status, string description_text)
|
||||
{
|
||||
this.name = name;
|
||||
this.year = year;
|
||||
if(continuing.Contains(status.ToLower()))
|
||||
this.status = "Continuing";
|
||||
else if(ended.Contains(status.ToLower()))
|
||||
this.status = "Ended";
|
||||
else
|
||||
this.status = status;
|
||||
this.status = status switch
|
||||
{
|
||||
ReleaseStatusByte.Continuing => "Continuing",
|
||||
ReleaseStatusByte.Completed => "Ended",
|
||||
_ => Enum.GetName(status) ?? "Ended"
|
||||
};
|
||||
this.description_text = description_text;
|
||||
|
||||
//kill it with fire, but otherwise Komga will not parse
|
||||
|
@ -49,7 +49,7 @@ public class Bato : MangaConnector
|
||||
Log($"Failed to retrieve site");
|
||||
return null;
|
||||
}
|
||||
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, url.Split('/')[^1]);
|
||||
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, url.Split('/')[^1], url);
|
||||
}
|
||||
|
||||
private Manga[] ParsePublicationsFromHtml(HtmlDocument document)
|
||||
@ -72,7 +72,7 @@ public class Bato : MangaConnector
|
||||
return ret.ToArray();
|
||||
}
|
||||
|
||||
private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId)
|
||||
private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl)
|
||||
{
|
||||
HtmlNode infoNode = document.DocumentNode.SelectSingleNode("/html/body/div/main/div[1]/div[2]");
|
||||
|
||||
@ -115,7 +115,7 @@ public class Bato : MangaConnector
|
||||
}
|
||||
|
||||
Manga manga = new (sortName, authors, description, altTitles, tags, posterUrl, coverFileNameInCache, new Dictionary<string, string>(),
|
||||
year, originalLanguage, status, publicationId, releaseStatus);
|
||||
year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
|
||||
cachedPublications.Add(manga);
|
||||
return manga;
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ public class MangaDex : MangaConnector
|
||||
|
||||
Dictionary<string, string> linksDict = new();
|
||||
if (attributes.TryGetPropertyValue("links", out JsonNode? linksNode))
|
||||
foreach (KeyValuePair<string, JsonNode> linkKv in linksNode!.AsObject())
|
||||
foreach (KeyValuePair<string, JsonNode?> linkKv in linksNode!.AsObject())
|
||||
linksDict.TryAdd(linkKv.Key, linkKv.Value.GetValue<string>());
|
||||
|
||||
string? originalLanguage =
|
||||
@ -183,9 +183,9 @@ public class MangaDex : MangaConnector
|
||||
linksDict,
|
||||
year,
|
||||
originalLanguage,
|
||||
Enum.GetName(status) ?? "",
|
||||
publicationId,
|
||||
status
|
||||
status,
|
||||
websiteUrl: $"https://mangadex.org/title/{publicationId}"
|
||||
);
|
||||
cachedPublications.Add(pub);
|
||||
return pub;
|
||||
|
@ -28,7 +28,7 @@ public class MangaKatana : MangaConnector
|
||||
&& requestResult.redirectedToUrl is not null
|
||||
&& requestResult.redirectedToUrl.Contains("mangakatana.com/manga"))
|
||||
{
|
||||
return new [] { ParseSinglePublicationFromHtml(requestResult.result, requestResult.redirectedToUrl.Split('/')[^1]) };
|
||||
return new [] { ParseSinglePublicationFromHtml(requestResult.result, requestResult.redirectedToUrl.Split('/')[^1], requestResult.redirectedToUrl) };
|
||||
}
|
||||
|
||||
Manga[] publications = ParsePublicationsFromHtml(requestResult.result);
|
||||
@ -47,7 +47,7 @@ public class MangaKatana : MangaConnector
|
||||
downloadClient.MakeRequest(url, RequestType.MangaInfo);
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return null;
|
||||
return ParseSinglePublicationFromHtml(requestResult.result, url.Split('/')[^1]);
|
||||
return ParseSinglePublicationFromHtml(requestResult.result, url.Split('/')[^1], url);
|
||||
}
|
||||
|
||||
private Manga[] ParsePublicationsFromHtml(Stream html)
|
||||
@ -77,13 +77,12 @@ public class MangaKatana : MangaConnector
|
||||
return ret.ToArray();
|
||||
}
|
||||
|
||||
private Manga ParseSinglePublicationFromHtml(Stream html, string publicationId)
|
||||
private Manga ParseSinglePublicationFromHtml(Stream html, string publicationId, string websiteUrl)
|
||||
{
|
||||
StreamReader reader = new(html);
|
||||
string htmlString = reader.ReadToEnd();
|
||||
HtmlDocument document = new();
|
||||
document.LoadHtml(htmlString);
|
||||
string status = "";
|
||||
Dictionary<string, string> altTitles = new();
|
||||
Dictionary<string, string>? links = null;
|
||||
HashSet<string> tags = new();
|
||||
@ -112,8 +111,7 @@ public class MangaKatana : MangaConnector
|
||||
authors = value.Split(',');
|
||||
break;
|
||||
case "status":
|
||||
status = value;
|
||||
switch (status.ToLower())
|
||||
switch (value.ToLower())
|
||||
{
|
||||
case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break;
|
||||
case "completed": releaseStatus = Manga.ReleaseStatusByte.Completed; break;
|
||||
@ -144,7 +142,7 @@ public class MangaKatana : MangaConnector
|
||||
}
|
||||
|
||||
Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
|
||||
year, originalLanguage, status, publicationId, releaseStatus);
|
||||
year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
|
||||
cachedPublications.Add(manga);
|
||||
return manga;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class MangaLife : MangaConnector
|
||||
|
||||
RequestResult requestResult = this.downloadClient.MakeRequest(url, RequestType.MangaInfo);
|
||||
if(requestResult.htmlDocument is not null)
|
||||
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, publicationId);
|
||||
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, publicationId, url);
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ public class MangaLife : MangaConnector
|
||||
}
|
||||
|
||||
|
||||
private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId)
|
||||
private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl)
|
||||
{
|
||||
string originalLanguage = "", status = "";
|
||||
Dictionary<string, string> altTitles = new(), links = new();
|
||||
@ -122,7 +122,7 @@ public class MangaLife : MangaConnector
|
||||
string description = descriptionNode.InnerText;
|
||||
|
||||
Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl,
|
||||
coverFileNameInCache, links, year, originalLanguage, status, publicationId, releaseStatus);
|
||||
coverFileNameInCache, links, year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
|
||||
cachedPublications.Add(manga);
|
||||
return manga;
|
||||
}
|
||||
|
@ -65,12 +65,11 @@ public class Manganato : MangaConnector
|
||||
|
||||
if (requestResult.htmlDocument is null)
|
||||
return null;
|
||||
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, url.Split('/')[^1]);
|
||||
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, url.Split('/')[^1], url);
|
||||
}
|
||||
|
||||
private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId)
|
||||
private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl)
|
||||
{
|
||||
string status = "";
|
||||
Dictionary<string, string> altTitles = new();
|
||||
Dictionary<string, string>? links = null;
|
||||
HashSet<string> tags = new();
|
||||
@ -101,8 +100,7 @@ public class Manganato : MangaConnector
|
||||
authors = value.Split('-');
|
||||
break;
|
||||
case "status":
|
||||
status = value;
|
||||
switch (status.ToLower())
|
||||
switch (value.ToLower())
|
||||
{
|
||||
case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break;
|
||||
case "completed": releaseStatus = Manga.ReleaseStatusByte.Completed; break;
|
||||
@ -130,7 +128,7 @@ public class Manganato : MangaConnector
|
||||
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, releaseStatus);
|
||||
year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
|
||||
cachedPublications.Add(manga);
|
||||
return manga;
|
||||
}
|
||||
|
@ -120,11 +120,11 @@ public class Mangasee : MangaConnector
|
||||
|
||||
RequestResult requestResult = this.downloadClient.MakeRequest(url, RequestType.MangaInfo);
|
||||
if((int)requestResult.statusCode < 300 && (int)requestResult.statusCode >= 200 && requestResult.htmlDocument is not null)
|
||||
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, publicationId);
|
||||
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, publicationId, url);
|
||||
return null;
|
||||
}
|
||||
|
||||
private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId)
|
||||
private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl)
|
||||
{
|
||||
string originalLanguage = "", status = "";
|
||||
Dictionary<string, string> altTitles = new(), links = new();
|
||||
@ -178,7 +178,7 @@ public class Mangasee : MangaConnector
|
||||
|
||||
Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl,
|
||||
coverFileNameInCache, links,
|
||||
year, originalLanguage, status, publicationId, releaseStatus);
|
||||
year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
|
||||
cachedPublications.Add(manga);
|
||||
return manga;
|
||||
}
|
||||
|
@ -68,10 +68,10 @@ public class Mangaworld: MangaConnector
|
||||
|
||||
Regex idRex = new (@"https:\/\/www\.mangaworld\.[a-z]{0,63}\/manga\/([0-9]+\/[0-9A-z\-]+).*");
|
||||
string id = idRex.Match(url).Groups[1].Value;
|
||||
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, id);
|
||||
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, id, url);
|
||||
}
|
||||
|
||||
private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId)
|
||||
private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl)
|
||||
{
|
||||
Dictionary<string, string> altTitles = new();
|
||||
Dictionary<string, string>? links = null;
|
||||
@ -119,7 +119,7 @@ public class Mangaworld: MangaConnector
|
||||
int year = Convert.ToInt32(yearString);
|
||||
|
||||
Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
|
||||
year, originalLanguage, status, publicationId, releaseStatus);
|
||||
year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
|
||||
cachedPublications.Add(manga);
|
||||
return manga;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user