Exemplo n.º 1
0
        private void donetimer_Tick(object sender, EventArgs e)
        {
            /* Updates the process for the end user */

            //Set volume to Zero, otherwise the user will hear Plays.tv in the background because of gecko
            waveOutSetVolume(IntPtr.Zero, 0);


            if (done4)
            {
                //DONE
                Infotimer.Stop();
                donetimer.Stop();
                step4.ForeColor       = Color.Lime;
                loadingind.Image      = Properties.Resources.checkmark_96px;
                downloadingrn.Visible = true;
                downloadingrn.Text    = "Done!";
                infolbl.Show();
                infolbl.Text = "Please consider donating if you support this project";
                didyouknow.Hide();
                paypal.Show();
                geckoWebBrowser.Dispose();
            }
            else if (done3)
            {
                //Stage 3
                if (videosfound != 0 && continuenow == false)
                {
                    continuenow = true;
                }
                else
                {
                    step3.ForeColor       = Color.Lime;
                    downloadingrn.Visible = true;
                    downloadingrn.Text    = "Downloaded: " + (downdone) + "/" + videosfound;

                    if ((downdone == videosfound) && (Math.Round(downloadeddone) == Math.Round(downloaded)))
                    {
                        done4 = true;
                    }
                }
            }
            else if (done2)
            {
                //Stage 2
                step2.ForeColor       = Color.Lime;
                downloadingrn.Visible = true;
                if (!downloadingrn.Text.Contains("Retrying:"))
                {
                    if (!downloadingrn.Text.Contains("Plays servers are slow today..."))
                    {
                        downloadingrn.Text = "Loading...";
                    }
                }
            }
            else if (done1)
            {
                //Stage 1
                step1.ForeColor       = Color.Lime;
                downloadingrn.Visible = true;
                downloadingrn.Text    = "Logging in...";
            }
        }
Exemplo n.º 2
0
        private async Task Load1SiteAsync()
        {
            //Navigates to the homescreen and sets a SAFE delay
            await PutTaskDelay(5000);

            geckoWebBrowser.Navigate("https://plays.tv/home");
            done1 = true;

            string linkredirect = "";

            while (linkredirect == "")
            {
                await PutTaskDelay(5000);

                //Checks if the user is logged in or not
                GeckoNodeCollection links = geckoWebBrowser.Document.GetElementsByClassName("avatar");

                foreach (GeckoElement link in links)
                {
                    try
                    {
                        if (link.GetAttribute("href").Length > 0)
                        {
                            linkredirect = link.GetAttribute("href");
                        }
                    }
                    catch
                    {
                    }
                }
                if (linkredirect != "")
                {
                    break;
                }
                else
                {
                    geckoWebBrowser.Navigate("https://plays.tv/home");
                    await PutTaskDelay(10000);
                }
            }

            //Redirects to users home video
            geckoWebBrowser.Navigate("https://plays.tv" + linkredirect);
            await PutTaskDelay(5000);

            done2 = true;

            //Gets users ID
            GeckoElement VideoJSONtemp;

            while (true)
            {
                try
                {
                    VideoJSONtemp = (GeckoElement)geckoWebBrowser.Document.GetElementsByClassName("full-width header-profile")[0];
                    break;
                }
                catch
                {
                    setTextSafe("Plays servers are slow today. Still loading...");
                    await PutTaskDelay(3000);
                }
            }
            string  JSON    = Convert.ToString(VideoJSONtemp.GetAttribute("data-conf"));
            dynamic details = JValue.Parse(JSON);

            //Navigates to the JSON file (With a webclient the JSON would only show published videos)
            geckoWebBrowser.Navigate("https://plays.tv/playsapi/feedsys/v1/userfeed/" + details.login_user.id + "/uploaded?limit=999999");
            await PutTaskDelay(5000);

            string JSONformated = "";
            int    retrying     = 0;

            while (retrying < 100)
            {
                //Tries to get the JSON, you need to be logged in to get unlisted videos
                try
                {
                    string JSONunformated = geckoWebBrowser.Document.Body.OuterHtml;
                    if (!JSONunformated.Contains("</pre></body>"))
                    {
                        retrying++;
                        setTextSafe("Retrying: " + retrying + "/100");
                        await PutTaskDelay(3500);
                    }
                    else
                    {
                        JSONformated = JSONunformated.Replace("</pre></body>", "").Replace("<body><pre>", "");
                        break;
                    }
                }
                catch
                {
                    retrying++;
                    setTextSafe("Retrying: " + retrying + "/100");
                    await PutTaskDelay(3500);
                }
            }
            if (retrying > 100)
            {
                MessageBox.Show("Can't access Plays.TV api...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                System.Diagnostics.Process.Start(Application.ExecutablePath); // to start new instance of application
                this.Close();
            }

            //Gets the JSON from Plays api
            dynamic videoJSON = JValue.Parse(JSONformated);
            JArray  items     = (JArray)videoJSON["items"];

            //Creates a list that hold video information
            List <string> nameList         = new List <string>();
            List <string> downloadlinkList = new List <string>();
            List <string> typeList         = new List <string>();
            List <string> gameList         = new List <string>();
            List <string> descriptionList  = new List <string>();
            List <string> dateList         = new List <string>();

            for (int i = 0; i < items.Count; i++)
            {
                dynamic item     = (JObject)items[i];
                bool    unlisted = item.unlisted;

                //Get video information
                string name         = item.description;
                string downloadlink = item.downloadUrl;
                string type         = item.type;
                string game         = item.gameTitle;
                string description  = item.description;
                string date         = item.created;

                if ((dntscreenshots.Checked == true) && (type.Contains("image") == true))
                {
                }
                else
                {
                    if (unlisted == true && publiconly == true)
                    {
                    }
                    else
                    {
                        nameList.Add(name);
                        downloadlinkList.Add(downloadlink);
                        typeList.Add(type);
                        gameList.Add(game);
                        descriptionList.Add(description);
                        dateList.Add(Convert.ToString(date).Replace("000", ""));
                    }
                }

                //Inserts information to Did you know
                JObject res  = (JObject)items[i];
                double  secc = Convert.ToDouble(item.duration);
                infoclipseconds += Convert.ToDouble(secc);
                infoviews       += (int)res["stats"]["clicks"];
                infocomments    += (int)res["stats"]["comments"];
                double dateUnix = Convert.ToDouble(Convert.ToString(item.created).Replace("000", ""));
                infofirstplays = UnixTimeStampToDateTime(dateUnix);
            }
            //Adds the total videos the a integer that the end user will see
            videosfound = nameList.Count;

            done3 = true;

            //First did you know
            Infotimer.Start();
            infolbl.Text = "Did you know:";
            infolbl.Show();
            didyouknow.Text = "The first Plays.tv video was uploaded 03/09/2015 by Plays";
            didyouknow.Show();

            for (int i = 0; i < nameList.Count; i++)
            {
                curdown = i;

                //Adds SORT BY DATE
                if (rbUD.Checked)
                {
                    sort = "[" + (i + 1) + "] ";
                }
                if (incDate.Checked)
                {
                    if (paranthesiscbx.Checked == true)
                    {
                        dateString = (" (" + (UnixTimeStampToDateTime(Convert.ToDouble(dateList[i]))).ToShortDateString() + ")").Replace("/", "-");
                    }
                    else
                    {
                        dateString = (" " + (UnixTimeStampToDateTime(Convert.ToDouble(dateList[i]))).ToShortDateString()).Replace("/", "-");
                    }
                }

                //Gets current video information
                string name         = Convert.ToString(nameList[i]);
                string downloadlink = Convert.ToString(downloadlinkList[i]);
                string game         = Convert.ToString(gameList[i]);
                string description  = Convert.ToString(descriptionList[i]);
                string type         = Convert.ToString(typeList[i]);



                //Tries to get the game if the description is the name of the game.
                if (game == null)
                {
                    if (gameList.Contains(description))
                    {
                        game = description;
                    }
                    else
                    {
                        game = "Unknown";
                    }
                }



                //Replaces bad names
                Regex illegalName = new Regex(@"[\\/:*?""<>|]");
                name       = illegalName.Replace(name, "_");
                dateString = illegalName.Replace(dateString, "_");
                game       = illegalName.Replace(game, " ");


                try
                {
                    //Checks if it's an image or not
                    if (type == "image")
                    {
                        //If the user wants screenshots or not
                        if (incscreenshots.Checked == true)
                        {
                            //If the user wants it to be put into game-folders
                            if (includeGameFolders.Checked)
                            {
                                if (!Directory.Exists(path + @"\" + game))
                                {
                                    Directory.CreateDirectory(path + @"\" + game);
                                }
                                if (rbUD.Checked)
                                {
                                    sort = "[" + (Directory.GetFiles(path + @"\" + game).Length + 1) + "] ";
                                }

                                if (!File.Exists(path + @"\" + game + @"\" + sort + name + dateString + ".jpeg"))
                                {
                                    DownloadFile(downloadlink, path + @"\" + game + @"\" + sort + name + dateString + ".jpeg");
                                    break;
                                }
                                else
                                {
                                    int addIfExists = 1;
                                    while (true)
                                    {
                                        if (!File.Exists(path + @"\" + game + @"\" + sort + name + "(" + addIfExists + ")" + dateString + ".jpeg"))
                                        {
                                            DownloadFile(downloadlink, path + @"\" + game + @"\" + sort + name + "(" + addIfExists + ")" + dateString + ".jpeg");
                                            break;
                                        }
                                        else
                                        {
                                            addIfExists++;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (!File.Exists(path + @"\" + sort + name + dateString + ".jpeg"))
                                {
                                    DownloadFile(downloadlink, path + @"\" + sort + name + dateString + ".jpeg");
                                }
                                else
                                {
                                    int addIfExists = 1;
                                    while (true)
                                    {
                                        if (!File.Exists(path + @"\" + sort + name + "(" + addIfExists + ")" + dateString + ".jpeg"))
                                        {
                                            DownloadFile(downloadlink, path + @"\" + sort + name + "(" + addIfExists + ")" + dateString + ".jpeg");
                                            break;
                                        }
                                        else
                                        {
                                            addIfExists++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (includeGameFolders.Checked)
                        {
                            if (!Directory.Exists(path + @"\" + game))
                            {
                                Directory.CreateDirectory(path + @"\" + game);
                            }
                            if (rbUD.Checked)
                            {
                                sort = "[" + (Directory.GetFiles(path + @"\" + game).Length + 1) + "] ";
                            }

                            if (!File.Exists(path + @"\" + game + @"\" + sort + name + dateString + ".mp4"))
                            {
                                DownloadFile(downloadlink, path + @"\" + game + @"\" + sort + name + dateString + ".mp4");
                            }
                            else
                            {
                                int addIfExists = 1;
                                while (true)
                                {
                                    if (!File.Exists(path + @"\" + game + @"\" + sort + name + "(" + addIfExists + ")" + dateString + ".mp4"))
                                    {
                                        DownloadFile(downloadlink, path + @"\" + game + @"\" + sort + name + "(" + addIfExists + ")" + dateString + ".mp4");
                                        break;
                                    }
                                    else
                                    {
                                        addIfExists++;
                                    }
                                }
                            }
                        }
                        else
                        {
                            // DownloadFile(downloadlink, path + @"\" + sort + name + dateString + ".mp4");
                            if (!File.Exists(path + @"\" + sort + name + dateString + ".mp4"))
                            {
                                DownloadFile(downloadlink, path + @"\" + sort + name + dateString + ".mp4");
                            }
                            else
                            {
                                int addIfExists = 1;
                                while (true)
                                {
                                    if (!File.Exists(path + @"\" + sort + name + "(" + addIfExists + ")" + dateString + ".mp4"))
                                    {
                                        DownloadFile(downloadlink, path + @"\" + sort + name + "(" + addIfExists + ")" + dateString + ".mp4");
                                        break;
                                    }
                                    else
                                    {
                                        addIfExists++;
                                    }
                                }
                            }
                        }
                    }
                }
                catch
                {
                    //If an error occured.
                    MessageBox.Show("Plays did not provide any download link to the video called: " + name + "\nYou will need to download it manually.\nClick OK to continue downloading the rest of the videos.", "Error.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                await PutTaskDelay(3000);
            }
        }