public static async Task <bool> PostDataAboutId(int id, AniListStatusType type, int score, int progress) { const string q = @"mutation ($id: Int, $status: MediaListStatus, $scoreRaw: Int, $progress: Int) { SaveMediaListEntry (mediaId: $id, status: $status, scoreRaw: $scoreRaw, progress: $progress) { id status progress score } }&variables={ ""id"": {0}, ""status"":""{1}"", ""scoreRaw"":{2}, ""progress"":{3} }" ; try { var fullQ = ($"&query={q}") .Replace("{0}", id.ToString()) .Replace("{1}", AniListStatusString[(int)type]) .Replace("{2}", (score * 10).ToString()) .Replace("{3}", progress.ToString()); CloudStreamCore.print(fullQ); var data = await PostApi("https://graphql.anilist.co", fullQ ); //"{\"data\":{\"SaveMediaListEntry\":{\"id\":144884500,\"status\":\"PLANNING\",\"progress\":8,\"score\":7}}}" return(data != ""); } catch (Exception) { return(false); } }
public static async Task <AniListTitleHolder?> GetDataAboutId(int id) { const string q = @"query ($id: Int) { # Define which variables will be used in the query (id) Media (id: $id, type: ANIME) { # Insert our variables into the query arguments (id) (type: ANIME is hard-coded in the query) #id isFavourite mediaListEntry { progress status score (format: POINT_10) } } }&variables={ ""id"":""{0}"" }" ; try { var data = await PostApi("https://graphql.anilist.co", ($"&query={q}").Replace("{0}", id.ToString())); GetDataRoot d = JsonConvert.DeserializeObject <GetDataRoot>(data); var main = d.data.Media; CloudStreamCore.print(data); return(new AniListTitleHolder() { id = id, isFavourite = main.isFavourite, progress = main.mediaListEntry.progress, score = main.mediaListEntry.score, type = (AniListStatusType)AniListStatusString.IndexOf(main.mediaListEntry.status), }); } catch (Exception) { return(null); } }
public static async Task <string> PostRequest(string postdata, DataUpdate _type) { try { string url = Settings.PublishDatabaseServerIp; CloudStreamCore.print("PUBLISHIP: " + url); int waitTime = 400; HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(url); if (CloudStreamCore.GetRequireCert(url)) { webRequest.ServerCertificateValidationCallback = delegate { return(true); }; } webRequest.Method = "POST"; webRequest.UserAgent = "CLOUDSTREAM APP v" + App.GetBuildNumber(); webRequest.Timeout = waitTime * 10; webRequest.ReadWriteTimeout = waitTime * 10; webRequest.ContinueTimeout = waitTime * 10; webRequest.Headers.Add("TYPE", ((int)_type).ToString()); try { HttpWebRequest _webRequest = webRequest; Stream postStream = await _webRequest.GetRequestStreamAsync(); string requestBody = postdata; // --- RequestHeaders --- byte[] byteArray = Encoding.UTF8.GetBytes(requestBody); postStream.Write(byteArray, 0, byteArray.Length); postStream.Close(); // BEGIN RESPONSE try { HttpWebRequest request = webRequest; HttpWebResponse response = (HttpWebResponse)(await webRequest.GetResponseAsync()); using StreamReader httpWebStreamReader = new StreamReader(response.GetResponseStream()); try { string s = await httpWebStreamReader.ReadToEndAsync(); CloudStreamCore.print("RESPONSEF FROM POST::: " + s); } catch (Exception) { return(""); } } catch (Exception _ex) { CloudStreamCore.error("FATAL EX IN POST2: " + _ex); } } catch (Exception _ex) { CloudStreamCore.error("FATAL EX IN POSTREQUEST" + _ex); } return(""); } catch (Exception _ex) { CloudStreamCore.error(_ex); return(""); } }
public static void OpenBrowser(string url) { CloudStreamCore.print("Trying to open: " + url); if (CloudStreamCore.CheckIfURLIsValid(url)) { try { Launcher.OpenAsync(new Uri(url)); } catch (Exception) { CloudStreamCore.print("BROWSER LOADED ERROR, SHOULD NEVER HAPPEND!!"); } } }
public static async Task <string> _PostRequest(string postdata, DataUpdate _type) { try { string url = Settings.PublishDatabaseServerIp; CloudStreamCore.print("PUBLISHIP: " + url); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "POST"; byte[] byteArray = Encoding.UTF8.GetBytes(postdata); request.ContentType = "application/json"; request.ContentLength = byteArray.Length; request.Headers.Add("TYPE", ((int)_type).ToString()); Stream dataStream = await request.GetRequestStreamAsync(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); WebResponse response = await request.GetResponseAsync(); dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = await reader.ReadToEndAsync(); reader.Close(); dataStream.Close(); response.Close(); return(responseFromServer); } catch (WebException e) { CloudStreamCore.error(e); try { using (WebResponse response = e.Response) { HttpWebResponse httpResponse = (HttpWebResponse)response; Console.WriteLine("Error code: {0}", httpResponse.StatusCode); using Stream data = response.GetResponseStream(); using var reader = new StreamReader(data); string text = reader.ReadToEnd(); Console.WriteLine(text); } return(""); } catch (Exception _ex) { CloudStreamCore.error(_ex); return(""); } } catch (Exception _ex) { CloudStreamCore.error(_ex); return(""); } }
public string DownloadUrl(string url, string fileName, bool mainPath, string extraPath, string toast = "", bool isNotification = false, string body = "") { try { string basePath = GetPath(mainPath, extraPath); CloudStreamCore.print(basePath); Java.IO.File _file = new Java.IO.File(basePath); _file.Mkdirs(); basePath += "/" + CensorFilename(fileName); CloudStreamCore.print(basePath); //webClient.DownloadFile(url, basePath); using (WebClient wc = new WebClient()) { wc.DownloadProgressChanged += (o, e) => { App.OnDownloadProgressChanged(basePath, e); /* * if (e.ProgressPercentage == 100) { * App.ShowToast("Download Successful"); * //OpenFile(basePath); * }*/ // print(e.ProgressPercentage + "|" + basePath); }; wc.DownloadFileCompleted += (o, e) => { if (toast != "") { if (isNotification) { App.ShowNotification(toast, body); } else { App.ShowToast(toast); } } }; wc.DownloadFileAsync( // Param1 = Link of file new System.Uri(url), // Param2 = Path to save basePath ); } } catch (Exception) { App.ShowToast("Download Failed"); return(""); } return(GetPath(mainPath, extraPath) + "/" + CensorFilename(fileName)); }
public static void SetKey(string folder, string name, object value) { string path = GetKeyPath(folder, name); string _set = ConvertToString(value); if (myApp.Properties.ContainsKey(path)) { CloudStreamCore.print("CONTAINS KEY"); myApp.Properties[path] = _set; } else { CloudStreamCore.print("ADD KEY"); myApp.Properties.Add(path, _set); } }
public static T GetKey <T>(string path, T defVal) { try { if (myApp.Properties.ContainsKey(path)) { CloudStreamCore.print("GETKEY::" + myApp.Properties[path]); CloudStreamCore.print("GETKEY::" + typeof(T).ToString() + "||" + ConvertToObject <T>(myApp.Properties[path] as string, defVal)); return((T)ConvertToObject <T>(myApp.Properties[path] as string, defVal)); } else { return(defVal); } } catch (Exception) { return(defVal); } }
public static async Task OpenPathsAsVideo(List <string> path, List <string> name, string subtitleLoc) { string absolutePath = Android.OS.Environment.ExternalStorageDirectory + "/" + Android.OS.Environment.DirectoryDownloads; CloudStreamCore.print("AVS: " + absolutePath); bool subtitlesEnabled = subtitleLoc != ""; string writeData = CloudStreamForms.App.ConvertPathAndNameToM3U8(path, name, subtitlesEnabled, "content://" + absolutePath + "/"); Java.IO.File subFile = null; WriteFile(CloudStreamForms.App.baseM3u8Name, absolutePath, writeData); if (subtitlesEnabled) { subFile = WriteFile(CloudStreamForms.App.baseSubtitleName, absolutePath, subtitleLoc); } // await Task.Delay(5000); Device.BeginInvokeOnMainThread(() => { // OpenPathAsVideo(path.First(), name.First(), ""); OpenVlcIntent(absolutePath + "/" + CloudStreamForms.App.baseM3u8Name, absolutePath + "/" + App.baseSubtitleName); }); }
public static Java.IO.File WriteFile(string name, string basePath, string write) { try { File.Delete(basePath + "/" + name); } catch (System.Exception) { } //name = Regex.Replace(name, @"[^A-Za-z0-9\.]+", String.Empty); //name.Replace(" ", ""); // name = name.ToLower(); Java.IO.File file = new Java.IO.File(basePath, name); Java.IO.File _file = new Java.IO.File(basePath); CloudStreamCore.print("PATH: " + basePath + "/" + name); _file.Mkdirs(); file.CreateNewFile(); Java.IO.FileWriter writer = new Java.IO.FileWriter(file); // Writes the content to the file writer.Write(write); writer.Flush(); writer.Close(); return(file); }
public string DownloadUrl(string url, string fileName, bool mainPath, string extraPath, string toast = "", bool isNotification = false, string body = "") { CloudStreamCore.print(fileName); string basePath = GetPath(fileName); try { //webClient.DownloadFile(url, basePath); using (WebClient wc = new WebClient()) { wc.DownloadProgressChanged += (o, e) => { _App.OnDownloadProgressChanged(basePath, e); /* * if (e.ProgressPercentage == 100) { * App.ShowToast("Download Successful"); * //OpenFile(basePath); * }*/ // print(e.ProgressPercentage + "|" + basePath); }; wc.DownloadFileCompleted += (o, e) => { if (toast != "") { if (isNotification) { _App.ShowNotification(toast, body); } else { ShowToast(toast, 2.5); } } }; wc.DownloadFileAsync( // Param1 = Link of file new System.Uri(url), // Param2 = Path to save basePath ); } } catch (Exception) { print("PROGRESS FAILED"); _App.ShowToast("Download Failed"); return(""); } return(basePath); try { TempThred tempThred = new TempThred(); tempThred.typeId = 4; // MAKE SURE THIS IS BEFORE YOU CREATE THE THRED tempThred.Thread = new System.Threading.Thread(() => { try { WebClient webClient = new WebClient(); byte[] data = webClient.DownloadData(url); DownloadFile(data, fileName, mainPath, extraPath); //if (!GetThredActive(tempThred)) { return; }; // COPY UPDATE PROGRESS } finally { JoinThred(tempThred); } }); tempThred.Thread.Name = "Download Thread"; tempThred.Thread.Start(); return(GetPath(fileName)); } catch (Exception) { CloudStreamForms.App.ShowToast("Download Failed"); return(""); } }
// Invoked when background is clicked protected override bool OnBackgroundClicked() { CloudStreamCore.print("BG"); // Return false if you don't want to close this popup page when a background of the popup page is clicked return(base.OnBackgroundClicked()); }