Пример #1
0
        private async Task <VideoQualityFormat> getVideoFormatsAsync(string url)
        {
            VideoQualityFormat data = null;

            var updateGUIThread = new Progress <string>((value) =>
            {
            });


            var updateMainForm = updateGUIThread as IProgress <string>;


            await Task.Run(() => {
                string x = "";

                var youtubeDL1 = new YoutubeDL();
                youtubeDL1.StandardOutputEvent += (sender, output) => {
                    Console.WriteLine(output);
                    x = output;
                };
                youtubeDL1.StandardErrorEvent += (sender, errorOutput) => Console.WriteLine(errorOutput);
                youtubeDL1.VideoUrl            = _VODObject.url;
                youtubeDL1.Options.VerbositySimulationOptions.DumpJson = true;

                //Only can do one json even at a time
                youtubeDL1.Download();

                data = JsonConvert.DeserializeObject <VideoQualityFormat>(x);
            });


            return(data);
        }
        /// <summary>
        /// Gets the download links and creates the global VideoQualityFormats object
        /// </summary>
        /// <param name="url">VOD url</param>
        /// <returns>Task that contains the VideoQualityObject for the URL</returns>
        private async Task <VideoQualityFormat> getVideoFormats(string url)
        {
            VideoQualityFormat data = null;

            var updateGUIThread = new Progress <Boolean>((value) =>
            {
                if (value)
                {
                    //loading image while video quality links loads
                    selectedVODPictureBox.Image = Properties.Resources.loadingIcon;
                }
                else
                {
                    //replace loading image with stream thumbnail
                    try
                    {
                        selectedVODPictureBox.Load(_selectedVOD.thumbnail_url.Replace("%{width}", "300").Replace("%{height}", "300"));
                    }
                    catch (Exception e)
                    {
                        selectedVODPictureBox.Load(_selectedVOD.thumbnail_url.Replace("%{width}", "300").Replace("%{height}", "300"));
                        Console.WriteLine(e.Message);
                    }
                }
            });

            var updateMainForm = updateGUIThread as IProgress <Boolean>;

            string videoQualityRawJSON = "";


            var youtubeDL = new YoutubeDL()
            {
                VideoUrl      = url,
                YoutubeDlPath = Properties.Settings.Default.YoutubeDLLocation
            };

            youtubeDL.Options.VerbositySimulationOptions.DumpJson = true;

            youtubeDL.StandardOutputEvent += (sender, output) => {
                Console.WriteLine(output);
                videoQualityRawJSON = output;
            };
            youtubeDL.StandardErrorEvent += (sender, errorOutput) => Console.WriteLine(errorOutput);

            updateMainForm.Report(true);

            //downloads the json for video quality
            await youtubeDL.DownloadAsync();

            data = JsonConvert.DeserializeObject <VideoQualityFormat>(videoQualityRawJSON);
            updateMainForm.Report(false);

            return(data);
        }
Пример #3
0
        private async void DownloadStreamForm_Load_1Async(object sender, EventArgs e)
        {
            if (_VODObject != null)
            {
                _videoQualityFormats = await getVideoFormatsAsync(_VODObject.url);

                _videoQualityFormats.VideoQualityList.ForEach(x => comboBox2.Items.Add(x.format));

                pictureBox1.Load(_VODObject.thumbnail_url.Replace("%{width}", "300").Replace("%{height}", "300"));
                label1.Text   = _VODObject.title;
                label2.Text   = _VODObject.created_at.ToShortTimeString();
                label3.Text   = _VODObject.duration;
                label4.Text   = "";
                label5.Text   = "";
                textBox1.Text = String.Format("{0}", _VODObject.title);
                Console.WriteLine(_VODObject.duration);
            }
        }
        /// <summary>
        /// loads the video qualities and puts them in the VideoQualityComboBox
        /// </summary>
        private void populateComboBoxWithVideoFormats()
        {
            var updateGUIThread = new Progress <VideoQualityFormat>((value) =>
            {
                ClearForm();
                value.VideoQualityList.ForEach(x => VideoQualityComboBox.Items.Add(x.format));
                selectedVODPictureBox.Load(_selectedVOD.thumbnail_url.Replace("%{width}", "300").Replace("%{height}", "300"));
                TitleLabel.Text      = _selectedVOD.title;
                CreatedLabel.Text    = _selectedVOD.created_at.ToShortTimeString();
                SizeLabel.Text       = _selectedVOD.duration;
                FileNameTextBox.Text = String.Format("{0}", _selectedVOD.title);
            });

            var updateMainForm = updateGUIThread as IProgress <VideoQualityFormat>;

            if (_selectedVOD != null)
            {
                Task.Run(() => {
                    _videoQualityFormats = getVideoFormats(_selectedVOD.url).Result;
                    updateMainForm.Report(_videoQualityFormats);
                });
            }
        }