Skip to content

Commit

Permalink
Merge branch 'okolobaxa:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxxxxbox authored Feb 7, 2022
2 parents f68e1d5 + db3a11a commit a60a6eb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
14 changes: 4 additions & 10 deletions DataParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,9 @@ public static async ValueTask<PageData> GetPageData(ArchiveRecord record)
{
var body = await client.GetStringAsync(urlVariant);

var pageCount = GetPageCount(body);
if (pageCount == 0)
{
continue;
}
var pageUrls = GetPageUrls(body);

var pageUrls = GetPageUrls(body, pageCount);

return new PageData(pageUrls.ToArray(), pageCount, urlVariant);
return new PageData(pageUrls, pageUrls.Count, urlVariant);
}
catch (HttpRequestException)
{
Expand Down Expand Up @@ -71,9 +65,9 @@ from urlVariant in urlVariants
return combinations.ToArray();
}

private static IReadOnlyCollection<string> GetPageUrls(string body, int pageCount)
private static IReadOnlyCollection<string> GetPageUrls(string body)
{
var urls = new List<string>(pageCount);
var urls = new List<string>();
const string token = "data-original=\"";

var position = 0;
Expand Down
10 changes: 6 additions & 4 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Threading.Tasks;
Expand Down Expand Up @@ -135,7 +137,7 @@ record = record with { End = pageData.PageCount };
{
for (int i = record.Start; i <= record.End; i++)
{
var url = $"https://cgamos.ru{pageData.PageUrls[i - 1]}";
var url = $"https://cgamos.ru{pageData.PageUrls.ElementAt(i - 1)}";

var pbar = mainProgressBar.Spawn(100, $"Скачивание {url}", progressBarOptions);

Expand Down Expand Up @@ -178,11 +180,11 @@ private static string GetFileName(string url)
// '/images/MB_LS/01-0203-0745-000184/00000004.jpg' -> '0004.jpg'
var index = url.LastIndexOf('/');

return url.Substring(index + 5).Replace(".JPG", ".jpg");
return url.Substring(index + 5).ToLowerInvariant();
}
}

internal record ArchiveRecord(string Fond, string Opis, string Delo, short Start = 1, short? End = null);
internal record ArchiveRecord(string Fond, string Opis, string Delo, int Start = 1, int? End = null);

internal record PageData(string[] PageUrls, short PageCount, string PageMainUrl);
internal record PageData(IReadOnlyCollection<string> PageUrls, int PageCount, string PageMainUrl);
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

### Запуск
Скачиваем программу
* Windows https://github.com/okolobaxa/cgamos-downloader/releases/download/v1.7/cgamos-windows.zip
* MacOS https://github.com/okolobaxa/cgamos-downloader/releases/download/v1.7/cgamos-macos.zip
* Windows 8 и выше https://github.com/okolobaxa/cgamos-downloader/releases/download/v1.8/cgamos.1.8.win-x64.zip
* MacOS https://github.com/okolobaxa/cgamos-downloader/releases/download/v1.8/cgamos.1.8.osx-x64.tar.gz

Запустите файл cgamos и следуйте инструкциям.

Expand Down

0 comments on commit a60a6eb

Please sign in to comment.