コード例 #1
0
 public Settings()
 {
     InitializeComponent();
     textBoxVLCPath.Text        = SSettings.GetVlcFile();
     textBoxDownload.Text       = SSettings.getDownloadFolder();
     textBoxChacheLocation.Text = SSettings.getCacheFolder();
 }
コード例 #2
0
        public void DownloadVideo(YouTubeVideo video, string VideoURL)
        {
            // TODO if a file like this already exists warn the user of the duplicated download
            // don't waste his
            localFileLocation = SSettings.getDownloadFolder() + @"\" + $"[{video.Resolution}]" + video.FullName;
            bool download = true;

            if (File.Exists(localFileLocation))
            {
                const string message = "This video has been already downloaded \n Do you want to re-Download it again ? ";
                const string caption = "Redownload  ?";
                var          result  = MessageBox.Show(message, caption,
                                                       MessageBoxButtons.YesNo,
                                                       MessageBoxIcon.Question);
                if (result == DialogResult.No)
                {
                    download = false;
                }
            }

            if (download)
            {
                try
                {
                    tempDownloadFile = SSettings.getCacheFolder() + $"[{video.Resolution}]" + video.FullName;
                    if (File.Exists(tempDownloadFile))
                    {
                        try
                        {
                            File.Delete(tempDownloadFile);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "ERROR ");
                            Dispose();
                        }
                    }
                    webClient.DownloadFileCompleted   += new AsyncCompletedEventHandler(DownloadFinished);
                    webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
                    webClient.DownloadFileAsync(new Uri(video.Uri), tempDownloadFile);
                    startTime          = DateTimeOffset.Now.ToUnixTimeMilliseconds();
                    labRemoteLink.Text = VideoURL;
                    labLocalFile.Text  = $"[{video.Resolution}]" + video.FullName;
                    Text = "Downloading " + $"[{video.Resolution}]" + video.FullName;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Network Error");
                }
            }

            else
            {
                webClient.Dispose();
                Dispose();
            }
        }
コード例 #3
0
 static void Main()
 {
     SSettings.getCurrentLocation();
     SSettings.loadSettings();
     Directory.CreateDirectory(SSettings.getDownloadFolder());
     Directory.CreateDirectory(SSettings.getCacheFolder());
     foreach (var str in Directory.GetFiles(SSettings.getCacheFolder()))
     {
         try
         {
             File.Delete(str);
         }
         catch (Exception e)
         {
             Console.WriteLine(e.Message);
         }
     }
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new MainForm());
 }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: humanshield89/SharpTube
        private void btnSearch_Click(object sender, EventArgs e)
        {
            btnSearch.Enabled = false;
            listResults.Items.Clear();
            string searchQuery = txtSearchQuery.Text;

            if (txtSearchQuery.Text.StartsWith("https://www.youtube.com/watch?v=") ||
                txtSearchQuery.Text.StartsWith("http://www.youtube.com/watch?v=") || txtSearchQuery.Text.StartsWith("www.youtube.com/watch?v="))
            {
                searchQuery = txtSearchQuery.Text.Split('=')[1].Split('&')[0];
            }
            try
            {
                results = YoutubeScrapeEngine.scrapeYoutube(searchQuery);
            }
            catch (Exception ex)
            {
                results = new List <VideoItem>();
                MessageBox.Show(ex.Message + "\n Hint : Check your internet connection before trying again ", "Network Error");
            }
            ImageList imageList = new ImageList();

            imageList.ImageSize  = new Size(120, 80);
            imageList.ColorDepth = ColorDepth.Depth24Bit;
            if (results.Any())
            {
                int i = 0;

                Directory.CreateDirectory(SSettings.getCacheFolder());
                foreach (VideoItem video in results)
                {
                    string path = video.DownloadThumbSmallImage();
                    imageList.Images.Add(Image.FromFile(path));

                    string[]     arr = { "", "" + (i + 1), video.title, video.url };
                    ListViewItem l   = new ListViewItem(arr)
                    {
                        Font       = new Font("Century Gothic", 10.75F, FontStyle.Regular, GraphicsUnit.Point, 0),
                        ImageIndex = i
                    };
                    listResults.Items.Add(l);


                    i++;
                }

                listResults.SmallImageList = imageList;
            }
            else
            {
                imageList.Images.Add(imageList1.Images[0]);
                string[]     arr = { "", " ", "No Results check your enternet connection ", "N/A" };
                ListViewItem t   = new ListViewItem(arr)
                {
                    Font       = Font = new Font("Century Gothic", 10.75F, FontStyle.Regular, GraphicsUnit.Point, 0),
                    ImageIndex = 0
                };

                listResults.Items.Add(t);
                listResults.SmallImageList = imageList;
            }
            btnSearch.Enabled = true;
            foreach (var video in results)
            {
                video.LoadVideos();
            }
        }