Ejemplo n.º 1
0
        public async Task <bool> UploadRemoteMultipleAsync(List <string> UrlsToUP)
        {
            var parameters = new AuthDictionary
            {
                { "url", string.Join(" ", UrlsToUP) },
                { "folderid", FolderID.ToString() }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/downloadfileasync"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters);
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(true);
                    }
                    else
                    {
                        ShowError(result);
                        return(false);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <JSON_DeviceMetadata> Create(string NickName, string Model, string Manufacturer, int?AppVersion, Utilitiez.iconEnum?Icon, bool?HasSMS)
        {
            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                var         HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("devices"));
                var         JSONobj       = new { nickname = NickName, model = Model, manufacturer = Manufacturer, app_version = AppVersion.Equals(0) | !AppVersion.HasValue ? null : AppVersion, icon = Icon.HasValue ? Icon.ToString() : null, has_sms = HasSMS.HasValue ? HasSMS : null };
                HttpContent streamContent = new StringContent(JsonConvert.SerializeObject(JSONobj, Formatting.None, new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore
                }), System.Text.Encoding.UTF8, "application/json");
                HtpReqMessage.Content = streamContent;
                HttpResponseMessage ResPonse = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false);

                var result = await ResPonse.Content.ReadAsStringAsync();

                if (ResPonse.StatusCode == HttpStatusCode.OK)
                {
                    var FinRes = JsonConvert.DeserializeObject <JSON_DeviceMetadata>(result, JSONhandler);
                    // FinRes.ApiLimits = GetApiLimits(ResPonse)
                    return(FinRes);
                }
                else
                {
                    ShowError(result);
                    return(null);
                }
            }
        }
Ejemplo n.º 3
0
        public async Task <string> UploadRemoteAsync(string UrlToUP, string Filename = null)
        {
            var GeneJobID  = RandomString(8);
            var parameters = new AuthDictionary
            {
                { "url", UrlToUP },
                { "folderid", FolderID.ToString() },
                { "target", Filename },
                { "progresshash", GeneJobID }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/downloadfileasync"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters);
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(GeneJobID);
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public async Task <JSON_ListFolder> ListWithoutShared()
        {
            var parameters = new AuthDictionary {
                { "folderid", FolderID.ToString() }, { "noshares", "1" }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/listfolder"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters);
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        var finLst = JObject.Parse(result).SelectToken("metadata").SelectToken("contents").ToList();
                        var files  = (from x in finLst where x.Value <bool>("isfolder") == false select JsonConvert.DeserializeObject <JSON_FileMetadata>(x.ToString(), JSONhandler)).ToList();
                        var dirs   = (from x in finLst where x.Value <bool>("isfolder") == true select JsonConvert.DeserializeObject <JSON_FolderMetadata>(x.ToString(), JSONhandler)).ToList();
                        return(new JSON_ListFolder()
                        {
                            Files = files, FilesCount = files.Count, Folders = dirs, FoldersCount = dirs.Count
                        });
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public async Task <bool> Rename(string RenameTo)
        {
            var parameters = new AuthDictionary
            {
                { "folderid", FolderID.ToString() },
                { "toname", RenameTo }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/renamefolder"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters);
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(true);
                    }
                    else
                    {
                        ShowError(result);
                        return(false);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public async Task <JSON_PublicMetadata> Metadata(Uri publiclink)
        {
            var parameters = new AuthDictionary {
                { "code", publiclink.GetParameterInUrl("code") }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/getfilepublink"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters.RemoveEmptyValues());
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(JsonConvert.DeserializeObject <JSON_PublicMetadata>(JObject.Parse(result).SelectToken("metadata").ToString(), JSONhandler));
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public async Task <JSON_Checksum> Checksum()
        {
            var parameters = new AuthDictionary {
                { "fileid", FileID.ToString() }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/checksumfile"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters);
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(JsonConvert.DeserializeObject <JSON_Checksum>(result, JSONhandler));
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public async Task <JSON_FolderMetadata> ListAll()
        {
            var parameters = new AuthDictionary
            {
                { "folderid", "0" },
                { "recursive", "1" }
            };

            // parameters.Add("nofiles", 1)
            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/listfolder"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters);
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == System.Net.HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(JsonConvert.DeserializeObject <JSON_FolderMetadata>(JObject.Parse(result).SelectToken("metadata").ToString(), JSONhandler));
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public async Task <string> CompressAsync(long DestinationFolderID, string Filename = null)
        {
            var GeneJobID  = Utilitiez.RandomString(8);
            var parameters = new AuthDictionary
            {
                { "folderids", string.Join(",", FolderIDs) },
                { "tofolderid", DestinationFolderID.ToString() },
                { "toname", Filename },
                { "progresshash", GeneJobID }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/savezip"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters);
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == System.Net.HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(GeneJobID);
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public async Task <JSON_FileMetadata> CopyThumbnail(long DestinationFolderID, string WIDTH_x_HEIGHT, ExtEnum Ext, bool Crop, bool AutoRename, string RenameTo = null)
        {
            var parameters = new AuthDictionary
            {
                { "fileid", FileID.ToString() },
                { "tofolderid", DestinationFolderID.ToString() },
                { "noover", AutoRename ? "1" : null },
                { "toname", RenameTo },
                { "type", Ext.ToString() },
                { "size", WIDTH_x_HEIGHT },
                { "crop", Crop ? "1" : null }
            };

            var encodedContent = new FormUrlEncodedContent(parameters.RemoveEmptyValues());

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/savethumb"));
                HtpReqMessage.Content = encodedContent;
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(JsonConvert.DeserializeObject <JSON_FileMetadata>(JObject.Parse(result).SelectToken("metadata").ToString(), JSONhandler));
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public async Task <JSON_FileMetadata> Move(long DestinationFolderID, string RenameTo = null)
        {
            var parameters = new AuthDictionary
            {
                { "fileid", FileID.ToString() },
                { "tofolderid", DestinationFolderID.ToString() },
                { "toname", RenameTo }
            };
            var encodedContent = new FormUrlEncodedContent(parameters);

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/renamefile"));
                HtpReqMessage.Content = encodedContent;
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(JsonConvert.DeserializeObject <JSON_FileMetadata>(JObject.Parse(result).SelectToken("metadata").ToString(), JSONhandler));
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 12
0
        public async Task <string> DirectZipUrl(Uri publiclink, string ZipName)
        {
            var parameters = new AuthDictionary()
            {
                { "code", publiclink.GetParameterInUrl("code") }, { "filename", ZipName.ToLower().EndsWith(".zip") ? ZipName : $"{ZipName}.zip" }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/getpubziplink"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters);
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(string.Format("https://{0}{1}", JObject.Parse(result).SelectToken("hosts[0]").ToString(), JObject.Parse(result).SelectToken("path").ToString().Replace(@"\", string.Empty)));
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public async Task <string> ThumbnailUrl(string WIDTH_x_HEIGHT, ExtEnum Ext, bool Crop)
        {
            var parameters = new AuthDictionary()
            {
                { "fileid", FileID.ToString() }, { "size", WIDTH_x_HEIGHT }, { "type", Ext.ToString() }, { "crop", Crop ? "1" : null }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/getthumblink"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters.RemoveEmptyValues());
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(string.Format("https://{0}{1}", JObject.Parse(result).SelectToken("hosts[0]").ToString(), JObject.Parse(result).SelectToken("path").ToString().Replace(@"\", string.Empty)));
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 14
0
        public static async Task <JSON_ExchangingVerificationCodeForToken> ExchangingVerificationCode_For_Token(string AuthorizationCode, string ClientID, string ClientSecret)
        {
            string URL        = "https://www.dailymotion.com/oauth/authorize";
            var    parameters = new Dictionary <string, string>();

            parameters.Add("grant_type", ResponseType.authorization_code.ToString());
            parameters.Add("client_id", ClientID);
            parameters.Add("client_secret", ClientSecret);
            parameters.Add("redirect_uri", "https://unlimitedillegal.altervista.org/Dailymotion/app.html");
            parameters.Add("code", AuthorizationCode);

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                var HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new Uri(URL + Utilitiez.AsQueryString(parameters)));
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    var TheRsult = JsonConvert.DeserializeObject <JSON_ExchangingVerificationCodeForToken>(result, JSONhandler);
                    if (response.IsSuccessStatusCode)
                    {
                        return(TheRsult);
                    }
                    else
                    {
                        throw new DailymotionException(TheRsult._ErrorMessage, (int)response.StatusCode);
                    }
                }
            }
        }
Ejemplo n.º 15
0
        public async Task <JSON_RemoteUpload> UploadRemote(string VideoUrl, string VideoTitle, List <string> VideoTags = null, ChannelsEnum?VideoChannel = null, PrivacyEnum?Privacy = null)
        {
            var parameters = new Dictionary <string, string>();

            parameters.Add("url", VideoUrl);
            parameters.Add("title", VideoTitle);
            //if (VideoTags == null){VideoTags = new List<string>();}
            parameters.Add("tags", VideoTags != null ? string.Join(",", VideoTags) : null);
            parameters.Add("channel", VideoChannel.HasValue ? VideoChannel.ToString() : null);
            if (Privacy.HasValue)
            {
                switch (Privacy)
                {
                case PrivacyEnum.Public:
                    parameters.Add("published", "1");
                    parameters.Add("private", "0");
                    break;

                case PrivacyEnum.Private:
                    parameters.Add("published", "0");
                    parameters.Add("private", "1");
                    break;
                }
            }

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage  HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/me/videos", parameters.RemoveEmptyValues()));
                HttpResponseMessage ResPonse      = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false);

                var result = await ResPonse.Content.ReadAsStringAsync();

                return(ResPonse.IsSuccessStatusCode ? JsonConvert.DeserializeObject <JSON_RemoteUpload>(result, JSONhandler) : throw ShowError(result));
            }
        }
Ejemplo n.º 16
0
        public async Task <JSON_FolderMetadata> CreateIfNotExists(string FolderName)
        {
            var parameters = new AuthDictionary
            {
                { "folderid", FolderID.ToString() },
                { "name", FolderName }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/createfolderifnotexists"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters);
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(JsonConvert.DeserializeObject <JSON_FolderMetadata>(JObject.Parse(result).SelectToken("metadata").ToString(), JSONhandler));
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 17
0
        public async Task <string> Public(int?MaxDownloads = null, long?MaxTrafficInBytes = null)
        {
            var parameters = new AuthDictionary
            {
                { "fileid", FileID.ToString() },
                { "maxdownloads", MaxDownloads.HasValue?MaxDownloads.Value.ToString():null },
                { "maxtraffic", MaxTrafficInBytes.HasValue  ? MaxTrafficInBytes.Value.ToString() : null }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/getfilepublink"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters.RemoveEmptyValues());
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(JObject.Parse(result).SelectToken("link").ToString().Replace(@"\", string.Empty));
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 18
0
        public async Task <bool> Copy(long DestinationFolderID, bool AutoRename)
        {
            var parameters = new AuthDictionary
            {
                { "fileid", string.Join(",", FileIDs) },
                { "tofolderid", DestinationFolderID.ToString() },
                { "noover", AutoRename ? "1" : null }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/copyfile"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters.RemoveEmptyValues());
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(true);
                    }
                    else
                    {
                        ShowError(result);
                        return(false);
                    }
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// get auth token from email and passeord
        /// </summary>
        public static async Task <string> GetAuthToken(string Email, string Password)
        {
            var parameters = new AuthDictionary();

            parameters.Add("username", WebUtility.UrlEncode(Email));
            parameters.Add("password", WebUtility.UrlEncode(Password));
            parameters.Add("getauth", "1");
            parameters.Add("logout", "1");

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/userinfo"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters);
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(JObject.Parse(result).SelectToken("auth").ToString());
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 20
0
        public async Task <Dictionary <long, string> > ThumbnailUrl(string WIDTH_x_HEIGHT, ExtEnum Ext, bool Crop)
        {
            var parameters = new AuthDictionary()
            {
                { "fileids", string.Join(",", FileIDs) }, { "size", WIDTH_x_HEIGHT }, { "type", Ext.ToString() }
            };

            if (Crop)
            {
                parameters.Add("crop", "1");
            }

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/getthumbslinks"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters);
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        Dictionary <long, string> addationStatus = new Dictionary <long, string>();
                        JObject.Parse(result).SelectToken("thumbs").ToList().ForEach(x => addationStatus.Add(x.Value <long>("fileid"), x.Value <int>("result").Equals(0) ? string.Format("https://{0}{1}", x.SelectToken("hosts").ToList().First(), x.Value <string>("path")) : x.Value <string>("error")));
                        return(addationStatus);
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 21
0
        public async Task <string> FileInFolderDirectUrl(Uri folderpubliclink, long fileid)
        {
            var parameters = new AuthDictionary {
                { "code", folderpubliclink.GetParameterInUrl("code") }, { "fileid", fileid.ToString() }, { "forcedownload", "1" }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/getfilepublink"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters.RemoveEmptyValues());
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(string.Format("https://{0}{1}", JObject.Parse(result).SelectToken("hosts[0]").ToString(), JObject.Parse(result).SelectToken("path").ToString().Replace(@"\", string.Empty)));
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 22
0
        public async Task <JSON_FileMetadata> CopyZip(Uri publiclink, long DestinationFolderID, string RenameTo = null)
        {
            var parameters = new AuthDictionary {
                { "code", publiclink.GetParameterInUrl("code") }, { "tofolderid", DestinationFolderID.ToString() }
            };

            if (!string.IsNullOrEmpty(RenameTo))
            {
                parameters.Add("toname", RenameTo.ToLower().EndsWith(".zip") ? RenameTo : $"{RenameTo}.zip");
            }

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/savepubzip"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters.RemoveEmptyValues());
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(JsonConvert.DeserializeObject <JSON_FileMetadata>(JObject.Parse(result).SelectToken("metadata").ToString(), JSONhandler));
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// https://secure.backblaze.com/app_keys.htm   ?bznetid=5282715381565789718559
        /// https://www.backblaze.com/b2/docs/b2_authorize_account.html
        /// </summary>
        /// <param name="Key_ID">ApplicationKeyID OR accountID</param>
        /// <param name="Application_Key">ApplicationKey</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static async Task <JSON_AuthorizeAccount> GetToken_24Hrs(string Key_ID, string Application_Key)
        {
            ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                localHttpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.Default.GetBytes($"{Key_ID}:{Application_Key}")));

                var HtpReqMessage = new HttpRequestMessage(HttpMethod.Get, new Uri("https://api.backblazeb2.com/b2api/v2/b2_authorize_account"));
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        var userInfo = JsonConvert.DeserializeObject <JSON_AuthorizeAccount>(result, JSONhandler);
                        userInfo.JSON = Newtonsoft.Json.Linq.JToken.Parse(result);
                        return(userInfo);
                    }
                    else
                    {
                        throw new BackBlazeException(response.ReasonPhrase, (int)response.StatusCode);
                    }
                }
            }
        }
Ejemplo n.º 24
0
        public async Task <List <JSON_VideoResolutions> > VideoResolutionUrls()
        {
            var parameters = new AuthDictionary()
            {
                { "fileid", FileID.ToString() }, { "forcedownload", "1" }, { "skipfilename", "false" }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/getvideolinks"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters);
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(JsonConvert.DeserializeObject <List <JSON_VideoResolutions> >(JObject.Parse(result).SelectToken("variants").ToString(), JSONhandler));
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 25
0
        public static async Task <JSON_ExchangingVerificationCodeForToken> RenewExpiredToken(string TheRefreshToken, string ClientID, string ClientSecret)
        {
            string URL        = "https://api.dailymotion.com/oauth/token";
            var    parameters = new Dictionary <string, string>
            {
                { "grant_type", ResponseType.refresh_token.ToString() },
                { "client_id", ClientID },
                { "client_secret", ClientSecret },
                { "refresh_token", TheRefreshToken }
            };
            var encodedContent = new FormUrlEncodedContent(parameters);

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                var HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new Uri(URL))
                {
                    Content = encodedContent
                };
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    var TheRsult = JsonConvert.DeserializeObject <JSON_ExchangingVerificationCodeForToken>(result);
                    if (response.IsSuccessStatusCode)
                    {
                        return(TheRsult);
                    }
                    else
                    {
                        throw new DailymotionException(TheRsult._ErrorMessage, (int)response.StatusCode);
                    }
                }
            }
        }
Ejemplo n.º 26
0
        public async Task <Uri> VideoToMp3(int AudioBitRate)
        {
            var parameters = new AuthDictionary()
            {
                { "fileid", FileID.ToString() }, { "abitrate", AudioBitRate.ToString() }, { "forcedownload", "1" }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/getaudiolink"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters);
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(new Uri(string.Format("https://{0}{1}", JObject.Parse(result).SelectToken("hosts[0]").ToString(), JObject.Parse(result).SelectToken("path").ToString().Replace(@"\", string.Empty))));
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 27
0
        public async Task <JSON_List> List(string DestinationBucketID, string StartWith = null, string Contains = null, string DelimiterMark = null, int Limit = 999)
        {
            var parameters = new Dictionary <object, object>();

            parameters.Add("bucketId", DestinationBucketID);
            parameters.Add("startFileName", StartWith);
            parameters.Add("prefix", Contains);
            if (DelimiterMark != null)
            {
                parameters.Add("delimiter", DelimiterMark);
            }
            parameters.Add("maxFileCount", Limit);

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                var HtpReqMessage = new HtpRequestMessage(HttpMethod.Post, new pUri("b2_list_file_names"))
                {
                    Content = SerializeDictionary(parameters)
                };
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    return(response.StatusCode == HttpStatusCode.OK ? JsonConvert.DeserializeObject <JSON_List>(result, JSONhandler) : throw ShowError(result, (int)response.StatusCode));
                }
            }
        }
Ejemplo n.º 28
0
        public async Task <string> UnCompressAsync(long ExtractIntoFolderID, string ArchivePassword = null, IfExistsEnum IfExists = IfExistsEnum.rename)
        {
            var GeneJobID  = RandomString(8);
            var parameters = new AuthDictionary
            {
                { "password", ArchivePassword ?? null },
                { "tofolderid", ExtractIntoFolderID.ToString() },
                { "nooutput", "1" },
                { "overwrite", IfExists.ToString() },
                { "progresshash", GeneJobID }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/extractarchive"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters.RemoveEmptyValues());
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(GeneJobID);
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 29
0
        public static async Task <string> OneHourToken(string Username, string Password, string CaptchaWord = null, string ChallengeID = null)
        {
            ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("login"));
                var JSONobj = new { username = Username, password = Password, captcha_challenge = ChallengeID, captcha_response = CaptchaWord };
                HtpReqMessage.Content = JSONobj.JsonContent();
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (JObject.Parse(result).SelectToken("status").ToString() == "success")
                    {
                        return(JObject.Parse(result).SelectToken("auth_token").ToString());
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 30
0
        public async Task DownloadAsZip(Uri publiclink, string FileSaveDir, IProgress <ReportStatus> ReportCls = null, CancellationToken token = default)
        {
            string FileName = $"pCloudPublicLink_{Utilitiez.RandomString(3)}.zip";

            ReportCls = ReportCls ?? new Progress <ReportStatus>();
            ReportCls.Report(new ReportStatus {
                Finished = false, TextStatus = "Initializing..."
            });
            try
            {
                var progressHandler = new ProgressMessageHandler(new HCHandler());
                progressHandler.HttpReceiveProgress += (sender, e) => { ReportCls.Report(new ReportStatus {
                        ProgressPercentage = e.ProgressPercentage, BytesTransferred = e.BytesTransferred, TotalBytes = e.TotalBytes ?? 0, TextStatus = "Downloading..."
                    }); };
                var localHttpClient = new HtpClient(progressHandler);
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Get, new pUri("/getpubzip", new AuthDictionary()
                {
                    { "code", publiclink.GetParameterInUrl("code") }, { "filename", FileName }
                }));

                using (HttpResponseMessage ResPonse = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead, token).ConfigureAwait(false))
                {
                    if (ResPonse.IsSuccessStatusCode)
                    {
                        ReportCls.Report(new ReportStatus {
                            Finished = true, TextStatus = $"[{FileName}] Downloaded successfully."
                        });
                    }
                    else
                    {
                        ReportCls.Report(new ReportStatus {
                            Finished = true, TextStatus = $"Error code: {ResPonse.StatusCode}"
                        });
                    }
                    ResPonse.EnsureSuccessStatusCode();
                    Stream stream_ = await ResPonse.Content.ReadAsStreamAsync();

                    var FPathname = Path.Combine(FileSaveDir, FileName);
                    using (FileStream fileStream = new FileStream(FPathname, FileMode.Append, FileAccess.Write))
                    {
                        stream_.CopyTo(fileStream);
                    }
                }
            }
            catch (Exception ex)
            {
                ReportCls.Report(new ReportStatus {
                    Finished = true
                });
                if (!ex.Message.ToString().ToLower().Contains("a task was canceled"))
                {
                    throw new pCloudException(ex.Message, 1001);
                }
                ReportCls.Report(new ReportStatus {
                    TextStatus = ex.Message
                });
            }
        }