public static TachiyomiDetails ToTachiyomiMetadata(this GalleryResult result) { var metadata = new TachiyomiDetails { Title = GetTitle(result.Title), Author = SafeJoin(result.Artists), Artist = SafeJoin(result.Artists), Description = $"Source: https://nhentai.net/g/{result.Id}", Genres = result.Tags }; return(metadata); }
public async Task DownloadAsync(GalleryResult result, string outputPath, bool pack, bool useTachiyomiFolderLayout, IProgressBar progress) { // Prepare the download. await PrepareAsync(result, outputPath, useTachiyomiFolderLayout).ConfigureAwait(false); // If the progress is null, we create a new one. var progressTheme = ProgressBarConfiguration.BarOption; var progressInitialTitle = $"[queued] id: {_taskId}"; using var bar = progress == null ? new ProgressBar(result.TotalPages, progressInitialTitle, progressTheme) : (IProgressBar)progress.Spawn(result.TotalPages, progressInitialTitle, progressTheme); using var throttler = new SemaphoreSlim(2); var taskList = new List <Task>(); foreach (var page in result.Images) { await throttler.WaitAsync().ConfigureAwait(false); var referenceBar = bar; var referenceThrottler = throttler; taskList.Add(Task.Run(async() => { await FetchImageAsync(result.MediaId, page, referenceBar).ConfigureAwait(false); referenceThrottler.Release(); })); } await Task.WhenAll(taskList).ConfigureAwait(false); if (pack) { var imageFiles = Directory.GetFiles(_destinationPath); await _packer.RunAsync(_folderName, imageFiles, $"{_destinationPath}.cbz", bar); } }
private async Task PrepareAsync(GalleryResult result, string outputPath, bool useTachiyomiFolderLayout) { _taskId = result.Id; _destinationPath = Environment.CurrentDirectory; if (!string.IsNullOrEmpty(outputPath)) { _destinationPath = outputPath; } var galleryTitle = string.IsNullOrEmpty(result.Title.Japanese) ? (string.IsNullOrEmpty(result.Title.English) ? result.Title.Pretty : result.Title.English) : result.Title.Japanese; var folderName = SantizeFolderName($"{result.Id} - {galleryTitle}"); _folderName = folderName; var mangaRootPath = Path.Join(_destinationPath, folderName); _destinationPath = useTachiyomiFolderLayout ? Path.Join(mangaRootPath, "ch1") : mangaRootPath; if (!Directory.Exists(_destinationPath)) { Directory.CreateDirectory(_destinationPath); } var metadataPath = Path.Combine(mangaRootPath, "info.txt"); await File.WriteAllTextAsync(metadataPath, result.ToReadable()) .ConfigureAwait(false); // Generate Tachiyomi details.json if (useTachiyomiFolderLayout) { var tachiyomiMetadataPath = Path.Combine(mangaRootPath, "details.json"); var tachiyomiMetadata = JsonConvert .SerializeObject(result.ToTachiyomiMetadata(), Formatting.Indented); await File.WriteAllTextAsync(tachiyomiMetadataPath, tachiyomiMetadata) .ConfigureAwait(false); } }
public static string ToReadable(this GalleryResult result) { var builder = new StringBuilder(); builder.AppendLine("Title ========================================="); builder.AppendLine($"Japanese: {result.Title.Japanese}"); builder.AppendLine($"English: {result.Title.English}"); builder.AppendLine($"Pretty: {result.Title.Pretty}"); builder.AppendLine("Tags =========================================="); builder.AppendLine($"Artists: {SafeJoin(result.Artists)}"); builder.AppendLine($"Parodies: {SafeJoin(result.Parodies)}"); builder.AppendLine($"Characters: {SafeJoin(result.Characters)}"); builder.AppendLine($"Categories: {SafeJoin(result.Categories)}"); builder.AppendLine($"Groups: {SafeJoin(result.Groups)}"); builder.AppendLine($"Tags: {SafeJoin(result.Tags)}"); builder.AppendLine($"Language: {SafeJoin(result.Languages)}"); builder.AppendLine("==============================================="); builder.AppendLine($"Total Pages: {result.TotalPages}"); builder.AppendLine($"URL: https://nhentai.net/g/{result.Id}\n"); return(builder.ToString()); }