Multiple authors resolves #7
This commit is contained in:
parent
234735a562
commit
32f89f9dce
@ -166,7 +166,7 @@ public abstract class Connector
|
|||||||
new XElement("Tags", string.Join(',',publication.tags)),
|
new XElement("Tags", string.Join(',',publication.tags)),
|
||||||
new XElement("LanguageISO", publication.originalLanguage),
|
new XElement("LanguageISO", publication.originalLanguage),
|
||||||
new XElement("Title", chapter.name),
|
new XElement("Title", chapter.name),
|
||||||
new XElement("Writer", publication.author),
|
new XElement("Writer", string.Join(',', publication.authors)),
|
||||||
new XElement("Volume", chapter.volumeNumber),
|
new XElement("Volume", chapter.volumeNumber),
|
||||||
new XElement("Number", chapter.chapterNumber)
|
new XElement("Number", chapter.chapterNumber)
|
||||||
);
|
);
|
||||||
|
@ -93,19 +93,21 @@ public class MangaDex : Connector
|
|||||||
}
|
}
|
||||||
|
|
||||||
string? posterId = null;
|
string? posterId = null;
|
||||||
string? authorId = null;
|
HashSet<string> authorIds = new();
|
||||||
if (manga.ContainsKey("relationships") && manga["relationships"] is not null)
|
if (manga.ContainsKey("relationships") && manga["relationships"] is not null)
|
||||||
{
|
{
|
||||||
JsonArray relationships = manga["relationships"]!.AsArray();
|
JsonArray relationships = manga["relationships"]!.AsArray();
|
||||||
posterId = relationships.FirstOrDefault(relationship => relationship!["type"]!.GetValue<string>() == "cover_art")!["id"]!.GetValue<string>();
|
posterId = relationships.FirstOrDefault(relationship => relationship!["type"]!.GetValue<string>() == "cover_art")!["id"]!.GetValue<string>();
|
||||||
authorId = relationships.FirstOrDefault(relationship => relationship!["type"]!.GetValue<string>() == "author")!["id"]!.GetValue<string>();
|
foreach (JsonNode node in relationships.Where(relationship =>
|
||||||
|
relationship!["type"]!.GetValue<string>() == "author"))
|
||||||
|
authorIds.Add(node!["id"]!.GetValue<string>());
|
||||||
}
|
}
|
||||||
string? coverUrl = GetCoverUrl(publicationId, posterId);
|
string? coverUrl = GetCoverUrl(publicationId, posterId);
|
||||||
string? coverCacheName = null;
|
string? coverCacheName = null;
|
||||||
if (coverUrl is not null)
|
if (coverUrl is not null)
|
||||||
coverCacheName = SaveCoverImageToCache(coverUrl, (byte)RequestType.AtHomeServer);
|
coverCacheName = SaveCoverImageToCache(coverUrl, (byte)RequestType.AtHomeServer);
|
||||||
|
|
||||||
string? author = GetAuthor(authorId);
|
List<string> authors = GetAuthors(authorIds);
|
||||||
|
|
||||||
Dictionary<string, string> linksDict = new();
|
Dictionary<string, string> linksDict = new();
|
||||||
if (attributes.ContainsKey("links") && attributes["links"] is not null)
|
if (attributes.ContainsKey("links") && attributes["links"] is not null)
|
||||||
@ -129,7 +131,7 @@ public class MangaDex : Connector
|
|||||||
|
|
||||||
Publication pub = new (
|
Publication pub = new (
|
||||||
title,
|
title,
|
||||||
author,
|
authors,
|
||||||
description,
|
description,
|
||||||
altTitlesDict,
|
altTitlesDict,
|
||||||
tags.ToArray(),
|
tags.ToArray(),
|
||||||
@ -257,21 +259,23 @@ public class MangaDex : Connector
|
|||||||
return coverUrl;
|
return coverUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string? GetAuthor(string? authorId)
|
private List<string> GetAuthors(IEnumerable<string> authorIds)
|
||||||
|
{
|
||||||
|
List<string> ret = new();
|
||||||
|
foreach (string authorId in authorIds)
|
||||||
{
|
{
|
||||||
if (authorId is null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest($"https://api.mangadex.org/author/{authorId}", (byte)RequestType.Author);
|
downloadClient.MakeRequest($"https://api.mangadex.org/author/{authorId}", (byte)RequestType.Author);
|
||||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||||
return null;
|
return ret;
|
||||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||||
if (result is null)
|
if (result is null)
|
||||||
return null;
|
return ret;
|
||||||
|
|
||||||
string author = result["data"]!["attributes"]!["name"]!.GetValue<string>();
|
string authorName = result["data"]!["attributes"]!["name"]!.GetValue<string>();
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Got author {authorId} -> {author}");
|
ret.Add(authorName);
|
||||||
return author;
|
logger?.WriteLine(this.GetType().ToString(), $"Got author {authorId} -> {authorName}");
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -71,8 +71,8 @@ public class Manganato : Connector
|
|||||||
Dictionary<string, string> altTitles = new();
|
Dictionary<string, string> altTitles = new();
|
||||||
Dictionary<string, string>? links = null;
|
Dictionary<string, string>? links = null;
|
||||||
HashSet<string> tags = new();
|
HashSet<string> tags = new();
|
||||||
string? author = null, originalLanguage = null;
|
string[] authors = Array.Empty<string>();
|
||||||
int? year = DateTime.Now.Year;
|
string originalLanguage = "";
|
||||||
|
|
||||||
HtmlNode infoNode = document.DocumentNode.Descendants("div").First(d => d.HasClass("story-info-right"));
|
HtmlNode infoNode = document.DocumentNode.Descendants("div").First(d => d.HasClass("story-info-right"));
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ public class Manganato : Connector
|
|||||||
altTitles.Add(i.ToString(), alts[i]);
|
altTitles.Add(i.ToString(), alts[i]);
|
||||||
break;
|
break;
|
||||||
case "authors":
|
case "authors":
|
||||||
author = value;
|
authors = value.Split('-');
|
||||||
break;
|
break;
|
||||||
case "status":
|
case "status":
|
||||||
status = value;
|
status = value;
|
||||||
@ -119,9 +119,9 @@ public class Manganato : Connector
|
|||||||
|
|
||||||
string yearString = document.DocumentNode.Descendants("li").Last(li => li.HasClass("a-h")).Descendants("span")
|
string yearString = document.DocumentNode.Descendants("li").Last(li => li.HasClass("a-h")).Descendants("span")
|
||||||
.First(s => s.HasClass("chapter-time")).InnerText;
|
.First(s => s.HasClass("chapter-time")).InnerText;
|
||||||
year = Convert.ToInt32(yearString.Split(',')[^1]) + 2000;
|
int year = Convert.ToInt32(yearString.Split(',')[^1]) + 2000;
|
||||||
|
|
||||||
return new Publication(sortName, author, description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
|
return new Publication(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
|
||||||
year, originalLanguage, status, publicationId);
|
year, originalLanguage, status, publicationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,10 +141,9 @@ public class Mangasee : Connector
|
|||||||
HtmlNode[] authorsNodes = attributes.Descendants("li")
|
HtmlNode[] authorsNodes = attributes.Descendants("li")
|
||||||
.First(node => node.InnerText.Contains("author(s):", StringComparison.CurrentCultureIgnoreCase))
|
.First(node => node.InnerText.Contains("author(s):", StringComparison.CurrentCultureIgnoreCase))
|
||||||
.Descendants("a").ToArray();
|
.Descendants("a").ToArray();
|
||||||
string[] authors = new string[authorsNodes.Length];
|
List<string> authors = new();
|
||||||
for (int j = 0; j < authors.Length; j++)
|
foreach(HtmlNode authorNode in authorsNodes)
|
||||||
authors[j] = authorsNodes[j].InnerText;
|
authors.Add(authorNode.InnerText);
|
||||||
string author = string.Join(" - ", authors);
|
|
||||||
|
|
||||||
HtmlNode[] genreNodes = attributes.Descendants("li")
|
HtmlNode[] genreNodes = attributes.Descendants("li")
|
||||||
.First(node => node.InnerText.Contains("genre(s):", StringComparison.CurrentCultureIgnoreCase))
|
.First(node => node.InnerText.Contains("genre(s):", StringComparison.CurrentCultureIgnoreCase))
|
||||||
@ -171,7 +170,7 @@ public class Mangasee : Connector
|
|||||||
foreach(string at in a)
|
foreach(string at in a)
|
||||||
altTitles.Add((i++).ToString(), at);
|
altTitles.Add((i++).ToString(), at);
|
||||||
|
|
||||||
return new Publication(sortName, author, description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
|
return new Publication(sortName, authors, description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
|
||||||
year, originalLanguage, status, publicationId);
|
year, originalLanguage, status, publicationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ namespace Tranga;
|
|||||||
public readonly struct Publication
|
public readonly struct Publication
|
||||||
{
|
{
|
||||||
public string sortName { get; }
|
public string sortName { get; }
|
||||||
public string? author { get; }
|
public List<string> authors { get; }
|
||||||
public Dictionary<string,string> altTitles { get; }
|
public Dictionary<string,string> altTitles { get; }
|
||||||
// ReSharper disable trice MemberCanBePrivate.Global, trust
|
// ReSharper disable trice MemberCanBePrivate.Global, trust
|
||||||
public string? description { get; }
|
public string? description { get; }
|
||||||
@ -29,10 +29,10 @@ public readonly struct Publication
|
|||||||
|
|
||||||
private static readonly Regex LegalCharacters = new Regex(@"[A-Z]*[a-z]*[0-9]* *\.*-*,*'*\'*\)*\(*~*!*");
|
private static readonly Regex LegalCharacters = new Regex(@"[A-Z]*[a-z]*[0-9]* *\.*-*,*'*\'*\)*\(*~*!*");
|
||||||
|
|
||||||
public Publication(string sortName, string? author, string? description, Dictionary<string,string> altTitles, string[] tags, string? posterUrl, string? coverFileNameInCache, Dictionary<string,string>? links, int? year, string? originalLanguage, string status, string publicationId)
|
public Publication(string sortName, List<string> authors, string? description, Dictionary<string,string> altTitles, string[] tags, string? posterUrl, string? coverFileNameInCache, Dictionary<string,string>? links, int? year, string? originalLanguage, string status, string publicationId)
|
||||||
{
|
{
|
||||||
this.sortName = sortName;
|
this.sortName = sortName;
|
||||||
this.author = author;
|
this.authors = authors;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.altTitles = altTitles;
|
this.altTitles = altTitles;
|
||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
|
Loading…
Reference in New Issue
Block a user