Esempio n. 1
0
        void YouTubeDownload(int num, int session)
        {
            PassArguments result = songArray[session][num];

//            while (true)
//            {
            try
            {
                List <YouTubeVideoQuality> urls        = result.YouTubeVideoQuality;
                YouTubeVideoQuality        highestQual = new YouTubeVideoQuality();

                foreach (var url in urls)
                {
                    if (url.Extention == "mp4")
                    {
                        highestQual = urls[0];
                        break;
                    }
                }
                string Url    = "";
                string saveTo = "";
                try
                {
                    YouTubeVideoQuality tempItem = highestQual;
                    Url    = tempItem.DownloadUrl;
                    saveTo = EscapeFilename(result.PassedFileName) + ".mp4";
                }
                catch (Exception ex)
                {
                    Log("[Error x11] " + ex.InnerException, true);
                }
                if (result.PassedFileName == null || result.PassedNum == null)
                {
                    MessageBox.Show("Somthing null");
                }
                EditList("Downloading...", result.PassedFileName, result.PassedNum, 2);
                var    folder = Path.GetDirectoryName(_tempDir + saveTo);
                string file   = Path.GetFileName(_tempDir + saveTo);

                var client  = new WebClient();
                Uri address = new Uri(Url);
                client.DownloadFile(address, folder + "\\" + file);
                EditList("Converting...", result.PassedFileName, result.PassedNum, 3);
                StartConvert(result.PassedFileName);
                MusicTags(num, session);
                _youtubeDownloadedNum++;
                Done(result.PassedFileName, num);
                _running--;
                if (_running < 0)
                {
                    _running = 0;
                }
//                    break;
            }
            catch (Exception ex)
            {
                Log("[Error x12] " + "|" + ex.Message + "| " + ex.InnerException + " | " + result.PassedFileName, true);
            }
//            }
        }
Esempio n. 2
0
        private static YouTubeVideoQuality GetPreferred(List <YouTubeVideoQuality> videoList)
        {
            YouTubeVideoQuality userPreferredVideo = null;

            double videoDist = Double.MaxValue;

            foreach (var video in videoList)
            {
                if (userPreferredVideo == null)
                {
                    userPreferredVideo = video;
                }

                if (videoWidth > 0 || videoSize > 0)
                {
                    double curVideoDist = GetVideoDistance(video);
                    if (videoDist > curVideoDist)
                    {
                        videoDist          = curVideoDist;
                        userPreferredVideo = video;
                    }

                    if (videoDist == curVideoDist && string.Compare(video.Extention, videoExtension, true) == 0)
                    {
                        userPreferredVideo = video;
                    }
                }
                else if (string.Compare(video.Extention, videoExtension, true) == 0)
                {
                    userPreferredVideo = video;
                }
            }

            return(userPreferredVideo);
        }
Esempio n. 3
0
        private static void DownloadVideo(string url, string fileName)
        {
            Console.WriteLine("* Download YourTube video");

            Console.WriteLine("Fetching video informations ...");
            List <YouTubeVideoQuality> videoList = YouTubeDownloader.GetYouTubeVideoUrls(url);

            if (videoList.Count > 0)
            {
                downloadDone = new ManualResetEvent(false);

                YouTubeVideoQuality video = GetPreferred(videoList);

                if (video != null)
                {
                    string fn = fileName;

                    if (string.IsNullOrEmpty(fn))
                    {
                        fn = string.Concat(video.VideoTitle, ".", video.Extention);
                    }

                    Console.WriteLine("url: {0}", url);
                    Console.WriteLine("fileName: \"{0}\"", fn);

                    if (File.Exists(fn))
                    {
                        Console.Write("\"{0}\" already exists! Overwrite? (y/N) ", fn);
                        char res = ConsoleEx.ReadKey(5, 'n');
                        if (res.Equals('n'))
                        {
                            File.Delete(fn);
                        }
                        else
                        {
                            return;
                        }
                    }

                    downloadDone.Reset();
                    Console.WriteLine("Video Title: \"{0}\"", video.VideoTitle);
                    Console.WriteLine("File lenght: {0}", new FileSize(video.VideoSize).ToString(FileSizeUnit.B));
                    Console.WriteLine("* Downloading {0} => \"{1}\"", ConsoleEx.CompactPath(video.DownloadUrl, 40), ConsoleEx.CompactPath(fileName, 40));
                    DownloadFile(video.DownloadUrl, fn);
                    downloadDone.WaitOne();
                }
                else
                {
                    Console.WriteLine("No video match conditions!");
                }
            }
            else
            {
                Console.WriteLine("The <url> specified doesn't contain videos");
            }
        }
Esempio n. 4
0
        private void btnDownload_Click(object sender, EventArgs e)
        {
            YouTubeVideoQuality tempItem = (YouTubeVideoQuality)cbxQuality.SelectedItem;

            saveFileDialog1.FileName = tempItem.VideoTitle + "." + tempItem.Extention;
            saveFileDialog1.ShowDialog();
            string         folder     = Path.GetDirectoryName(saveFileDialog1.FileName);
            string         file       = Path.GetFileName(saveFileDialog1.FileName);
            FileDownloader downloader = new FileDownloader(tempItem.DownloadUrl, folder, file);

            downloader.ProgressChanged    += this.OnRunWorkerProgress;
            downloader.RunWorkerCompleted += OnRunWorkerCompleted;
            downloader.RunWorkerAsync();
        }
Esempio n. 5
0
        private static double GetVideoDistance(YouTubeVideoQuality video)
        {
            double f1 = 0.0;

            if (videoWidth > 0)
            {
                f1 = Math.Pow(Math.Abs(video.Dimension.Width - videoWidth), 2);
            }

            double f2 = 0.0;

            if (videoSize > 0)
            {
                f2 = Math.Pow(Math.Abs(video.VideoSize - videoSize), 2);
            }

            return(Math.Sqrt(f1 + f2));
        }