1 #include "httputils.h" 2 #include "cachedhttp.h" 3 #include "constants.h" 4 #include "http.h" 5 #include "localcache.h" 6 notCached()7Http &HttpUtils::notCached() { 8 static Http *h = [] { 9 Http *http = new Http; 10 http->addRequestHeader("User-Agent", userAgent()); 11 12 return http; 13 }(); 14 return *h; 15 } 16 cached()17Http &HttpUtils::cached() { 18 static Http *h = [] { 19 Http *http = new Http; 20 http->addRequestHeader("User-Agent", userAgent()); 21 22 CachedHttp *cachedHttp = new CachedHttp(*http, "http"); 23 24 return cachedHttp; 25 }(); 26 return *h; 27 } 28 yt()29Http &HttpUtils::yt() { 30 static Http *h = [] { 31 Http *http = new Http; 32 http->addRequestHeader("User-Agent", stealthUserAgent()); 33 34 CachedHttp *cachedHttp = new CachedHttp(*http, "yt"); 35 cachedHttp->setMaxSeconds(86400); 36 37 return cachedHttp; 38 }(); 39 return *h; 40 } 41 stealthAndNotCached()42Http &HttpUtils::stealthAndNotCached() { 43 static Http *h = [] { 44 Http *http = new Http; 45 http->addRequestHeader("User-Agent", stealthUserAgent()); 46 47 return http; 48 }(); 49 return *h; 50 } 51 clearCaches()52void HttpUtils::clearCaches() { 53 LocalCache::instance("yt")->clear(); 54 LocalCache::instance("http")->clear(); 55 } 56 userAgent()57const QByteArray &HttpUtils::userAgent() { 58 static const QByteArray ua = [] { 59 return QString(QLatin1String(Constants::NAME) + QLatin1Char('/') + 60 QLatin1String(Constants::VERSION) + QLatin1String(" ( ") + 61 Constants::WEBSITE + QLatin1String(" )")) 62 .toUtf8(); 63 }(); 64 return ua; 65 } 66 stealthUserAgent()67const QByteArray &HttpUtils::stealthUserAgent() { 68 static const QByteArray ua = 69 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like " 70 "Gecko) Chrome/84.0.4147.105 Safari/537.36"; 71 return ua; 72 } 73