コード例 #1
0
        private void FrameMain_Shown(object sender, EventArgs e)
        {
            checkDependencies();
            YouTubeDL.checkForUpdates();

            checkForUpdatesToolStripMenuItem_Click(false, e);
        }
コード例 #2
0
        private void checkDependencies()
        {
            if (!YouTubeDL.isInstalled())
            {
                var result = MessageBox.Show("youtube-dl is required. Install?", "Install Core Component", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result == DialogResult.Yes)
                {
                    var f = new FrameYTDLDependencyInstall();
                    f.ShowDialog();
                    // TODO ?
                    MessageBox.Show("Components have been installed successfully!", "Required Components Installed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    f.Close();
                }
                else
                {
                    MessageBox.Show("Required components not installed! This app will NOT behave correctly because its critical dependencies are missing.", "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            if (!FFmpeg.isInstalled())
            {
                MessageBox.Show("Could not find FFmpeg on your system. This app will NOT behave correctly because its critical dependencies are missing. Please reinstall this app.", "Required components not installed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (!AtomicParsley.isInstalled())
            {
                MessageBox.Show("Could not find AtomicParsley on your system.. This app will NOT behave correctly because its critical dependencies are missing. Please reinstall this app.", "Required components not installed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
コード例 #3
0
        private void addMediaItemRow(string title, string type, string url, string opts, string filePath)
        {
            var li = new ListViewItem(new string[] { title, "Waiting", type, "-", "", "0%", "0.0 KB/s", url, filePath });

            li.Tag = Common.RandomString(5) + DateTime.UtcNow.Ticks;
            listItems.Items.Add(li);

            Process          p   = YouTubeDL.run(opts);
            ProcessUpdateRow pur = new ProcessUpdateRow();

            pur.proc    = p;
            pur.item    = listItems.Items[listItems.Items.Count - 1];
            pur.results = new List <string>
            {
                "" // intentional
            };

            dict.Add(li.Tag.ToString(), pur);

            int index = 0; // video

            if (type == "audio")
            {
                index = 1;
            }
            pur.item.ImageIndex = index;
        }
コード例 #4
0
        private void FrameYTDLDependencyInstall_Shown(object sender, EventArgs e)
        {
            Application.DoEvents();

            YouTubeDL.downloadAndInstall();
            this.Close();
        }
コード例 #5
0
        private void FrameMain_Shown(object sender, EventArgs e)
        {
            checkDependencies();

            Task.Run(() =>
            {
                YouTubeDL.checkForUpdates();
            });
        }
コード例 #6
0
        private void addMediaItemRow(string title, string type, string url, string opts, string filePath)
        {
            var li = new ListViewItem(new string[] { title, "Waiting", type, "-", "", "0%", "0.0 KB/s", url, filePath });

            li.Tag = DateTime.Now.ToString("yyyyMMddhmmsstt");
            listItems.Items.Add(li);

            Process          p   = YouTubeDL.run(opts);
            ProcessUpdateRow pur = new ProcessUpdateRow();

            pur.proc    = p;
            pur.item    = listItems.Items[listItems.Items.Count - 1];
            pur.results = new List <string>
            {
                "" // intentional
            };

            Task.Run(() =>
            {
                // spawns a new thread to read standard out data
                while (pur.proc != null && !pur.proc.HasExited)
                {
                    pur.results.Add(pur.proc.StandardOutput.ReadLine());
                }
            });

            Task.Run(() =>
            {
                // spawns a new thread to read error stream data
                while (pur.proc != null && !pur.proc.HasExited)
                {
                    string line = pur.proc.StandardError.ReadLine();
                    if (!String.IsNullOrEmpty(line))
                    {
                        pur.results.Add(line);
                    }
                }
            });

            dict.Add(li.Tag.ToString(), pur);

            int index = 0; // video

            if (type == "audio")
            {
                index = 1;
            }
            pur.item.ImageIndex = index;
        }
コード例 #7
0
        private void FrameAbout_Load(object sender, EventArgs e)
        {
            labelVersion.Text = Common.getAppVersion();

            try
            {
                var lines = "* " + YouTubeDL.getExtractors().Replace("\n", "\r\n* ");
                textExtractors.Text = lines;

                labelYouTubeDL.Text = String.Format("youtube-dl {0}", YouTubeDL.getVersion());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                textExtractors.Text = "ERROR: Can't get list of supported services.";
            }
        }
コード例 #8
0
        private void downloadBatchYouTubePlaylistlToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var d = new FrameImportPlaylist();

            if (d.ShowDialog() == DialogResult.OK)
            {
                string url   = d.url;
                var    items = YouTubeDL.getPlaylistMetadata(url);

                string result = "";
                foreach (var item in items)
                {
                    result += String.Format("https://www.youtube.com/watch?v={0}\r\n", item.id);
                }

                downloadBatchManualToolStripMenuItem_Click(result, e);
            }
        }
コード例 #9
0
        private void ingestMediaUrl()
        {
            var f = new FrameCheckMetadata();

            try
            {
                string url = textUrl.Text.Trim();
                if (url != lastValidUrl && Common.isValidURL(url))
                {
                    lastValidUrl = url;

                    this.Enabled = false;
                    f.Show();
                    Application.DoEvents();

                    var    info = YouTubeDL.getMediaData(url);
                    string thumbnailFilePath = YouTubeDL.downloadThumbnail(info.thumbnail);
                    pbPreview.ImageLocation = thumbnailFilePath;

                    labelTitle.Text       = info.title;
                    labelDescription.Text = info.description;
                    // TODO: may need to be revised now that using --restrict-filenames flag in youtube-dl
                    textLocation.Text = YouTubeDL.defaultDownloadPath + "\\" + String.Format("{0}{1}", Common.stripIllegalFileNameChars(info.filename.Substring(0, info.filename.LastIndexOf('.'))), info.filename.Substring(info.filename.LastIndexOf('.')));

                    if (info.formats != null && info.formats.Count > 0)
                    {
                        cbVideoFormat.Items.Clear();
                        cbAudioFormat.Items.Clear();

                        if (info.requestedFormats != null && info.requestedFormats.Count > 0)
                        {
                            info.formats.Insert(0, info.requestedFormats[0]);

                            if (info.requestedFormats.Count > 1)
                            {
                                info.formats.Insert(0, info.requestedFormats[1]);
                            }
                        }

                        string recommendedVideoFormat = "";
                        string recommendedAudioFormat = "";
                        var    videoFormatList        = new List <string>();
                        var    audioFormatList        = new List <string>();
                        videoIdLookupTable = new Dictionary <string, string>();
                        audioIdLookupTable = new Dictionary <string, string>();

                        foreach (var format in info.formats)
                        {
                            if (!String.IsNullOrEmpty(format.width) && !String.IsNullOrEmpty(format.height))
                            {
                                string codec = ((!String.IsNullOrEmpty(format.vcodec) && format.vcodec != "none") ? format.vcodec : "unknwon codec");
                                string tbr   = ((!String.IsNullOrEmpty(format.tbr)) ? Math.Floor(Convert.ToDecimal(format.tbr)).ToString() + "k" : "---"); // rounds down
                                string fps   = ((!String.IsNullOrEmpty(format.fps)) ? format.fps + "fps" : "---");
                                string note  = ((!String.IsNullOrEmpty(format.formateNote)) ? format.formateNote : "---");
                                string str   = String.Format("{0} x {1} / {2} / {3} / {4} / {5} {6}", format.width.PadRight(4), format.height.PadLeft(4), tbr.PadRight(7), format.ext.PadRight(5), note.PadRight(6), fps.PadLeft(6), codec);

                                if (info.requestedFormats != null && String.IsNullOrEmpty(recommendedVideoFormat))
                                {
                                    str += " [Recommended]";
                                    recommendedVideoFormat = str;
                                }
                                else
                                {
                                    videoFormatList.Add(str);
                                }

                                if (!videoIdLookupTable.ContainsKey(str))
                                {
                                    videoIdLookupTable.Add(str, format.formatId);
                                }
                            }

                            if (!String.IsNullOrEmpty(format.acodec) && format.acodec != "none")
                            {
                                var bitrate    = (String.IsNullOrEmpty(format.abr) ? "---" : format.abr + " kbps");
                                var sampleRate = (String.IsNullOrEmpty(format.asr) ? "---" : format.asr + "Hz");
                                var str        = String.Format("{0} / {1} / {2} / {3}", bitrate.PadRight(9), sampleRate.PadLeft(8), format.ext.PadRight(5), format.acodec);

                                if (info.requestedFormats != null && String.IsNullOrEmpty(recommendedAudioFormat))
                                {
                                    str += " [Recommended]";
                                    recommendedAudioFormat = str;
                                }
                                else
                                {
                                    audioFormatList.Add(str);
                                }

                                if (!audioIdLookupTable.ContainsKey(str))
                                {
                                    audioIdLookupTable.Add(str, format.formatId);
                                }
                            }
                        }

                        if (!String.IsNullOrEmpty(recommendedVideoFormat))
                        {
                            cbVideoFormat.Items.Add(recommendedVideoFormat);
                        }

                        try
                        {
                            videoFormatList.Sort((x, y) => Int32.Parse(x.Trim().Split(' ')[0]).CompareTo(Int32.Parse(y.Trim().Split(' ')[0])));
                        }
                        catch (FormatException ex)
                        {
                            Console.WriteLine(ex);
                        }
                        videoFormatList.Reverse(); // TODO: optimze this out
                        foreach (var item in videoFormatList)
                        {
                            cbVideoFormat.Items.Add(item);
                        }

                        if (!String.IsNullOrEmpty(recommendedAudioFormat))
                        {
                            cbAudioFormat.Items.Add(recommendedAudioFormat);
                        }

                        try
                        {
                            audioFormatList.Sort((x, y) => Int32.Parse(x.Trim().Split(' ')[0]).CompareTo(Int32.Parse(y.Trim().Split(' ')[0])));
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }

                        audioFormatList.Reverse(); // TODO: optimze this out
                        foreach (var item in audioFormatList)
                        {
                            cbAudioFormat.Items.Add(item);
                        }

                        if (cbVideoFormat.Items.Count < 1)
                        {
                            cbVideoFormat.Items.Add("(no video metadata could be extracted)");
                        }
                        cbVideoFormat.SelectedIndex = 0;
                        if (cbAudioFormat.Items.Count < 1)
                        {
                            cbAudioFormat.Items.Add("(no audio metadata could be extracted)");
                        }
                        cbAudioFormat.SelectedIndex = 0;
                        if (cbVideoEncoder.Items.Count > 0)
                        {
                            cbVideoEncoder.SelectedIndex = 0;
                        }
                        if (cbAudioEncoder.Items.Count > 0)
                        {
                            cbAudioEncoder.SelectedIndex = 0;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                MessageBox.Show("Unable to detect metadata!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            f.Close();
            this.Enabled = true;
        }