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

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                using (HttpResponseMessage response = await localHttpClient.GetAsync(new pUri("/downloadfile", parameters), 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);
                    }
                }
            }
        }
Exemplo n.º 2
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));
                }
            }
        }
Exemplo n.º 3
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));
            }
        }
Exemplo n.º 4
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);
                    }
                }
            }
        }
Exemplo n.º 5
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);
                    }
                }
            }
        }
Exemplo n.º 6
0
        public async Task <List <JSON_Entry> > ChangesHistory()
        {
            var parameters = new AuthDictionary()
            {
                { "fileid", FileID.ToString() }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                using (HttpResponseMessage response = await localHttpClient.GetAsync(new pUri("/getfilehistory", parameters), 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_Entry> >(JObject.Parse(result).SelectToken("entries").ToString(), JSONhandler));
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Exemplo n.º 7
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);
                    }
                }
            }
        }
Exemplo n.º 8
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);
                    }
                }
            }
        }
Exemplo n.º 9
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);
                    }
                }
            }
        }
Exemplo n.º 10
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);
                    }
                }
            }
        }
Exemplo n.º 11
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);
                    }
                }
            }
        }
Exemplo n.º 12
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);
                }
            }
        }
Exemplo n.º 13
0
        public async Task <JSON_ListPushes> ListContinue(string Cursor, int Limit)
        {
            var parameters = new Dictionary <string, string>()
            {
                { "active", "true" }, { "limit", Limit.ToString() }, { "cursor", Cursor }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                var RequestUri = new pUri("pushes", parameters);
                using (HttpResponseMessage resPonse = await localHttpClient.GetAsync(RequestUri).ConfigureAwait(false))
                {
                    string result = await resPonse.Content.ReadAsStringAsync();

                    if (resPonse.StatusCode == HttpStatusCode.OK)
                    {
                        var FinRes = JsonConvert.DeserializeObject <JSON_ListPushes>(result, JSONhandler);
                        // FinRes.ApiLimits = GetApiLimits(resPonse)
                        return(FinRes);
                    }
                    else
                    {
                        ShowError(result);
                    }

                    return(null);
                }
            }
        }
Exemplo n.º 14
0
        public async Task <JSON_JobProgress> CompressTaskProgress(string JobID)
        {
            IClient client   = new PClient(Username, Password, ConnectionSetting);
            var     TheDomin = (await client.Account().GetCurrentServer()).hostname;

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                using (HttpResponseMessage response = await localHttpClient.GetAsync(new Uri(string.Format("https://{0}/savezipprogress", TheDomin) + AsQueryString(new AuthDictionary()
                {
                    { "progresshash", JobID }
                })), 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_JobProgress>(result, JSONhandler));
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Exemplo n.º 15
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);
                    }
                }
            }
        }
Exemplo n.º 16
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);
                    }
                }
            }
        }
Exemplo n.º 17
0
        public async Task <bool> UnCompressTaskProgress(string JobID)
        {
            IClient clint    = new PClient(Username, Password, ConnectionSetting);
            var     TheDomin = (await clint.Account().GetCurrentServer()).hostname;

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                using (HttpResponseMessage response = await localHttpClient.GetAsync(new Uri(string.Format("https://{0}/extractarchiveprogress", TheDomin) + AsQueryString(new AuthDictionary()
                {
                    { "progresshash", JobID }
                })), System.Net.Http.HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(Convert.ToBoolean(JObject.Parse(result).SelectToken("finished").ToString()));
                    }
                    else
                    {
                        ShowError(result);
                        return(false);
                    }
                }
            }
        }
Exemplo 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);
                    }
                }
            }
        }
Exemplo n.º 19
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);
                    }
                }
            }
        }
Exemplo n.º 20
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);
                    }
                }
            }
        }
Exemplo n.º 21
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);
                    }
                }
            }
        }
Exemplo n.º 22
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);
                    }
                }
            }
        }
Exemplo 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);
                    }
                }
            }
        }
Exemplo n.º 24
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);
                    }
                }
            }
        }
Exemplo n.º 25
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);
                    }
                }
            }
        }
Exemplo n.º 26
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);
                    }
                }
            }
        }
Exemplo n.º 27
0
        public static async Task <JSON_GetVideoDirectLink> VideoDirectLink(string VideoID)
        {
            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                var RequestUri = new Uri($"https://www.dailymotion.com/embed/video/{VideoID}");
                HttpResponseMessage ResPonse = await localHttpClient.GetAsync(RequestUri).ConfigureAwait(false);

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

                if (ResPonse.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    string partONE         = "var config = {";
                    string partTWO         = "};";
                    var    ExtractTheDlink = Between(result, partONE, partTWO);
                    ExtractTheDlink = string.Concat("{", ExtractTheDlink, "}");
                    var TheRsult = JsonConvert.DeserializeObject <JSON_GetVideoDirectLink>(ExtractTheDlink, JSONhandler);

                    if (TheRsult.metadata.qualities.auto == null)
                    {
                        throw new DailymotionException("video maybe private or password protected", (int)ResPonse.StatusCode);
                    }
                    TheRsult.VideoResolutionUrls = await FormatDirectLnks(TheRsult.metadata.qualities.auto[0].url);

                    return(TheRsult);
                }
                else
                {
                    throw new DailymotionException(ResPonse.ReasonPhrase, (int)ResPonse.StatusCode);
                }
            }
        }
Exemplo n.º 28
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);
                    }
                }
            }
        }
Exemplo n.º 29
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);
                    }
                }
            }
        }
Exemplo n.º 30
0
        public async Task <JSON_FileMetadata> UploadRemote(string UrlToUP, string Filename = null)
        {
            var parameters = new AuthDictionary
            {
                { "url", UrlToUP },
                { "folderid", FolderID.ToString() },
                { "target", Filename }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                using (HttpResponseMessage response = await localHttpClient.GetAsync(new pUri("/downloadfile", parameters), 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).Value <JSON_FileMetadata>("metadata"));
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }