Skip to content

Commit 9a19a0e

Browse files
authored
Merge pull request #205 from AlexCSDev/release_26
Release 26
2 parents d201951 + 91660c0 commit 9a19a0e

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

PatreonDownloader.App/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929
// Build Number
3030
// Revision
3131
//
32-
[assembly: AssemblyVersion("25.0.0.0")]
33-
[assembly: AssemblyFileVersion("25.0.0.0")]
32+
[assembly: AssemblyVersion("26.0.0.0")]
33+
[assembly: AssemblyFileVersion("26.0.0.0")]

PatreonDownloader.Implementation/Models/PatreonDownloaderSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public record PatreonDownloaderSettings : UniversalDownloaderPlatformSettings, I
5050
public bool IsUseLegacyFilenaming { get; init; }
5151

5252
public string LoginPageAddress { get { return "https://www.patreon.com/login"; } }
53-
public string LoginCheckAddress { get { return "https://www.patreon.com/api/current_user"; } }
53+
public string LoginCheckAddress { get { return "https://www.patreon.com/api/badges?json-api-version=1.0&include=[]"; } }
5454
public string CaptchaCookieRetrievalAddress { get { return "https://www.patreon.com/home"; } }
5555
public Uri RemoteBrowserAddress { get; init; }
5656
public bool IsHeadlessBrowser { get; init; }

PatreonDownloader.Implementation/PatreonCrawlTargetInfoRetriever.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private async Task<long> GetCampaignId(string url)
3535
{
3636
string pageHtml = await _webDownloader.DownloadString(url);
3737

38-
Regex regex = new Regex("\"self\": \"https:\\/\\/www\\.patreon\\.com\\/api\\/campaigns\\/(\\d+)\"");
38+
Regex regex = new Regex("\"self\": ?\"https:\\/\\/www\\.patreon\\.com\\/api\\/campaigns\\/(\\d+)\"");
3939
Match match = regex.Match(pageHtml);
4040
if (!match.Success)
4141
{

PatreonDownloader.Implementation/PatreonCrawledUrlProcessor.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Text;
66
using System.Text.RegularExpressions;
7+
using System.Threading;
78
using System.Threading.Tasks;
89
using NLog;
910
using PatreonDownloader.Implementation.Enums;
@@ -23,8 +24,9 @@ class PatreonCrawledUrlProcessor : ICrawledUrlProcessor
2324

2425
private readonly IRemoteFilenameRetriever _remoteFilenameRetriever;
2526
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
27+
private readonly SemaphoreSlim _duplicateNamesCheckSemaphore;
2628

27-
private ConcurrentDictionary<string, int> _fileCountDict; //file counter for duplicate check
29+
private Dictionary<string, int> _fileCountDict; //file counter for duplicate check
2830
private PatreonDownloaderSettings _patreonDownloaderSettings;
2931

3032
private static readonly Regex _fileIdRegex = new Regex(
@@ -42,12 +44,14 @@ public PatreonCrawledUrlProcessor(IRemoteFilenameRetriever remoteFilenameRetriev
4244
_remoteFilenameRetriever = remoteFilenameRetriever ??
4345
throw new ArgumentNullException(nameof(remoteFilenameRetriever));
4446

47+
_duplicateNamesCheckSemaphore = new SemaphoreSlim(1, 1);
48+
4549
_logger.Debug("KemonoCrawledUrlProcessor initialized");
4650
}
4751

4852
public async Task BeforeStart(IUniversalDownloaderPlatformSettings settings)
4953
{
50-
_fileCountDict = new ConcurrentDictionary<string, int>();
54+
_fileCountDict = new Dictionary<string, int>();
5155
_patreonDownloaderSettings = (PatreonDownloaderSettings) settings;
5256
await _remoteFilenameRetriever.BeforeStart(settings);
5357
}
@@ -147,13 +151,30 @@ public async Task<bool> ProcessCrawledUrl(ICrawledUrl udpCrawledUrl)
147151

148152
string key = $"{crawledUrl.PostId}_{filename.ToLowerInvariant()}";
149153

150-
_fileCountDict.AddOrUpdate(key, 0, (key, oldValue) => oldValue + 1);
154+
//Semaphore is required because of possible race condition between multiple threads
155+
await _duplicateNamesCheckSemaphore.WaitAsync();
156+
157+
int count = -1;
158+
try
159+
{
160+
if(_fileCountDict.ContainsKey(key))
161+
_fileCountDict[key]++;
162+
else
163+
_fileCountDict[key] = 0;
164+
165+
166+
count = _fileCountDict[key];
167+
}
168+
finally
169+
{
170+
_duplicateNamesCheckSemaphore.Release();
171+
}
151172

152-
if (_fileCountDict[key] > 1)
173+
if (count > 1)
153174
{
154175
_logger.Warn($"Found more than a single file with the name {filename} in the same folder in post {crawledUrl.PostId}, sequential number will be appended to its name.");
155176

156-
string appendStr = _fileCountDict[key].ToString();
177+
string appendStr = count.ToString();
157178

158179
if (crawledUrl.UrlType != PatreonCrawledUrlType.ExternalUrl)
159180
{

0 commit comments

Comments
 (0)