Skip to content

Commit

Permalink
Fix for browser obsoleting by Youtube; see also aliakseis/pytube@2b02c8c
Browse files Browse the repository at this point in the history
  • Loading branch information
aliakseis committed Sep 18, 2019
1 parent e49c662 commit dc69a2d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions networking/http_get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace {

const wchar_t USER_AGENT[]
= L"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36";

class CComUsageScope
{
bool m_bInitialized;
Expand Down Expand Up @@ -35,6 +38,7 @@ long HttpGetStatus(const char * url)

if (SUCCEEDED(result = pIWinHttpRequest.CoCreateInstance(L"WinHttp.WinHttpRequest.5.1", NULL, CLSCTX_INPROC_SERVER))
&& SUCCEEDED(result = pIWinHttpRequest->Open(CComBSTR(L"HEAD"), CComBSTR(static_cast<const char*>(url)), varFalse))
&& SUCCEEDED(result = pIWinHttpRequest->SetRequestHeader(CComBSTR(L"User-Agent"), CComBSTR(USER_AGENT)))
&& SUCCEEDED(result = pIWinHttpRequest->Send(varEmpty)))
{
pIWinHttpRequest->get_Status(&result);
Expand All @@ -56,6 +60,7 @@ CComVariant HttpGet(const char * url)

if (SUCCEEDED(pIWinHttpRequest.CoCreateInstance(L"WinHttp.WinHttpRequest.5.1", NULL, CLSCTX_INPROC_SERVER))
&& SUCCEEDED(pIWinHttpRequest->Open(CComBSTR(L"GET"), CComBSTR(static_cast<const char*>(url)), varFalse))
&& SUCCEEDED(pIWinHttpRequest->SetRequestHeader(CComBSTR(L"User-Agent"), CComBSTR(USER_AGENT)))
&& SUCCEEDED(pIWinHttpRequest->Send(varEmpty)))
{
pIWinHttpRequest->get_ResponseBody(&varBody);
Expand Down

0 comments on commit dc69a2d

Please # to comment.