Skip to content

Commit

Permalink
Add enhanced support for records with letters in number
Browse files Browse the repository at this point in the history
  • Loading branch information
okolobaxa committed Jul 3, 2022
1 parent db3a11a commit 254c7c6
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
73 changes: 68 additions & 5 deletions DataParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace cgamos
Expand All @@ -19,6 +20,25 @@ internal static class DataParser
"https://cgamos.ru/inye-konfessii/lutheranism/"
};

private static readonly Dictionary<char, char> ConvertedLetters = new Dictionary<char, char>
{
// ru to en
{'а', 'a'},
{'о', 'o'},
{'с', 'c'},
{'А', 'A'},
{'О', 'O'},
{'С', 'C'},

// en to ru
{'a', 'а'},
{'o', 'о'},
{'c', 'с'},
{'A', 'А'},
{'O', 'О'},
{'C', 'С'},
};

public static async ValueTask<PageData> GetPageData(ArchiveRecord record)
{
var client = new HttpClient();
Expand Down Expand Up @@ -51,12 +71,37 @@ public static async ValueTask<PageData> GetPageData(ArchiveRecord record)

private static IReadOnlyCollection<string> GetUrlVariants(ArchiveRecord record)
{
var urlVariants = new string[]
var containtReplacement = TryGetReplacement(record.Delo, out var replacement);

string[] urlVariants;

if (containtReplacement)
{
$"{record.Fond}-{record.Opis}-{record.Delo}/",
$"{record.Fond}_{record.Opis}_{record.Delo}/",
$"{record.Fond}/{record.Fond}-{record.Opis}/{record.Fond}_{record.Opis}_{record.Delo}/"
};
var sb = new StringBuilder(record.Delo);
sb[replacement.position] = replacement.letter;
var replaced = sb.ToString();

urlVariants = new string[]
{
$"{record.Fond}-{record.Opis}-{record.Delo}/",
$"{record.Fond}_{record.Opis}_{record.Delo}/",
$"{record.Fond}/{record.Fond}-{record.Opis}/{record.Fond}_{record.Opis}_{record.Delo}/",

$"{record.Fond}-{record.Opis}-{replaced}/",
$"{record.Fond}_{record.Opis}_{replaced}/",
$"{record.Fond}/{record.Fond}-{record.Opis}/{record.Fond}_{record.Opis}_{replaced}/"
};
}
else
{
urlVariants = new string[]
{
$"{record.Fond}-{record.Opis}-{record.Delo}/",
$"{record.Fond}_{record.Opis}_{record.Delo}/",
$"{record.Fond}/{record.Fond}-{record.Opis}/{record.Fond}_{record.Opis}_{record.Delo}/"
};
}


var combinations = from directory in Directories
from urlVariant in urlVariants
Expand All @@ -65,6 +110,24 @@ from urlVariant in urlVariants
return combinations.ToArray();
}

private static bool TryGetReplacement(string str, out (int position, char letter) replacement)
{
for (int i = 0; i < str.Length; i++)
{
char ch = str[i];

if (ConvertedLetters.TryGetValue(ch, out var replacedChar))
{
replacement = (i, replacedChar);
return true;
}
}

replacement = default;

return false;
}

private static IReadOnlyCollection<string> GetPageUrls(string body)
{
var urls = new List<string>();
Expand Down
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 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
* Windows 8 и выше https://github.com/okolobaxa/cgamos-downloader/releases/download/v1.9/cgamos.1.9.win-x64.zip
* MacOS https://github.com/okolobaxa/cgamos-downloader/releases/download/v1.9/cgamos.1.9.osx-x64.tar.gz

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

Expand Down
2 changes: 1 addition & 1 deletion cgamos.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net60</TargetFramework>
<Version>1.8</Version>
<Version>1.9</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Downloader" Version="2.3.0"/>
Expand Down

0 comments on commit 254c7c6

Please sign in to comment.