forked from kc3hack/2024_H
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#1-2 ScraperSelectorを追加
- Loading branch information
Showing
12 changed files
with
178 additions
and
128 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
Epub/KoeBook.Epub/Contracts/Services/IFileExtensionService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace KoeBook.Epub.Contracts.Services; | ||
|
||
public interface IFileExtensionService | ||
{ | ||
public string GetImagesMediaType(string fileName); | ||
} |
11 changes: 11 additions & 0 deletions
11
Epub/KoeBook.Epub/Contracts/Services/IScraperSelectorService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using KoeBook.Epub.Models; | ||
|
||
namespace KoeBook.Epub.Contracts.Services; | ||
|
||
/// <summary> | ||
/// スクレイピングを行い、EpubDocumentを作成します。 | ||
/// </summary> | ||
public interface IScraperSelectorService | ||
{ | ||
public ValueTask<EpubDocument> ScrapingAsync(string url, string coverFillePath, string tempDirectory, Guid id, CancellationToken ct); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using KoeBook.Epub.Contracts.Services; | ||
|
||
namespace KoeBook.Epub.Services; | ||
|
||
public class FileExtensionService : IFileExtensionService | ||
{ | ||
public string GetImagesMediaType(string fileName) | ||
{ | ||
return Path.GetExtension(fileName) switch | ||
{ | ||
".gif" => "image/gif", | ||
".jpg" or ".jpeg" => "image/jpeg", | ||
".png" => "image/png", | ||
".svg" => "image/svg+xml", | ||
".webp" => "image/webp", | ||
_ => string.Empty, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Collections.Immutable; | ||
using KoeBook.Epub.Contracts.Services; | ||
using KoeBook.Epub.Models; | ||
|
||
namespace KoeBook.Epub.Services; | ||
|
||
public class ScraperSelectorService(IEnumerable<IScrapingService> scrapingServices) : IScraperSelectorService | ||
{ | ||
private readonly ImmutableArray<IScrapingService> _scrapingServices = scrapingServices.ToImmutableArray(); | ||
|
||
public async ValueTask<EpubDocument> ScrapingAsync(string url, string coverFillePath, string tempDirectory, Guid id, CancellationToken ct) | ||
{ | ||
var uri = new Uri(url); | ||
|
||
foreach (var service in _scrapingServices) | ||
{ | ||
if (service.IsMatchSite(uri)) | ||
return await service.ScrapingAsync(url, coverFillePath, tempDirectory, id, ct); | ||
} | ||
|
||
throw new ArgumentException("対応するURLではありません"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.