Compare commits
2 Commits
3938c61297
...
31a0c6ffb2
Author | SHA1 | Date | |
---|---|---|---|
31a0c6ffb2 | |||
668a3b3a96 |
@ -62,7 +62,7 @@ public class MemoryLogger : LoggerBase
|
|||||||
ret.Add(_logMessages.GetValueAtIndex(_lastLogMessageIndex + retIndex).ToString());
|
ret.Add(_logMessages.GetValueAtIndex(_lastLogMessageIndex + retIndex).ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (NullReferenceException e)//Called when LogMessage has not finished writing
|
catch (NullReferenceException)//Called when LogMessage has not finished writing
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -225,7 +225,7 @@ public abstract class MangaConnector : GlobalBase
|
|||||||
}
|
}
|
||||||
if (progressToken?.cancellationRequested ?? false)
|
if (progressToken?.cancellationRequested ?? false)
|
||||||
{
|
{
|
||||||
progressToken?.Complete();
|
progressToken.Complete();
|
||||||
return HttpStatusCode.RequestTimeout;
|
return HttpStatusCode.RequestTimeout;
|
||||||
}
|
}
|
||||||
progressToken?.Increment();
|
progressToken?.Increment();
|
||||||
|
@ -51,16 +51,23 @@ public class MangaDex : MangaConnector
|
|||||||
if (result is null)
|
if (result is null)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
total = result["total"]!.GetValue<int>(); //Update the total number of Publications
|
if(result.ContainsKey("total"))
|
||||||
|
total = result["total"]!.GetValue<int>(); //Update the total number of Publications
|
||||||
|
else continue;
|
||||||
|
|
||||||
JsonArray mangaInResult = result["data"]!.AsArray(); //Manga-data-Array
|
if (result.ContainsKey("data"))
|
||||||
//Loop each Manga and extract information from JSON
|
|
||||||
foreach (JsonNode? mangaNode in mangaInResult)
|
|
||||||
{
|
{
|
||||||
Log($"Getting publication data. {++loadedPublicationData}/{total}");
|
JsonArray mangaInResult = result["data"]!.AsArray(); //Manga-data-Array
|
||||||
Manga manga = MangaFromJsonObject((JsonObject)mangaNode);
|
//Loop each Manga and extract information from JSON
|
||||||
retManga.Add(manga); //Add Publication (Manga) to result
|
foreach (JsonNode? mangaNode in mangaInResult)
|
||||||
}
|
{
|
||||||
|
if(mangaNode is null)
|
||||||
|
continue;
|
||||||
|
Log($"Getting publication data. {++loadedPublicationData}/{total}");
|
||||||
|
if(MangaFromJsonObject((JsonObject) mangaNode) is { } manga)
|
||||||
|
retManga.Add(manga); //Add Publication (Manga) to result
|
||||||
|
}
|
||||||
|
}else continue;
|
||||||
}
|
}
|
||||||
Log($"Retrieved {retManga.Count} publications. Term=\"{publicationTitle}\"");
|
Log($"Retrieved {retManga.Count} publications. Term=\"{publicationTitle}\"");
|
||||||
return retManga.ToArray();
|
return retManga.ToArray();
|
||||||
@ -81,20 +88,30 @@ public class MangaDex : MangaConnector
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Manga MangaFromJsonObject(JsonObject manga)
|
private Manga? MangaFromJsonObject(JsonObject manga)
|
||||||
{
|
{
|
||||||
|
if (!manga.ContainsKey("attributes"))
|
||||||
|
return null;
|
||||||
JsonObject attributes = manga["attributes"]!.AsObject();
|
JsonObject attributes = manga["attributes"]!.AsObject();
|
||||||
|
|
||||||
|
if(!manga.ContainsKey("id"))
|
||||||
|
return null;
|
||||||
string publicationId = manga["id"]!.GetValue<string>();
|
string publicationId = manga["id"]!.GetValue<string>();
|
||||||
|
|
||||||
|
if(!attributes.ContainsKey("title"))
|
||||||
|
return null;
|
||||||
string title = attributes["title"]!.AsObject().ContainsKey("en") && attributes["title"]!["en"] is not null
|
string title = attributes["title"]!.AsObject().ContainsKey("en") && attributes["title"]!["en"] is not null
|
||||||
? attributes["title"]!["en"]!.GetValue<string>()
|
? attributes["title"]!["en"]!.GetValue<string>()
|
||||||
: attributes["title"]![((IDictionary<string, JsonNode?>)attributes["title"]!.AsObject()).Keys.First()]!.GetValue<string>();
|
: attributes["title"]![((IDictionary<string, JsonNode?>)attributes["title"]!.AsObject()).Keys.First()]!.GetValue<string>();
|
||||||
|
|
||||||
|
if(!attributes.ContainsKey("description"))
|
||||||
|
return null;
|
||||||
string? description = attributes["description"]!.AsObject().ContainsKey("en") && attributes["description"]!["en"] is not null
|
string? description = attributes["description"]!.AsObject().ContainsKey("en") && attributes["description"]!["en"] is not null
|
||||||
? attributes["description"]!["en"]!.GetValue<string?>()
|
? attributes["description"]!["en"]!.GetValue<string?>()
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
if(!attributes.ContainsKey("altTitles"))
|
||||||
|
return null;
|
||||||
JsonArray altTitlesObject = attributes["altTitles"]!.AsArray();
|
JsonArray altTitlesObject = attributes["altTitles"]!.AsArray();
|
||||||
Dictionary<string, string> altTitlesDict = new();
|
Dictionary<string, string> altTitlesDict = new();
|
||||||
foreach (JsonNode? altTitleNode in altTitlesObject)
|
foreach (JsonNode? altTitleNode in altTitlesObject)
|
||||||
@ -104,6 +121,8 @@ public class MangaDex : MangaConnector
|
|||||||
altTitlesDict.TryAdd(key, altTitleObject[key]!.GetValue<string>());
|
altTitlesDict.TryAdd(key, altTitleObject[key]!.GetValue<string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!attributes.ContainsKey("tags"))
|
||||||
|
return null;
|
||||||
JsonArray tagsObject = attributes["tags"]!.AsArray();
|
JsonArray tagsObject = attributes["tags"]!.AsArray();
|
||||||
HashSet<string> tags = new();
|
HashSet<string> tags = new();
|
||||||
foreach (JsonNode? tagNode in tagsObject)
|
foreach (JsonNode? tagNode in tagsObject)
|
||||||
@ -149,6 +168,8 @@ public class MangaDex : MangaConnector
|
|||||||
? attributes["originalLanguage"]!.GetValue<string?>()
|
? attributes["originalLanguage"]!.GetValue<string?>()
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
if(!attributes.ContainsKey("status"))
|
||||||
|
return null;
|
||||||
string status = attributes["status"]!.GetValue<string>();
|
string status = attributes["status"]!.GetValue<string>();
|
||||||
|
|
||||||
Manga pub = new(
|
Manga pub = new(
|
||||||
|
@ -52,7 +52,7 @@ public class Server : GlobalBase
|
|||||||
});
|
});
|
||||||
t.Start();
|
t.Start();
|
||||||
}
|
}
|
||||||
catch (HttpListenerException e)
|
catch (HttpListenerException)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user