Skip to content

Commit

Permalink
ArenaScansSource.cs is no more
Browse files Browse the repository at this point in the history
  • Loading branch information
Yucked committed Nov 22, 2023
1 parent 6001ed0 commit 3b81204
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 60 deletions.
16 changes: 9 additions & 7 deletions src/Handlers/DatabaseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ await collection.Indexes.CreateManyAsync([
return memoryCache.Get<T>(key);
}

public string? GetSourceIcon(string sourceId) {
return config.GetValue<bool>("Save:SourceIcon")
? Get<string>(sourceId)
: _sources.First(x => x.Id == sourceId).Icon;
public string GetSourceIcon(string sourceId) {
return (config.GetValue<bool>("Save:SourceIcon")
? Get<string>(sourceId)
: _sources.First(x => x.Id == sourceId).Icon)
?? "favicon_outline.png";
}

public Task AddMangaAsync(Manga manga) {
Expand Down Expand Up @@ -221,7 +222,7 @@ public async Task<IReadOnlyList<IGrimoireSource>> ListSourcesAsync() {
var tasks = _sources
.Select(async source => {
if (memoryCache.TryGetValue(source.Id, out _)) {
return source;
return;
}
var path = PathMaker
Expand All @@ -243,10 +244,11 @@ public async Task<IReadOnlyList<IGrimoireSource>> ListSourcesAsync() {
}
memoryCache.Set(source.Id, path.WithIcon(source.Icon));
return source;
});

return await Task.WhenAll(tasks);
await Task.WhenAll(tasks);
return _sources
.ToArray();
}

public async Task<bool> DoesSourceExistAsync(string sourceId) {
Expand Down
47 changes: 31 additions & 16 deletions src/Sources/Abstractions/HanmaAbstraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ private HanmaAbstraction(ILogger logger, HttpHandler httpHandler, string name, s
_url = url;
}

public async Task<IReadOnlyList<Manga>?> GetMangasAsync() {
public async Task<IReadOnlyList<Manga>> GetMangasAsync() {
using var document = await _httpHandler.ParseAsync($"{_url}/manga-list");
var lastPage = int.Parse(document
.QuerySelector("a.paging_prevnext.next")
.QuerySelector("a.paging_prevnext.next")!
.As<IHtmlAnchorElement>().Href[^2..]);

var urls = await Enumerable
Expand All @@ -51,7 +51,7 @@ private HanmaAbstraction(ILogger logger, HttpHandler httpHandler, string name, s
.GroupBy(x => x.Id)
.Select(x => {
if (x.Count() == 1) {
return x.FirstOrDefault();
return x.First();
}
var lst = x.ToArray();
Expand All @@ -64,16 +64,24 @@ private HanmaAbstraction(ILogger logger, HttpHandler httpHandler, string name, s
.ToArray();
}

public async Task<Manga?> GetMangaAsync(string url) {
public async Task<Manga> GetMangaAsync(string url) {
using var document = await _httpHandler.ParseAsync(url);

try {
var manga = new Manga {
Author = GetInfoValue("Author"),
Name = document.QuerySelector("span.series-name > a")?.TextContent,
Summary = document.QuerySelector("div.summary-content").TextContent.Clean(),
Cover = document.QuerySelector("div.img-in-ratio").TextContent,
Name = document
.QuerySelector("span.series-name > a")!
.TextContent,
Summary = document
.QuerySelector("div.summary-content")!
.TextContent
.Clean(),
Cover = document
.QuerySelector("div.img-in-ratio")!
.TextContent,
Genre = GetInfoValue("Genre").Split(' '),
SourceId = _name.GetIdFromName(),
Metonyms = new[] {
GetInfoValue("Other name"),
GetInfoValue("Doujinshi")
Expand All @@ -82,9 +90,15 @@ private HanmaAbstraction(ILogger logger, HttpHandler httpHandler, string name, s
.QuerySelectorAll("ul.list-chapters > a")
.Select(x => new Chapter {
Url = x.As<IHtmlAnchorElement>().Href,
Name = x.QuerySelector("div.chapter-name").TextContent,
Name = x
.QuerySelector("div.chapter-name")!
.TextContent,
ReleasedOn = DateOnly.ParseExact(
x.QuerySelector("div.chapter-time").TextContent.Split('-')[1].Trim(),
x
.QuerySelector("div.chapter-time")!
.TextContent
.Split('-')[1]
.Trim(),
"dd/MM/yyyy",
CultureInfo.InvariantCulture)
})
Expand All @@ -95,10 +109,9 @@ private HanmaAbstraction(ILogger logger, HttpHandler httpHandler, string name, s
}
catch (Exception exception) {
_logger.LogError("{}\n{}", url, exception);
throw;
}

return default;

string GetInfoValue(string infoName) {
var infoElement = document
.QuerySelectorAll("span.info-name")
Expand All @@ -109,21 +122,23 @@ string GetInfoValue(string infoName) {

return infoElement
.ParentElement
?.QuerySelector("span.info-value")
?.TextContent;
?.QuerySelector("span.info-value")!
.TextContent!;
}
}

public async Task<Chapter> FetchChapterAsync(Chapter chapter) {
using var document = await _httpHandler.ParseAsync(chapter.Url);
IElement element;
do {
element = document.All.FirstOrDefault(x => x is { LocalName: "div", Id: "chapter-content" });
} while (element == default && element.Children.Length == 0);
element = document
.All
.First(x => x is { LocalName: "div", Id: "chapter-content" });
} while (element.Children.Length == 0);

chapter.Pages = element
.Children
.Select(x => x.Attributes[1].Value)
.Select(x => x.Attributes[1]!.Value)
.ToArray();
return chapter;
}
Expand Down
37 changes: 0 additions & 37 deletions src/Sources/ArenaScansSource.cs

This file was deleted.

0 comments on commit 3b81204

Please sign in to comment.