Ejemplo n.º 1
0
        public static decimal getCloudVersion()
        {
            try {
                string xml = getJSON(githubJSON);
                if (xml == null)
                {
                    return(-1);
                }

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);
                XmlNodeList xmlTag = doc.DocumentElement.SelectNodes("/root/tag_name");

                return(decimal.Parse(xmlTag[0].InnerText));
            }
            catch (WebException wEx) {
                Debug.Print(wEx.ToString());
                ErrorLog.logError(wEx.ToString(), "UpdateCheckError");
                return(-1);
            }
            catch (Exception ex) {
                Debug.Print(ex.ToString());
                ErrorLog.logError(ex.ToString(), "UpdateCheckError");
                return(-1);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts a file.
        /// </summary>
        /// <param name="inputFile">The file that will be used as the input.</param>
        /// <param name="outputFile">The file that will be outputed as the converted file.</param>
        /// <param name="convType">The Conversion type. (0 = Video, 1 = Audio)</param>
        /// <param name="convFormat">The format it will be converted to.</param>
        /// <param name="cvAudQuality">The quality of the new audio.</param>
        /// <param name="cvResolution">The resolution that the video will be converted to.</param>
        /// <returns></returns>
        public static bool convert(string inputFile, string outputFile, int convType, string convFormat, int cvAudQuality = 0, int cvResolution = 0, int cvBit = 18)
        {
            try {
                Process Converter = new Process();
                Converter.StartInfo.FileName = "ffmpeg.exe";
                string args = "-i ";

                if (convType == 0)
                {
                    // Video
                    if (cvResolution == 0)
                    {
                        return(false);
                    }

                    args += "\"" + inputFile + "\" -vf scale=-1:" + cvResolution + " -c:v libx264 -crf " + cvBit + " -preset veryslow -c:a copy \"" + outputFile + "\"";
                    System.Windows.Forms.MessageBox.Show(args);
                }
                else if (convType == 1)
                {
                    // Audio
                    if (cvAudQuality == 0)
                    {
                        return(false);
                    }

                    args += "\"" + inputFile + "\" -ab " + cvAudQuality + "K" + " \"" + outputFile + "\"";
                }
                else
                {
                    return(false);
                }

                Converter.StartInfo.Arguments = args;
                Converter.Start();
                return(true);
            }
            catch (Exception ex) {
                if (Settings.Default.logErrorFiles)
                {
                    ErrorLog.logError(ex.ToString(), "ydgConvert.convert");
                }
                else
                {
                    ErrorLog.throwError(ex.ToString());
                }

                return(false);
            }
        }
Ejemplo n.º 3
0
 public static void runUpdater()
 {
     try {
         Process Updater = new Process();
         Updater.StartInfo.FileName                = System.Windows.Forms.Application.StartupPath + updateFile;
         Updater.StartInfo.UseShellExecute         = false;
         Updater.StartInfo.CreateNoWindow          = false;
         Properties.Settings.Default.runningUpdate = true;
         Updater.Start();
         Environment.Exit(0);
     }
     catch (Exception ex) {
         Debug.Print(ex.ToString());
         ErrorLog.logError(ex.ToString(), "UpdaterError");
         return;
     }
 }
Ejemplo n.º 4
0
        public static bool downloadCustom(string URL, string downloadDir, int downloadType, string args = null, string format = "best", string quality = "best")
        {
            if (downloadType != 1)
            {
                MessageBox.Show("Custom downloads are only limited to audio formats for the time being.");
                return(false);
            }

            try {
                Process Downloader = new Process();
                Downloader.StartInfo.FileName = Settings.Default.youtubedlDir;

                switch (downloadType)
                {
                case 0:
                    args = bestVideo;
                    break;

                case 1:
                    args = " -x --audio-format " + format + " --audio-quality " + quality + "K";
                    break;

                case 2:
                    break;
                }

                Downloader.StartInfo.Arguments = args;
                Downloader.Start();

                GC.Collect();
                return(true);
            }
            catch (Exception ex) {
                if (Settings.Default.logErrorFiles)
                {
                    ErrorLog.logError(ex.ToString(), "ydgDownload.downloadCustom");
                }
                else
                {
                    ErrorLog.throwError(ex.ToString());
                }

                GC.Collect();
                return(false);
            }
        }
Ejemplo n.º 5
0
 public static bool isUpdateAvailable(decimal cloudVersion)
 {
     try {
         if (Properties.Settings.Default.currentVersion < cloudVersion)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex) {
         Debug.Print(ex.ToString());
         ErrorLog.logError(ex.ToString(), "UpdateCheckError");
         return(false);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Downloads the youtube-dl.exe from Github.
        /// </summary>
        /// <param name="downloadDir"></param>
        public static bool downloadYoutubeDL(string downloadDir)
        {
            try {
                string      xml = Updater.getJSON("https://api.github.com/repos/rg3/youtube-dl/releases/latest");
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);
                XmlNodeList xmlTag = doc.DocumentElement.SelectNodes("/root/tag_name");

                if (xmlTag[0].InnerText == Properties.Settings.Default.ytDLVersion)
                {
                    MessageBox.Show("youtube-dl is already at the latest version.");
                    return(false);
                }

                string YtDl = "https://github.com/rg3/youtube-dl/releases/download/" + xmlTag[0].InnerText + "/youtube-dl.exe";

                if (File.Exists(System.Windows.Forms.Application.StartupPath + @"\youtube-dl.exe"))
                {
                    File.Delete(System.Windows.Forms.Application.StartupPath + @"\youtube-dl.exe");
                }

                using (WebClient wc = new WebClient()) {
                    wc.Headers.Add("User-Agent: " + Advanced.Default.UserAgent);
                    wc.DownloadFile(YtDl, System.Windows.Forms.Application.StartupPath + @"\youtube-dl.exe");
                }

                Settings.Default.DateLastUpdated = DateTime.Now;

                return(true);
            }
            catch (Exception ex) {
                if (Settings.Default.logErrorFiles)
                {
                    ErrorLog.logError(ex.ToString(), "ydgDownload.downloadYoutubeDL");
                }
                else
                {
                    ErrorLog.throwError(ex.ToString());
                }

                return(false);
            }
        }
Ejemplo n.º 7
0
        public static void createUpdaterStub(decimal cloudVersion)
        {
            /*
             * This is the entire code for the updater, it is designed to be light-weight and so is batch-based.
             *
             *  "@echo off"
             *  "echo Updating youtube-dl-gui..."
             *  "set upVersion=" + updVersion
             *  "set programName=" + System.AppDomain.CurrentDomain.FriendlyName;
             *  "timeout /t 5 /nobreak"
             *  "del %programName%"
             *  "powershell -Command "(New-Object Net.WebClient).DownloadFile(upateURL + '/%upVersion%/youtube-dl-gui.exe', '%programName%')""
             *  "%programName%"
             *   "exit"
             *
             */

            try {
                if (File.Exists(Application.StartupPath + updateFile))
                {
                    File.Delete(Application.StartupPath + updateFile);
                }

                File.Create(Application.StartupPath + updateFile).Dispose();
                System.IO.StreamWriter writeApp = new System.IO.StreamWriter(Application.StartupPath + updateFile);
                writeApp.WriteLine("@echo off");
                writeApp.WriteLine("echo Updating youtube-dl-gui...");
                writeApp.WriteLine("set upVersion=" + cloudVersion);
                writeApp.WriteLine("set programName=" + System.AppDomain.CurrentDomain.FriendlyName);
                writeApp.WriteLine("timeout /t 5 /nobreak");
                writeApp.WriteLine("del %programName%");
                writeApp.WriteLine("powershell -Command \"(New-Object Net.WebClient).DownloadFile('" + downloadURL + "', '%programName%')\"");
                writeApp.WriteLine("%programName%");
                writeApp.WriteLine("eixt");
                writeApp.Close();
            }
            catch (Exception ex) {
                Debug.Print(ex.ToString());
                ErrorLog.logError(ex.ToString(), "UpdaterError");
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Tooltip
        /// </summary>
        /// <param name="URL">The URL of the video (or otherwise) to download</param>
        /// <param name="downloadDir">The directory where the file will be downloaded to</param>
        /// <param name="downloadType">The type of download (0 = Video, 1 = Audio, 2 = Custom Arguments, any other will attempt a download without any arguments.</param>
        /// <param name="args">(Optional) custom arguments to pass to Youtube-DL</param>
        /// <returns></returns>
        public static bool downloadBest(string URL, string downloadDir, int downloadType, string args = "")
        {
            if (string.IsNullOrWhiteSpace(URL))
            {
                MessageBox.Show("Please enter a URL before trying to download.");
                return(false);
            }
            if (string.IsNullOrWhiteSpace(downloadDir))
            {
                MessageBox.Show("Please enter a download directory before trying to download.\nThis error is thrown from an unconfigured download directory. Check your settings and try again.");
                return(false);
            }

            try {
                Process Downloader = new Process();
                Downloader.StartInfo.FileName = Settings.Default.youtubedlDir;
                //Downloader.StartInfo.UseShellExecute = false;
                //Downloader.StartInfo.RedirectStandardOutput = true;
                //Downloader.StartInfo.CreateNoWindow = true;

                string outputFolder = " -o \"" + Settings.Default.DownloadDir + "/%(title)s-%(id)s.%(ext)s\""; // The folder where it will be downloaded
                string setArgs;                                                                                // Arguments to give.

                if (downloadType == 0 && Settings.Default.sortDownloads)
                {
                    // Video
                    setArgs = URL + " -f \"bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best\" " + outputFolder;
                }
                else if (downloadType == 1 && Settings.Default.sortDownloads)
                {
                    // Audio
                    setArgs = URL + " -x --audio-format best  --audio-quality best " + outputFolder;
                }
                else if (downloadType == 2 && Settings.Default.sortDownloads)
                {
                    // Custom
                    setArgs = args;
                }
                else
                {
                    // Unselected.
                    setArgs = URL + outputFolder;
                }

                Downloader.StartInfo.Arguments = setArgs;
                Downloader.Start();

                GC.Collect();
                return(true);
            }
            catch (Exception ex) {
                if (Settings.Default.logErrorFiles)
                {
                    ErrorLog.logError(ex.ToString(), "ydgDownload.download");
                }
                else
                {
                    ErrorLog.throwError(ex.ToString());
                }

                GC.Collect();
                return(false);
            }
        }