Skip to content

Commit

Permalink
Merge pull request #64 from yairp03/bug/user-agent
Browse files Browse the repository at this point in the history
Fixed driver's user agent
  • Loading branch information
yairp03 authored Sep 4, 2022
2 parents d957bcb + df43c93 commit e012346
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions SdarotAPI/Resources/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ public static class IdSelectors
public const int WaitTime = 30;
public const string Error2Message = "שגיאה 2!";
public const string LoginMessage = "התחברות לאתר";
public const string UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36";
}
1 change: 1 addition & 0 deletions SdarotAPI/SdarotAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="DotNetSeleniumExtras.WaitHelpers" Version="3.11.0" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.45" />
<PackageReference Include="Selenium.WebDriver" Version="4.4.0" />
</ItemGroup>

Expand Down
2 changes: 2 additions & 0 deletions SdarotAPI/SdarotDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public async Task Initialize(bool headless = true)
if (headless)
{
options.AddArgument("headless");
options.AddArgument("user-agent=" + Constants.UserAgent);
options.AddArgument("--remote-debugging-port=9222");
}

Expand Down Expand Up @@ -280,6 +281,7 @@ public async Task<EpisodeMediaDetails> GetEpisodeMediaDetailsAsync(EpisodeInform
{
throw new Error2Exception();
}

throw new WebsiteErrorException();
}

Expand Down
4 changes: 2 additions & 2 deletions SdarotAPI/SdarotHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static async Task DownloadEpisode(EpisodeMediaDetails episode, string dow
{
using var handler = new HttpClientHandler() { CookieContainer = episode.Cookies };
using var client = new HttpClient(handler);
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36");
client.DefaultRequestHeaders.Add("User-Agent", Constants.UserAgent);
using var file = new FileStream(downloadLocation, FileMode.Create, FileAccess.Write, FileShare.None);
await client.DownloadAsync(episode.MediaUrl, file, progress, ct);
}
Expand All @@ -26,7 +26,7 @@ public static async Task DownloadEpisode(EpisodeMediaDetails episode, string dow
{
using var handler = new HttpClientHandler() { CookieContainer = episode.Cookies };
using var client = new HttpClient(handler);
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36");
client.DefaultRequestHeaders.Add("User-Agent", Constants.UserAgent);
// Get the http headers first to examine the content length
using var response = await client.GetAsync(episode.MediaUrl, HttpCompletionOption.ResponseHeadersRead);
return response.Content.Headers.ContentLength;
Expand Down

0 comments on commit e012346

Please sign in to comment.