Exemple #1
0
        private DebridLinkFrRequestResult GetNewToken()
        {
            // request : https://debrid-link.fr/api/token/:publickey/new
            // result  :
            //{
            //  "result":"OK",
            //  "value":
            //  {
            //    "token":"10_2d600afa935e73e12898abac9ff075673c20625d99452393",
            //    "validTokenUrl":"https:\/\/debrid-link.fr\/user\/10_2d600afa935e73e12898abac9ff075673c20625d99452393\/login",
            //    "key":"sQ0bhf6k2A3yav5I"
            //  },
            //  "ts":1458902940
            //}

            string       url         = __url + string.Format("/token/{0}/new", _publicKey);
            DateTime     requestTime = DateTime.Now;
            BsonDocument result      = null;
            Exception    ex          = null;

            try
            {
                //Http.Http http = HttpManager.CurrentHttpManager.Load(new HttpRequest { Url = url }, _requestParameters);
                HttpResult <string> httpResult = _httpManagerConnexion.LoadText(new HttpRequest {
                    Url = url
                });
                //result = BsonSerializer.Deserialize<BsonDocument>(http.ResultText);
                result = BsonSerializer.Deserialize <BsonDocument>(httpResult.Data);
            }
            catch (Exception ex2)
            {
                ex = ex2;
                throw;
            }
            finally
            {
                if (_traceData != null)
                {
                    _traceData.Trace(new BsonDocument {
                        { "Category", "DebridLinkFr_v3" }, { "Ope", "GetNewToken" }, { "Key", "HttpRequest" }, { "Data", new BsonDocument {
                                                                                                                     { "Url", url }, { "Result", result }
                                                                                                                 } }
                    }, ex);
                }
                if (__trace)
                {
                    pb.Trace.WriteLine("  get new token               : \"{0}\"", url);
                    pb.Trace.WriteLine("  result                      :");
                    pb.Trace.WriteLine(result.zToJson());
                }
            }

            return(new DebridLinkFrRequestResult {
                RequestTime = requestTime, Result = result
            });
        }
Exemple #2
0
        //public static bool Trace { get { return __trace; } set { __trace = value; } }

        //public override string DebridLink(string[] links)
        //{
        //    var q = (from l in links select new { link = l, rate = GetLinkRate(l) }).OrderBy(link => link.rate).Select(link => link.link);
        //    foreach (string link in q)
        //    {
        //        try
        //        {
        //            string downloadLink = DebridLink(link);
        //            if (downloadLink != null)
        //                return downloadLink;
        //        }
        //        catch(Exception ex)
        //        {
        //            Trace.WriteLine("error : {0}", ex.Message);
        //            Trace.WriteLine(ex.StackTrace);
        //        }
        //    }
        //    return null;
        //}

        public override string DebridLink(string link)
        {
            //request           : http://www.alldebrid.com/service.php?pseudo=&password=&link=http%3A%2F%2Fuptobox.com%2F0485eztzwh1y
            //response          : 0,;,<a class='link_dl' href='http://s10.alldebrid.com/dl/dg47yr48c6/Echos.12-08.pdf' style='a:visited { color = black }'>Echos.12-08.pdf</a>,;,0
            //                    1,;,http://www.oboom.com/36U5SZ6H : <span style='color:#a00;'>Invalid link</span>,;,0
            //request view=1    : http://www.alldebrid.com/service.php?pseudo=&password=&link=http%3A%2F%2Fuptobox.com%2F0485eztzwh1y&view=1
            //response          : http://s14.alldebrid.com/dl/dg46ejab1c/Echos.12-08.pdf
            //                    1,;,http://www.oboom.com/9XLPJDT2 : <span style='color:#a00;'>Invalid link</span>,;,0
            //request json=true : http://www.alldebrid.com/service.php?pseudo=&password=&link=http%3A%2F%2Fuptobox.com%2F0485eztzwh1y&json=true
            //response          : {"link":"http:\/\/s19.alldebrid.com\/dl\/dg4a1xda7b\/Echos.12-08.pdf","host":"uptobox","filename":"Echos.12-08.pdf","icon":"\/lib\/images\/hosts\/uptobox.png","streaming":[],"nb":0,"error":"","filesize":"15414067"}
            //                    {"link":"http:\/\/www.oboom.com\/36U5SZ6H","host":false,"filename":"","icon":"\/lib\/images\/hosts\/.png","streaming":[],"nb":0,"error":"This link isn't valid or not supported."}
            if (__trace)
            {
                pb.Trace.Write("DebriderAlldebrid.DebridLink() : \"{0}\"", link);
            }
            string url = string.Format(__url, _login, _password, link);
            //Http.Http http = HttpManager.CurrentHttpManager.Load(new HttpRequest { Url = url });
            HttpResult <string> httpResult = _httpManager.LoadText(new HttpRequest {
                Url = url
            });
            //string debridLink = http.ResultText;
            string debridLink = httpResult.Data;

            if (__trace)
            {
                pb.Trace.WriteLine(" result \"{0}\"", debridLink);
            }
            if (!debridLink.StartsWith("http://"))
            {
                debridLink = null;
            }
            return(debridLink);
        }
Exemple #3
0
        protected bool LoadFromWeb(WebData_v2 <TSource, TData> webData)
        {
            //Trace.WriteLine($"WebDataManager_v5.LoadFromWeb()");

            TData   data    = webData.Data = _createData();
            TSource source  = webData.Request.Data;
            bool    success = true;

            foreach (KeyValuePair <string, Action <TData, HttpResult <string> > > value in _getDatas)
            {
                HttpRequest httpRequest = GetHttpRequest(source, value.Key);
                httpRequest.ReloadFromWeb = webData.Request.ReloadFromWeb;
                HttpResult <string> httpResult = _httpManager.LoadText(httpRequest);
                if (httpResult.Success)
                {
                    value.Value(data, httpResult);
                }
                else
                {
                    success = false;
                }
                webData.HttpResults.Add(value.Key, httpResult);
            }
            webData.DataLoaded        = true;
            webData.DataLoadedFromWeb = true;

            if (webData.Id != null)
            {
                webData.Data.zSetId(webData.Id);
            }

            return(success);
        }
Exemple #4
0
        public static void Test_LoadText(string url, string cacheDirectory = null)
        {
            HttpManager_v2      httpManager = CreateHttpManager(cacheDirectory);
            HttpResult <string> result      = httpManager.LoadText(new HttpRequest {
                Url = url
            });

            Trace.WriteLine($"Success {result.Success} LoadFromWeb {result.LoadFromWeb} LoadFromCache {result.LoadFromCache}");
            string resultText = result.Data;

            resultText = resultText.Substring(0, Math.Min(resultText.Length, 100));
            Trace.WriteLine(resultText + " ...");
        }
Exemple #5
0
        public BsonDocument ExecuteCommand(string requestPath, HttpRequestMethod method, string content = null)
        {
            // from https://debrid-link.fr/api_doc/#/home
            // URL : https://debrid-link.fr/api/account/infos
            // X-DL-TOKEN : 10_d82555567e30c1e7137828eee6bf35429706d27e43319312
            // X-DL-SIGN : ab90fa6a2c9f1bc2bbd7988ff266971b5c10583c
            // X-DL-TS : 1418758917
            // Sign decoded : 1418758917/account/infosi619yOI4Kt8WB02g

            Connect();
            string url = __url + requestPath;

            if (__trace)
            {
                pb.Trace.WriteLine("DebriderDebridLink.ExecuteGetCommand() :");
            }
            //HttpRequestParameters requestParameters = new HttpRequestParameters { Encoding = Encoding.UTF8 };

            // test de décalage du timestamp
            //timestamp -= 15;  // KO avec -15 ou +15
            //if (__trace)
            //    pb.Trace.WriteLine("  server time + 60 sec        : {0}", zdate.UnixTimeStampToDateTime(timestamp));
            int    timestamp = GetServerTimestamp();
            string signature = GetSignature(timestamp, requestPath, _connexion.Key);

            // set token, signature and timestamp as param in url
            //StringBuilder paramBuilder = new StringBuilder();
            //paramBuilder.Append('?');
            //paramBuilder.AppendFormat("x-dl-token={0}", _connexion.Token);
            //paramBuilder.AppendFormat("&x-dl-sign={0}", signature);
            //paramBuilder.AppendFormat("&x-dl-ts={0}", timestamp);
            //url += paramBuilder.ToString();

            // set token, signature and timestamp as headers of http request
            HttpRequestParameters requestParameters = _httpManagerCommand.RequestParameters;

            //_authenticateRequestParameters.Headers["x-dl-token"] = _connexion.Token;
            //_authenticateRequestParameters.Headers["x-dl-sign"] = signature;
            //_authenticateRequestParameters.Headers["x-dl-ts"] = timestamp.ToString();
            requestParameters.Headers["x-dl-token"] = _connexion.Token;
            requestParameters.Headers["x-dl-sign"]  = signature;
            requestParameters.Headers["x-dl-ts"]    = timestamp.ToString();

            if (__trace)
            {
                pb.Trace.WriteLine("  http method                 : {0}", method);
                pb.Trace.WriteLine("  http header                 : \"{0}\" = \"{1}\"", "x-dl-token", requestParameters.Headers["x-dl-token"]);
                pb.Trace.WriteLine("  http header                 : \"{0}\" = \"{1}\"", "x-dl-sign", requestParameters.Headers["x-dl-sign"]);
                pb.Trace.WriteLine("  http header                 : \"{0}\" = \"{1}\"", "x-dl-ts", requestParameters.Headers["x-dl-ts"]);
                if (content != null)
                {
                    pb.Trace.WriteLine("  http content                : \"{0}\"", content);
                }
            }

            DateTime dt = DateTime.Now;
            //Http.Http http = HttpManager.CurrentHttpManager.Load(new HttpRequest { Url = url, Method = method, Content = content }, _authenticateRequestParameters);
            HttpResult <string> httpResult = _httpManagerCommand.LoadText(new HttpRequest {
                Url = url, Method = method, Content = content
            });

            //BsonDocument result = BsonDocument.Parse(http.ResultText);
            BsonDocument result = BsonDocument.Parse(httpResult.Data);

            //if (__trace)
            //{
            int      newTimestamp     = result.zGet("ts").zAsInt();
            DateTime newServerTime    = zdate.UnixTimeStampToDateTime(newTimestamp);
            TimeSpan newServerTimeGap = newServerTime - dt;

            // gap gap {2}    newServerTimeGap - _connexion.ServerTimeGap
            pb.Trace.WriteLine("  new server time             : {0} gap {1} timestamp {2} timestamp gap {3}", newServerTime, newServerTimeGap, newTimestamp, timestamp - newTimestamp);
            //}

            //if (__trace)
            //{
            //    pb.Trace.WriteLine("  result                      :");
            //    pb.Trace.WriteLine(result.zToJson());
            //}
            return(result);
        }