Exemplo n.º 1
0
        private void AddHeaders(XUnityWebRequest request, bool isTranslationRequest)
        {
            request.Headers[HttpRequestHeader.UserAgent] = string.IsNullOrEmpty(AutoTranslatorSettings.UserAgent) ? UserAgents.Chrome_Win10_Latest : AutoTranslatorSettings.UserAgent;

            if (AcceptLanguage != null)
            {
                request.Headers[HttpRequestHeader.AcceptLanguage] = AcceptLanguage;
            }
            if (Accept != null)
            {
                request.Headers[HttpRequestHeader.Accept] = Accept;
            }
            if (Referer != null && isTranslationRequest)
            {
                request.Headers[HttpRequestHeader.Referer] = Referer;
            }
            if (Origin != null && isTranslationRequest)
            {
                request.Headers["Origin"] = Origin;
            }
            if (AcceptCharset != null)
            {
                request.Headers[HttpRequestHeader.AcceptCharset] = AcceptCharset;
            }
            if (ContentType != null && isTranslationRequest)
            {
                request.Headers[HttpRequestHeader.ContentType] = ContentType;
            }
        }
        public override void OnCreateRequest(IHttpRequestCreationContext context)
        {
            _translationCount++;

            var allUntranslatedText =
                JsonHelper.Escape(JsonHelper.Escape(string.Join("\n", context.UntranslatedTexts)));

            var query = string.Join("&", new[]
            {
                "rpcids=" + _translateRpcId,
                "f.sid=" + _FSID.ToString(CultureInfo.InvariantCulture),
                "bl=" + Uri.EscapeDataString(_version),
                "hl=en-US",
                "soc-app=1",
                "soc-platform=1",
                "soc-device=1",
                "_reqid=" + _reqId.ToString(CultureInfo.InvariantCulture),
                "rt=c"
            });

            var data = "f.req=" + Uri.EscapeDataString(string.Format(TranslationPostTemplate, _translateRpcId, allUntranslatedText, FixLanguage(context.SourceLanguage), FixLanguage(context.DestinationLanguage))) + "&";

            var url = _httpsServicePointTranslateTemplateUrl + "?" + query;

            var request = new XUnityWebRequest("POST", url, data);

            request.Cookies = _cookieContainer;
            AddHeaders(request, true);

            _reqId += 100000;

            context.Complete(request);
        }
Exemplo n.º 3
0
        public override void OnCreateRequest(IHttpRequestCreationContext context)
        {
            _translationCount++;

            string address = null;

            if (_ig == null || _iid == null)
            {
                address = HttpsServicePointTemplateUrlWithoutIG;
            }
            else
            {
                address = string.Format(HttpsServicePointTemplateUrl, _ig, _iid, _translationCount);
            }

            var data = string.Format(
                RequestTemplate,
                Uri.EscapeDataString(context.UntranslatedText),
                context.SourceLanguage,
                context.DestinationLanguage);

            var request = new XUnityWebRequest("POST", address, data);

            request.Cookies = _cookieContainer;
            AddHeaders(request, true);

            context.Complete(request);
        }
Exemplo n.º 4
0
        public override void OnCreateRequest(IHttpRequestCreationContext context)
        {
            var text    = Uri.EscapeDataString(string.Join("\n", context.UntranslatedTexts));
            var request = new XUnityWebRequest(
                "POST",
                UrlBase + (_isSMT ? UrlNSMT : UrlN2MT),
                string.Format(
                    FormUrlEncodedTemplate,
                    FixLanguage(context.SourceLanguage),
                    FixLanguage(context.DestinationLanguage),
                    text));

            // create token
            var timestamp = Math.Truncate(DateTime.Now.Subtract(DateTime.MinValue.AddYears(1969)).TotalMilliseconds);
            var key       = Encoding.UTF8.GetBytes(_version);
            var data      = Encoding.UTF8.GetBytes($"{UUID}\n{request.Address}\n{timestamp}");
            var token     = Convert.ToBase64String(new HMACMD5(key).ComputeHash(data));

            // set required headers
            request.Headers["Authorization"] = $"PPG {UUID}:{token}";
            request.Headers["Content-Type"]  = "application/x-www-form-urlencoded; charset=UTF-8";
            request.Headers["Timestamp"]     = timestamp.ToString();

            context.Complete(request);

            _translationCount++;
        }
        public override void OnCreateRequest(IHttpRequestCreationContext context)
        {
            _translationCount++;

            var allUntranslatedText = string.Join("\n", context.UntranslatedTexts);

            XUnityWebRequest request;

            if (context.DestinationLanguage == "romaji")
            {
                request = new XUnityWebRequest(
                    string.Format(
                        HttpsServicePointRomanizeTemplateUrl,
                        context.SourceLanguage,
                        Tk(allUntranslatedText),
                        Uri.EscapeDataString(allUntranslatedText)));
            }
            else
            {
                request = new XUnityWebRequest(
                    string.Format(
                        HttpsServicePointTranslateTemplateUrl,
                        context.SourceLanguage,
                        context.DestinationLanguage,
                        Tk(allUntranslatedText),
                        Uri.EscapeDataString(allUntranslatedText)));
            }

            request.Cookies = _cookieContainer;
            AddHeaders(request, true);

            context.Complete(request);
        }
        private XUnityWebRequest CreateWebSiteRequest()
        {
            var request = new XUnityWebRequest(_selectedUserBackend);

            request.Cookies = _cookieContainer;
            AddHeaders(request, false);

            return(request);
        }
Exemplo n.º 7
0
        private XUnityWebRequest CreateWebSiteRequest()
        {
            var request = new XUnityWebRequest(HttpsTranslateUserSite);

            request.Cookies = _cookieContainer;
            AddHeaders(request, false);

            return(request);
        }
 private static void SetupApiRequestHeaders(XUnityWebRequest request)
 {
     request.Headers["device-type"]       = "pc";
     request.Headers["Accept"]            = "application/json";
     request.Headers["x-apigw-partnerid"] = "papago";
     request.Headers["Content-Type"]      = "application/x-www-form-urlencoded; charset=UTF-8";
     request.Headers["Origin"]            = "https://papago.naver.com";
     request.Headers["Referer"]           = "https://papago.naver.com/";
 }
        public override void OnCreateRequest(IHttpRequestCreationContext context)
        {
            var request = new XUnityWebRequest(
                string.Format(
                    ServicePointTemplateUrl,
                    _endpoint,
                    context.SourceLanguage,
                    context.DestinationLanguage,
                    Uri.EscapeDataString(context.UntranslatedText)));

            context.Complete(request);
        }
Exemplo n.º 10
0
        public override void OnCreateRequest(IHttpRequestCreationContext context)
        {
            var request = new XUnityWebRequest(
                string.Format(
                    HttpsServicePointTemplateUrl,
                    context.SourceLanguage,
                    context.DestinationLanguage,
                    WwwHelper.EscapeUrl(context.UntranslatedText),
                    _key));

            request.Headers[HttpRequestHeader.Accept]        = "*/*";
            request.Headers[HttpRequestHeader.AcceptCharset] = "UTF-8";

            context.Complete(request);
        }
        public override void OnCreateRequest(IHttpRequestCreationContext context)
        {
            var fullTranslationText = string.Join("\n", context.UntranslatedTexts);
            var jsonString          = string.Format(JsonTemplate, _deviceId, FixLanguage(context.SourceLanguage), FixLanguage(context.DestinationLanguage), JsonHelper.Escape(fullTranslationText));
            var base64           = Convert.ToBase64String(Encoding.UTF8.GetBytes(jsonString));
            var obfuscatedBase64 = Obfuscate(16, base64);
            var data             = string.Format(FormUrlEncodedTemplate, Uri.EscapeDataString(obfuscatedBase64));

            var request = new XUnityWebRequest("POST", Url, data);

            request.Cookies = _cookies;

            SetupDefaultHeaders(request);
            SetupApiRequestHeaders(request);

            context.Complete(request);

            _translationCount++;
        }
        public override void OnCreateRequest(IHttpRequestCreationContext context)
        {
            var urlBuilder = new StringBuilder(HttpsServiceUrl);

            urlBuilder.Append("?key=").Append(Uri.EscapeDataString(_key));
            urlBuilder.Append("&source=").Append(context.SourceLanguage);
            urlBuilder.Append("&target=").Append(context.DestinationLanguage);
            for (int i = 0; i < context.UntranslatedTexts.Length; i++)
            {
                var untranslatedText = context.UntranslatedTexts[i];
                urlBuilder.Append("&q=").Append(Uri.EscapeDataString(untranslatedText));
            }

            var request = new XUnityWebRequest(
                "POST",
                urlBuilder.ToString());

            context.Complete(request);
        }
Exemplo n.º 13
0
        public override void OnCreateRequest(IHttpRequestCreationContext context)
        {
            string salt = DateTime.UtcNow.Millisecond.ToString();
            var    md5  = CreateMD5(_appId + context.UntranslatedText + salt + _appSecret);

            var request = new XUnityWebRequest(
                string.Format(
                    HttpServicePointTemplateUrl,
                    WwwHelper.EscapeUrl(context.UntranslatedText),
                    FixLanguage(context.SourceLanguage),
                    FixLanguage(context.DestinationLanguage),
                    _appId,
                    salt,
                    md5));

            request.Headers[HttpRequestHeader.UserAgent]     = string.IsNullOrEmpty(AutoTranslatorSettings.UserAgent) ? UserAgents.Chrome_Win10_Latest : AutoTranslatorSettings.UserAgent;
            request.Headers[HttpRequestHeader.AcceptCharset] = "UTF-8";

            context.Complete(request);
        }
 private void AddHeaders(XUnityWebRequest request, bool isTranslationRequest)
 {
     request.Headers[HttpRequestHeader.UserAgent] = string.IsNullOrEmpty(AutoTranslatorSettings.UserAgent) ? UserAgents.Chrome_Win10_Latest : AutoTranslatorSettings.UserAgent;
     if (AcceptLanguage != null)
     {
         request.Headers[HttpRequestHeader.AcceptLanguage] = AcceptLanguage;
     }
     if (Accept != null)
     {
         request.Headers[HttpRequestHeader.Accept] = Accept;
     }
     if (isTranslationRequest)
     {
         request.Headers[HttpRequestHeader.Referer] = _selectedUserBackend + "/";
     }
     if (AcceptCharset != null)
     {
         request.Headers[HttpRequestHeader.AcceptCharset] = AcceptCharset;
     }
 }
Exemplo n.º 15
0
 private void AddHeaders(XUnityWebRequest request, bool isTranslationRequest)
 {
     request.Headers[HttpRequestHeader.UserAgent] = UserAgent_Chrome_Win10_Latest;
     if (AcceptLanguage != null)
     {
         request.Headers[HttpRequestHeader.AcceptLanguage] = AcceptLanguage;
     }
     if (Accept != null)
     {
         request.Headers[HttpRequestHeader.Accept] = Accept;
     }
     if (Referer != null && isTranslationRequest)
     {
         request.Headers[HttpRequestHeader.Referer] = Referer;
     }
     if (AcceptCharset != null)
     {
         request.Headers[HttpRequestHeader.AcceptCharset] = AcceptCharset;
     }
 }
        private void AddHeaders(XUnityWebRequest request, bool isTranslationRequest)
        {
            request.Headers[HttpRequestHeader.UserAgent] = string.IsNullOrEmpty(AutoTranslatorSettings.UserAgent) ? UserAgents.Chrome_Win10_Latest : AutoTranslatorSettings.UserAgent;
            if (AcceptLanguage != null)
            {
                request.Headers[HttpRequestHeader.AcceptLanguage] = AcceptLanguage;
            }

            if (isTranslationRequest)
            {
                request.Headers[HttpRequestHeader.Referer] = _selectedUserBackend + "/";
                request.Headers["X-Same-Domain"]           = "1";
                request.Headers["DNT"] = "1";
                request.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded;charset=UTF-8";
                request.Headers[HttpRequestHeader.Accept]      = "*/*";
                request.Headers["Origin"] = _selectedUserBackend;
            }
            else
            {
                request.Headers["Upgrade-Insecure-Requests"] = "1";
            }
        }
        public override void OnCreateRequest(IHttpRequestCreationContext context)
        {
            StringBuilder data = new StringBuilder();

            data.Append("[");
            for (int i = 0; i < context.UntranslatedTexts.Length; i++)
            {
                var untranslatedText = JsonHelper.Escape(context.UntranslatedTexts[i]);
                data.Append("{\"Text\":\"");
                data.Append(untranslatedText);
                data.Append("\"}");

                if (context.UntranslatedTexts.Length - 1 != i)
                {
                    data.Append(",");
                }
            }
            data.Append("]");


            var request = new XUnityWebRequest(
                "POST",
                string.Format(HttpsServicePointTemplateUrl, context.SourceLanguage, context.DestinationLanguage),
                data.ToString());

            if (Accept != null)
            {
                request.Headers[HttpRequestHeader.Accept] = Accept;
            }
            if (ContentType != null)
            {
                request.Headers[HttpRequestHeader.ContentType] = ContentType;
            }
            request.Headers["Ocp-Apim-Subscription-Key"] = _key;

            context.Complete(request);
        }
        public override IEnumerator OnBeforeTranslate(IHttpTranslationContext context)
        {
            if (_translationCount % 133 == 0)
            {
                _cookies  = new CookieContainer();
                _deviceId = Guid.NewGuid().ToString();

                // terminate session?????

                var client  = new XUnityWebClient();
                var request = new XUnityWebRequest(Website);
                request.Cookies = _cookies;

                SetupDefaultHeaders(request);

                var response = client.Send(request);
                while (response.MoveNext())
                {
                    yield return(response.Current);
                }

                // dont actually cared about the response, just the cookies
            }
        }
 private static void SetupDefaultHeaders(XUnityWebRequest request)
 {
     request.Headers[HttpRequestHeader.UserAgent] = string.IsNullOrEmpty(AutoTranslatorSettings.UserAgent) ? UserAgents.Chrome_Win10_Latest : AutoTranslatorSettings.UserAgent;
     request.Headers["Accept-Language"]           = "en-US";
 }
Exemplo n.º 20
0
 void IHttpRequestCreationContext.Complete(XUnityWebRequest request)
 {
     Request = request;
 }