Replace ANDROID_TESTSUITE with GOOGLE_ASSISTANT
This commit is contained in:
parent
5e3d462fb1
commit
0ee16bf952
82
main.cpp
82
main.cpp
|
@ -778,9 +778,12 @@ json_t* download_info(VideoId& id)
|
|||
{
|
||||
CURL* curl = curl_easy_init();
|
||||
struct curl_slist *headers = curl_slist_append(NULL, "Content-Type: application/json");
|
||||
curl_slist_append(headers, "User-Agent: com.google.android.youtube/17.36.4 (Linux; U; Android 12; GB) gzip");
|
||||
std::string json= "{\"videoId\":\"" + id.Value() +"\",\"context\":{\"client\":{\"clientName\":\"ANDROID_TESTSUITE\",\"clientVersion\": \"1.9\",\"androidSdkVersion\":30, \"hl\":\"en\",\"gl\":\"US\",\"utcOffsetMinutes\":0}}}";
|
||||
|
||||
//curl_slist_append(headers, "User-Agent: com.google.android.youtube/17.36.4 (Linux; U; Android 12; GB) gzip");
|
||||
curl_slist_append(headers,"User-Agent: Google-Ads-Creatives-Assistant");
|
||||
curl_slist_append(headers,"SOCS: CAISEwgDEgk2NzM5OTg2ODUaAmVuIAEaBgiA6p23Bg");
|
||||
//std::string json= "{\"videoId\":\"" + id.Value() +"\",\"context\":{\"client\":{\"clientName\":\"ANDROID_TESTSUITE\",\"clientVersion\": \"1.9\",\"androidSdkVersion\":30, \"hl\":\"en\",\"gl\":\"US\",\"utcOffsetMinutes\":0}}}";
|
||||
std::string json= "{\"videoId\":\"" + id.Value() +"\",\"context\":{\"client\":{\"clientName\":\"GOOGLE_ASSISTANT\",\"clientVersion\": \"0.1\", \"hl\":\"en\",\"gl\":\"US\",\"utcOffsetMinutes\":0}}}";
|
||||
//I replaced ANDROID_TESTSUITE with GOOGLE_ASSISTANT and it worked wow
|
||||
|
||||
|
||||
///youtubei/v1/player?key=AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w
|
||||
|
@ -800,7 +803,17 @@ json_t* download_info(VideoId& id)
|
|||
curl_easy_setopt(curl,CURLOPT_URL,"https://www.youtube.com/youtubei/v1/player?key=AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w");
|
||||
CURLcode c= curl_easy_perform(curl);
|
||||
|
||||
if(c != CURLcode::CURLE_OK)
|
||||
printf("%s\n",curl_easy_strerror(c));
|
||||
else
|
||||
{
|
||||
long http_code = 0;
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
|
||||
|
||||
if(http_code != 200)
|
||||
printf("INFO STATUS_CODE: %i\n",(int)http_code);
|
||||
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
|
||||
return json_loads(outJson.c_str(),0,NULL);
|
||||
|
@ -829,15 +842,32 @@ void safe_title(std::string& s,const char* str, size_t len)
|
|||
if(Invalid(str[i])) continue;
|
||||
s.push_back(str[i]);
|
||||
}
|
||||
|
||||
}
|
||||
void download_file(const char* url, std::filesystem::path& file,bool progress=false)
|
||||
{
|
||||
CURL* curl = curl_easy_init();
|
||||
struct curl_slist *headers=curl_slist_append(NULL, "User-Agent: com.google.android.youtube/17.36.4 (Linux; U; Android 12; GB) gzip");
|
||||
curl_slist_append(headers,"SOCS: CAISEwgDEgk2NzM5OTg2ODUaAmVuIAEaBgiA6p23Bg");
|
||||
|
||||
curl_easy_setopt(curl,CURLOPT_URL,url);
|
||||
FILE* f = fopen(file.c_str(),"wb");
|
||||
curl_easy_setopt(curl,CURLOPT_WRITEDATA, f);
|
||||
curl_easy_setopt(curl,CURLOPT_HTTPHEADER,headers);
|
||||
curl_easy_setopt(curl,CURLOPT_NOPROGRESS,progress ? 0L : 1L);
|
||||
curl_easy_perform(curl);
|
||||
curl_easy_setopt(curl,CURLOPT_FOLLOWLOCATION,1L);
|
||||
CURLcode c= curl_easy_perform(curl);
|
||||
if(c != CURLcode::CURLE_OK)
|
||||
printf("%s\n",curl_easy_strerror(c));
|
||||
else
|
||||
{
|
||||
long http_code = 0;
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
|
||||
|
||||
if(http_code != 200)
|
||||
printf("STATUS_CODE: %i\n",(int)http_code);
|
||||
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
auto len=ftell(f);
|
||||
fclose(f);
|
||||
|
@ -864,16 +894,28 @@ void download_video(VideoId& id)
|
|||
|
||||
auto sd = json_object_get(res,"streamingData");
|
||||
if(sd == nullptr || !json_is_object(sd))
|
||||
{
|
||||
std::cout << "ERR: streamingData does not exist" << std::endl;
|
||||
goto end;
|
||||
}
|
||||
auto formats = json_object_get(sd,"formats");
|
||||
if(formats == nullptr || !json_is_array(formats))
|
||||
{
|
||||
std::cout << "ERR: formats does not exist" << std::endl;
|
||||
goto end;
|
||||
}
|
||||
auto fmt = json_array_get(formats,0);
|
||||
if(fmt == nullptr || !json_is_object(fmt))
|
||||
{
|
||||
std::cout << "ERR: formats[0] does not exist" << std::endl;
|
||||
goto end;
|
||||
}
|
||||
auto url = json_object_get(fmt,"url");
|
||||
if(url == nullptr || !json_is_string(url))
|
||||
{
|
||||
std::cout << "ERR: video url does not exist" << std::endl;
|
||||
goto end;
|
||||
}
|
||||
const char* _url=json_string_value(url);
|
||||
std::filesystem::path fname2 = fname;
|
||||
std::cout << "Downloading: " << title << std::endl;
|
||||
|
@ -887,20 +929,36 @@ void download_video(VideoId& id)
|
|||
|
||||
json_t* thumbnail = json_object_get(details,"thumbnail");
|
||||
if(thumbnail == nullptr || !json_is_object(thumbnail))
|
||||
{
|
||||
std::cout << "ERR: thumbnail does not exist" << std::endl;
|
||||
goto end;
|
||||
}
|
||||
json_t* thumbnails = json_object_get(thumbnail,"thumbnails");
|
||||
if(thumbnails == nullptr || !json_is_array(thumbnails))
|
||||
{
|
||||
std::cout << "ERR: thumbnails does not exist" << std::endl;
|
||||
goto end;
|
||||
}
|
||||
size_t index;
|
||||
json_t* value;
|
||||
json_array_foreach(thumbnails,index,value)
|
||||
{
|
||||
json_t* thumbUrl = json_object_get(value,"url");
|
||||
if(thumbUrl == nullptr || !json_is_string(thumbUrl)) continue;
|
||||
if(thumbUrl == nullptr || !json_is_string(thumbUrl))
|
||||
{
|
||||
std::cout << "ERR: thumbnail url does not exist" << std::endl;
|
||||
continue;
|
||||
}
|
||||
json_t* thubWid = json_object_get(value,"width");
|
||||
if(thubWid == nullptr || !json_is_integer(thubWid)) continue;
|
||||
if(thubWid == nullptr || !json_is_integer(thubWid)) {
|
||||
std::cout << "ERR: thumbnail width does not exist" << std::endl;
|
||||
continue;
|
||||
}
|
||||
json_t* thubHei = json_object_get(value,"height");
|
||||
if(thubHei == nullptr || !json_is_integer(thubHei)) continue;
|
||||
if(thubHei == nullptr || !json_is_integer(thubHei)) {
|
||||
std::cout << "ERR: thumbnail height does not exist" << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto w=json_integer_value(thubWid);
|
||||
auto h=json_integer_value(thubHei);
|
||||
|
@ -910,6 +968,16 @@ void download_video(VideoId& id)
|
|||
download_file(u,thumbPath);
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::cout << "ERR: video title does not exist" << std::endl;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
std::cout << "ERR: videoDetails does not exist" << std::endl;
|
||||
|
||||
}
|
||||
end:
|
||||
json_decref(res);
|
||||
|
|
Loading…
Reference in New Issue