private void DownloadButton_Click(object sender, RoutedEventArgs e) { if (IsDownloadRunning) { MessageBox.Show("Please wait for the current download to complete"); } else { StatusText.Content = "Downloading..."; VidDownloader = new YTDownloader(); VidDownloader.DownloadProgressChanged += VidDownloader_DownloadProgressChanged; VidDownloader.DownloadCompleted += VidDownloader_DownloadCompleted; if (IsDownloadingMP3) { if (usingMP3Thumbnail) { VidDownloader.DownloadVideo(VidURL, DownloadType.MP3Pic, SelectedAudQuality, SelectedVidQuality); } else { VidDownloader.DownloadVideo(VidURL, DownloadType.MP3Only, SelectedAudQuality, SelectedVidQuality); } } else { DownloadAudQuality = SelectedAudQuality; DownloadVidQuality = SelectedVidQuality; VidDownloader.DownloadVideo(VidURL, DownloadType.CustomQuality, SelectedAudQuality, SelectedVidQuality); } } }
public void SetVideoMetadata() { StatusText.Content = "Status: Getting Metadata"; MetadataScraper scraper = new MetadataScraper(); VidInfo = scraper.GetMetadata(VidURL, true, AppPath + "\\thumbnail.jpg"); VidTitle.Content = VidInfo.VidTitle; thumbnail.Source = null; BitmapImage thumbnailPic = new BitmapImage(); thumbnailPic.BeginInit(); thumbnailPic.UriSource = new Uri(VidInfo.ThumbnailURL, UriKind.RelativeOrAbsolute); thumbnailPic.EndInit(); thumbnail.Source = thumbnailPic; VidQualities = VidInfo.VidQualities; AudQualities = VidInfo.AudQualities; VidQualityBox.Items.Clear(); foreach (VidQuality quality in VidQualities) { VidQualityBox.Items.Add(quality.Format + " - " + quality.Resolution); } VidQualityBox.Items.Add("MP3 Only"); AudioQualityBox.Maximum = VidInfo.AudioCount; FileSizeLabel.Content = "Please select a video and audio quality"; StatusText.Content = ""; SelectedAQuality = ""; SelectedVidQuality = new VidQuality(); SelectedAudQuality = new AudQuality(); //AudioQualityBox. }
private void DownloadButton_Click(object sender, RoutedEventArgs e) { if (AllVideosInfoList.Count > 0) { CurrentVideo = CurrentVideo + 1; PlaylistStatus.Dispatcher.Invoke(new Action(() => PlaylistStatus.Content = "Status:[" + CurrentVideo.ToString() + "/" + TotalVideos.ToString() + "] Downloading youtube.com/watch?v=" + AllVideosInfoList[0].VidID)); if (AllVideosInfoList[0].IsMP3Only) { IsdownloadingMP3 = true; if (IsUsingMP3Thumbnail) { CurrentDownloadID = AllVideosInfoList[0].VidID; CurrentDownloadType = DownloadType.MP3Pic; downloader.DownloadVideo("https://www.youtube.com/watch?v=" + AllVideosInfoList[0].VidID, DownloadType.MP3Pic); } else { CurrentDownloadID = AllVideosInfoList[0].VidID; CurrentDownloadType = DownloadType.MP3Only; downloader.DownloadVideo("https://www.youtube.com/watch?v=" + AllVideosInfoList[0].VidID, DownloadType.MP3Only); } } else { IsdownloadingMP3 = false; CurrentDownloadType = DownloadType.CustomQuality; CurrentDownloadID = AllVideosInfoList[0].VidID; VideoQualityInfo NewDownloadInfo = AllVideosInfoList[0]; AudQuality aQuality = new AudQuality(); aQuality.AudNo = NewDownloadInfo.SelectedAudQuality.ToString(); VidQuality vQuality = new VidQuality(); vQuality.VidNo = NewDownloadInfo.SelectedVidQuality.ToString(); foreach (VidQuality quality in NewDownloadInfo.VidQualityList) { if (quality.VidNo == vQuality.VidNo) { vQuality.Format = quality.Format; } } foreach (AudQuality quality in NewDownloadInfo.AudQualityList) { if (quality.AudNo == aQuality.AudNo) { aQuality.Format = quality.Format; } } IsCrossFormat = NewDownloadInfo.IsCrossFormat; CurrentAudQuality = aQuality; CurrentVidQuality = vQuality; downloader.DownloadVideo("https://www.youtube.com/watch/?v=" + NewDownloadInfo.VidID, DownloadType.CustomQuality, aQuality, vQuality); } } }
private void AudioQualityBox_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { if (AudQualities.Count != 0) { if (IsDownloadingMP3) { return; } // MessageBox.Show(SelectedAQuality); int value = (int)AudioQualityBox.Value; SelectedAudQuality = AudQualities[value - 1]; SelectedAQuality = SelectedAQuality + "AUDIO"; if (SelectedAQuality.Contains("AUDIO") && SelectedAQuality.Contains("VIDEO")) { FileSizeLabel.Content = "Total File Size: " + SelectedVidQuality.FileSize + " (VIDEO), " + SelectedAudQuality.FileSize + " (AUDIO)"; } } }
private async Task ProcessRequest(HttpListenerContext context) { HttpListenerRequest request = context.Request; Log.WriteLog(LogType.Info, "Recieved a request for " + request.Url); if (request.RawUrl.Contains("getmetadata")) { StartCheckMaintainance: if (File.Exists(downloadPath + "\\maintainance.lck")) { Log.WriteLog(LogType.Info, "Delaying request for 4 seconds as maintainance is currently running"); Thread.Sleep(4000); goto StartCheckMaintainance; } string VidID = request.QueryString.GetValues(request.QueryString.AllKeys[0])[0]; string VidURL = "https://www.youtube.com/watch?v=" + VidID; MetadataScraper scraper = new MetadataScraper(); MetadataScrape scrape = new MetadataScrape(); scrape = scraper.GetMetadata(VidURL); HttpListenerResponse response = context.Response; MemoryStream xmlData = new MemoryStream(); //from https://stackoverflow.com/questions/16371037/save-xml-content-to-a-variable answer by Adil and https://csharp.net-tutorials.com/xml/writing-xml-with-the-xmlwriter-class/ using (XmlWriter writer = XmlWriter.Create(xmlData)) { writer.WriteStartDocument(); writer.WriteStartElement("VideoMetadata"); writer.WriteStartElement("VideoID"); writer.WriteString(VidID); writer.WriteEndElement(); writer.WriteStartElement("Title"); writer.WriteString(scrape.VidTitle); writer.WriteEndElement(); writer.WriteStartElement("ThumbnailURL"); writer.WriteString(scrape.ThumbnailURL); writer.WriteEndElement(); writer.WriteStartElement("VideoQualities"); foreach (VidQuality quality in scrape.VidQualities) { writer.WriteStartElement("vidquality"); writer.WriteAttributeString("format", quality.Format); writer.WriteAttributeString("size", quality.FileSize); writer.WriteAttributeString("resolution", quality.Resolution); writer.WriteAttributeString("ID", quality.VidNo); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteStartElement("AudioQualities"); foreach (AudQuality quality in scrape.AudQualities) { writer.WriteStartElement("audquality"); writer.WriteAttributeString("format", quality.Format); writer.WriteAttributeString("size", quality.FileSize); writer.WriteAttributeString("ID", quality.AudNo); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); } string xmlString = ASCIIEncoding.UTF8.GetString(xmlData.ToArray()); if (request.HttpMethod == "OPTIONS") { response.AddHeader("Access-Control-Allow-Headers", "*"); } response.AppendHeader("Access-Control-Allow-Origin", "*"); byte[] buffer = Encoding.UTF8.GetBytes(xmlString); context.Response.ContentLength64 = buffer.Length; context.Response.StatusCode = (int)HttpStatusCode.OK; context.Response.ContentType = "text/xml; encoding='utf-8'"; context.Response.OutputStream.Write(buffer, 0, buffer.Length); Log.WriteLog(LogType.Info, "Successfully sent output"); response.Close(); } else if (request.RawUrl.Contains("downloadvid")) { StartCheckMaintainance: if (File.Exists(downloadPath + "\\maintainance.lck")) { Log.WriteLog(LogType.Info, "Delaying request for 4 seconds as maintainance is currently running"); Thread.Sleep(4000); goto StartCheckMaintainance; } YTDownloader downloader = new YTDownloader(); downloader.DownloadCompleted += Downloader_DownloadCompleted; downloader.DownloadProgressChanged += Downloader_DownloadProgressChanged; string urlID = request.QueryString.GetValues(request.QueryString.AllKeys[0])[0]; string isMP3Only = request.QueryString.GetValues(request.QueryString.AllKeys[1])[0]; if (isMP3Only.ToLower().Contains("true")) { string isUsingThumbnail = request.QueryString.GetValues(request.QueryString.AllKeys[2])[0]; DownloadType mp3DownloadType; if (isUsingThumbnail.ToLower().Contains("true")) { mp3DownloadType = DownloadType.MP3Pic; } else { mp3DownloadType = DownloadType.MP3Only; } string vidURL = "https://www.youtube.com/watch?v=" + urlID; VidQuality vQuality = new VidQuality(); vQuality.VidNo = "MP3-Only"; AudQuality aQuality = new AudQuality(); aQuality.AudNo = urlID; YTDownload download = new YTDownload(); download.context = context; download.aQuality = aQuality; download.vQuality = vQuality; download.VidID = urlID; download.DownType = mp3DownloadType; RunningDownloads.Add(download); HttpListenerResponse response = context.Response; if (request.HttpMethod == "OPTIONS") { response.AddHeader("Access-Control-Allow-Headers", "*"); } response.AppendHeader("Access-Control-Allow-Origin", "*"); context.Response.SendChunked = true; downloader.DownloadVideo(vidURL, mp3DownloadType, aQuality, vQuality); } else { try { int VidID = int.Parse(request.QueryString.GetValues(request.QueryString.AllKeys[2])[0]); int AudID = int.Parse(request.QueryString.GetValues(request.QueryString.AllKeys[3])[0]); string vidURL = "https://www.youtube.com/watch?v=" + urlID; VidQuality vQuality = new VidQuality(); vQuality.VidNo = VidID.ToString(); AudQuality aQuality = new AudQuality(); aQuality.AudNo = AudID.ToString(); YTDownload download = new YTDownload(); download.aQuality = aQuality; download.vQuality = vQuality; download.VidID = urlID; download.context = context; download.DownType = DownloadType.CustomQuality; RunningDownloads.Add(download); HttpListenerResponse response = context.Response; if (request.HttpMethod == "OPTIONS") { response.AddHeader("Access-Control-Allow-Headers", "*"); } response.AppendHeader("Access-Control-Allow-Origin", "*"); context.Response.SendChunked = true; downloader.DownloadVideo(vidURL, DownloadType.CustomQuality, aQuality, vQuality); } catch (Exception ex) { Log.WriteLog(LogType.Error, ex.ToString()); } } } else if (request.RawUrl.Contains("download")) { StartCheckMaintainance: if (File.Exists(downloadPath + "\\maintainance.lck")) { Log.WriteLog(LogType.Info, "Delaying request for 4 seconds as maintainance is currently running"); Thread.Sleep(4000); goto StartCheckMaintainance; } try { HttpListenerResponse response = context.Response; string linkName = request.QueryString.GetValues(request.QueryString.AllKeys[0])[0]; string fileName = linkName.Replace('*', ' '); fileName = fileName.Replace('|', '&'); fileName = fileName.Replace('<', '='); if (request.HttpMethod == "OPTIONS") { response.AddHeader("Access-Control-Allow-Headers", "*"); } response.AppendHeader("Access-Control-Allow-Origin", "*"); if (File.Exists(downloadPath + "\\" + fileName)) { string contentType = ""; FileInfo info = new FileInfo(fileName); if (info.Extension.ToLower().Contains("mp4")) { contentType = "video/mp4"; } else if (info.Extension.ToLower().Contains("mp3")) { contentType = "audio/mpeg"; } else if (info.Extension.ToLower().Contains("webm")) { contentType = "video/webm"; } else if (info.Extension.ToLower().Contains("mkv")) { contentType = "video/x-matroska"; } response.StatusCode = (int)HttpStatusCode.OK; using (FileStream stream = File.OpenRead(downloadPath + "\\" + fileName)) { response.ContentType = contentType; response.ContentLength64 = info.Length; response.AddHeader( "Content-Disposition", "Attachment; filename=\"" + Path.GetFileName(downloadPath + "\\" + fileName) + "\""); stream.CopyTo(response.OutputStream); } } else { response.StatusCode = (int)HttpStatusCode.NotFound; string responseString = "File not found"; byte[] data = Encoding.UTF8.GetBytes(responseString); response.OutputStream.Write(data, 0, data.Length); } response.Close(); } catch (Exception ex) { Log.WriteLog(LogType.Error, "Error while downloading a file from server: " + ex.ToString()); } } }
public void SetVideoMetadata() { //StatusText.Content = "Status:Getting Metadata..."; //StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "Status: Getting Metadata")); StatusText.Content = "Status: Getting Metadata"; //thumbnail.Source = back; //if() // thumbnail.Dispatcher.Invoke(new Action(() => // BitmapImage back = new BitmapImage() // back.BeginInit() // back.UriSource = new Uri(@"Resources/blank.jpg", UriKind.RelativeOrAbsolute) // back.EndInit() //thumbnail.Source=back)) //thumbnail.Source. // if (File.Exists(AppPath + "\\thumbnail.jpg")) // { // File.Delete(AppPath + "\\thumbnail.jpg"); // } // GetThumbnailInfo.UseShellExecute = false; /* GetThumbnailInfo.Arguments = "--get-thumbnail " + VidURL; * GetThumbnailInfo.CreateNoWindow = true; * GetThumbnailInfo.WindowStyle = ProcessWindowStyle.Hidden; * GetThumbnailInfo.RedirectStandardOutput = true; * GetThumbnail.StartInfo = GetThumbnailInfo; * GetThumbnail.Start(); * string ThumbURL = GetThumbnail.StandardOutput.ReadToEnd(); * GetThumbnail.WaitForExit(); * GetThumbnail.Close(); * string[] URLoutputs = Regex.Split(ThumbURL, "\n"); * ThumbURL = URLoutputs[0]; * //ThumbURL=ThumbURL.TrimEnd() * MessageBox.Show("Starting pic download"); * MetadataHelper.DownloadFile("http://192.168.1.9/new_logo_label.png", "thumbnail.png"); * BitmapImage thumbnailPic = new BitmapImage(); * thumbnailPic.BeginInit(); * thumbnailPic.UriSource = new Uri(@"thumbnail.jpg", UriKind.RelativeOrAbsolute); * thumbnailPic.EndInit(); * GetTitleInfo.CreateNoWindow = true; * GetTitleInfo.Arguments = "--get-title " + VidURL; * GetTitleInfo.UseShellExecute = false; * GetTitleInfo.RedirectStandardOutput = true; * GetTitleInfo.WindowStyle = ProcessWindowStyle.Hidden; * GetTitle.StartInfo = GetTitleInfo; * GetTitle.Start(); * VidTitleName = GetTitle.StandardOutput.ReadToEnd(); * GetTitle.WaitForExit(); * GetTitle.Close(); * VidTitle.Dispatcher.Invoke(new Action(() => VidTitle.Content=VidTitleName)); * StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = ""));*/ MetadataScraper scraper = new MetadataScraper(); VidInfo = scraper.GetMetadata(VidURL, true, AppPath + "\\thumbnail.jpg"); VidTitle.Content = VidInfo.VidTitle; thumbnail.Source = null; BitmapImage thumbnailPic = new BitmapImage(); thumbnailPic.BeginInit(); thumbnailPic.UriSource = new Uri(VidInfo.ThumbnailURL, UriKind.RelativeOrAbsolute); // thumbnailPic.CacheOption = BitmapCacheOption.None; thumbnailPic.EndInit(); thumbnail.Source = thumbnailPic; VidQualities = VidInfo.VidQualities; AudQualities = VidInfo.AudQualities; VidQualityBox.Items.Clear(); foreach (VidQuality quality in VidQualities) { VidQualityBox.Items.Add(quality.Format + " - " + quality.Resolution); } VidQualityBox.Items.Add("MP3 Only"); AudioQualityBox.Maximum = VidInfo.AudioCount; FileSizeLabel.Content = "Please select a video and audio quality"; StatusText.Content = ""; SelectedAQuality = ""; SelectedVidQuality = new VidQuality(); SelectedAudQuality = new AudQuality(); //AudioQualityBox. }
public void ConvertFromMKV(string filename, bool IsToMP4) { ConvertVid = new Process(); ProcessStartInfo ConvertVidInfo = new ProcessStartInfo(AppPath + "\\ConvertDownload.bat"); StreamWriter editBAt = new StreamWriter(AppPath + "\\ConvertDownload.bat"); if (IsToMP4) { editBAt.WriteLine("ffmpeg -i " + '"' + FileNameNoEXT + ".mkv" + '"' + " " + '"' + FileNameNoEXT + ".mp4" + '"'); } else { editBAt.WriteLine("ffmpeg -i " + '"' + FileNameNoEXT + ".mkv" + '"' + " " + '"' + FileNameNoEXT + ".webm" + '"'); } editBAt.Close(); ConvertVidInfo.UseShellExecute = false; ConvertVidInfo.RedirectStandardError = true; ConvertVidInfo.CreateNoWindow = true; ConvertVidInfo.WindowStyle = ProcessWindowStyle.Hidden; ConvertVid.StartInfo = ConvertVidInfo; ConvertVid.ErrorDataReceived += ConvertVid_ErrorDataReceived; ConvertVid.Start(); ConvertVid.BeginErrorReadLine(); ConvertVid.WaitForExit(); ConvertVid.Close(); if (IsToMP4) { if (File.Exists(AppPath + "\\" + FileNameNoEXT + ".mp4")) { string savePath = ""; string message = ""; if (SaveLoc == "Default") { savePath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); message = " to My Documents"; } else { savePath = SaveLoc; } if (File.Exists(savePath + "\\" + FileNameNoEXT + ".mp4")) { MessageBoxResult result = MessageBox.Show("This video has been downloaded previously. Would you like to overwrite it?" + Environment.NewLine + "Otherwise its saved with a different filename", "Overwrite", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { File.Delete(savePath + "\\" + FileNameNoEXT + ".mp4"); File.Copy(AppPath + "\\" + FileNameNoEXT + ".mp4", savePath + "\\" + FileNameNoEXT + ".mp4"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".mp4"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".mkv"); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } } else { File.Copy(AppPath + "\\" + FileNameNoEXT + ".mp4", savePath + "\\" + FileNameNoEXT + " -NEW-" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + " " + DateTime.Now.Hour + "-" + DateTime.Now.Minute + ".mp4"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".mp4"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".mkv"); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } } } else { File.Copy(AppPath + "\\" + FileNameNoEXT + ".mp4", savePath + "\\" + FileNameNoEXT + ".mp4"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".mp4"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".mkv"); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } } DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); MessageBox.Show("Video downloaded successfully and saved " + message); } else { DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); MessageBox.Show("Failed to download video"); } } else { if (File.Exists(AppPath + "\\" + FileNameNoEXT + ".webm")) { string savePath = ""; string message = ""; if (SaveLoc == "Default") { savePath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); message = " to My Documents"; } else { savePath = SaveLoc; } if (File.Exists(savePath + "\\" + FileNameNoEXT + ".webm")) { MessageBoxResult result = MessageBox.Show("This video has been downloaded previously. Would you like to overwrite it?" + Environment.NewLine + "Otherwise its saved with a different filename", "Overwrite", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { File.Delete(savePath + "\\" + FileNameNoEXT + ".webm"); File.Copy(AppPath + "\\" + FileNameNoEXT + ".webm", savePath + "\\" + FileNameNoEXT + ".webm"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".webm"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".mkv"); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } } else { File.Copy(AppPath + "\\" + FileNameNoEXT + ".webm", savePath + "\\" + FileNameNoEXT + " -NEW-" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + " " + DateTime.Now.Hour + "-" + DateTime.Now.Minute + ".webm"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".webm"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".mkv"); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } } } else { File.Copy(AppPath + "\\" + FileNameNoEXT + ".webm", savePath + "\\" + FileNameNoEXT + ".webm"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".webm"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".mkv"); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } } DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); MessageBox.Show("Video downloaded successfully and saved " + message); } else { DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); MessageBox.Show("Failed to download video"); } } IsDownloadRunning = false; DownloadAudQuality = new AudQuality(); DownloadVidQuality = new VidQuality(); FileNameNoEXT = ""; }
private void VidDownloader_DownloadCompleted(DownloadProgress ProgData) { //throw new NotImplementedException(); //MessageBox.Show(ProgData.ProgressInfo + " " + ProgData.ProgType.ToString() + " " + ProgData.DownType + " " + ProgData.ProgressPercentage + "%"); if (IsDownloadingMP3) { //IsDownloadRunning = false; string savepath = ""; string message = ""; if (SaveLoc == "Default") { savepath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); message = " to My Documents"; } else { savepath = SaveLoc; } if (File.Exists(AppPath + "\\" + FileNameNoEXT)) { if (File.Exists(savepath + "\\" + FileNameNoEXT)) { MessageBoxResult result = MessageBox.Show("This MP3 has been downloaded previously. Would you like to overwrite it?" + Environment.NewLine + "Otherwise its saved with a different filename", "Overwrite", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { File.Delete(savepath + "\\" + FileNameNoEXT); File.Copy(AppPath + "\\" + FileNameNoEXT, savepath + "\\" + FileNameNoEXT); File.Delete(AppPath + "\\" + FileNameNoEXT); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } } else { File.Copy(AppPath + "\\" + FileNameNoEXT, savepath + "\\" + FileNameNoEXT + " -NEW-" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + " " + DateTime.Now.Hour + "-" + DateTime.Now.Minute + ".mp3"); File.Delete(AppPath + "\\" + FileNameNoEXT); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } } } else { File.Copy(AppPath + "\\" + FileNameNoEXT, savepath + "\\" + FileNameNoEXT); File.Delete(AppPath + "\\" + FileNameNoEXT); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } } StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); IsDownloadRunning = false; DownloadAudQuality = new AudQuality(); DownloadVidQuality = new VidQuality(); FileNameNoEXT = ""; MessageBox.Show("MP3 Downloaded successfully and saved" + message); } else { // MessageBox.Show(FileNameNoEXT); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); IsDownloadRunning = false; DownloadAudQuality = new AudQuality(); DownloadVidQuality = new VidQuality(); FileNameNoEXT = ""; MessageBox.Show("MP3 failed to download"); } } else { if ((DownloadVidQuality.Format == "mp4" && DownloadAudQuality.Format == "webm") || (DownloadVidQuality.Format == "webm" && DownloadAudQuality.Format == "m4a")) { if (DownloadVidQuality.Format == "mp4") { StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "Converting to MP4")); ConvertingThread = new Thread(() => ConvertFromMKV(FileNameNoEXT, true)); ConvertingThread.Start(); } else { StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "Converting to WEBM")); ConvertingThread = new Thread(() => ConvertFromMKV(FileNameNoEXT, false)); ConvertingThread.Start(); } } else if (DownloadVidQuality.Format == "mp4" && DownloadAudQuality.Format == "m4a") { if (!File.Exists(AppPath + "\\" + FileNameNoEXT + ".mp4")) { StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); IsDownloadRunning = false; DownloadAudQuality = new AudQuality(); DownloadVidQuality = new VidQuality(); FileNameNoEXT = ""; MessageBox.Show("Video failed to download"); return; } if (SaveLoc == "Default") { if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + FileNameNoEXT + ".mp4")) { MessageBoxResult result = MessageBox.Show("This video has been downloaded previously. Would you like to overwrite it?" + Environment.NewLine + "Otherwise its saved with a different filename", "Overwrite", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + FileNameNoEXT + ".mp4"); File.Copy(AppPath + "\\" + FileNameNoEXT + ".mp4", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + FileNameNoEXT + ".mp4"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".mp4"); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } MessageBox.Show("Video successfully downloaded to My Documents"); } else { File.Copy(AppPath + "\\" + FileNameNoEXT + ".mp4", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + FileNameNoEXT + " -NEW-" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + " " + DateTime.Now.Hour + "-" + DateTime.Now.Minute + ".mp4"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".mp4"); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } MessageBox.Show("Video successfully downloaded to My Documents"); } } else { File.Copy(AppPath + "\\" + FileNameNoEXT + ".mp4", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + FileNameNoEXT + ".mp4"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".mp4"); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } MessageBox.Show("Video successfully downloaded to My Documents"); } } else { if (File.Exists(SaveLoc + "\\" + FileNameNoEXT + ".mp4")) { MessageBoxResult result = MessageBox.Show("This video has been downloaded previously. Would you like to overwrite it?" + Environment.NewLine + "Otherwise its saved with a different filename", "Overwrite", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { File.Delete(SaveLoc + "\\" + FileNameNoEXT + ".mp4"); File.Copy(AppPath + "\\" + FileNameNoEXT + ".mp4", SaveLoc + "\\" + FileNameNoEXT + ".mp4"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".mp4"); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } MessageBox.Show("Video successfully downloaded"); } else { File.Copy(AppPath + "\\" + FileNameNoEXT + ".mp4", SaveLoc + "\\" + FileNameNoEXT + " -NEW-" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + " " + DateTime.Now.Hour + "-" + DateTime.Now.Minute + ".mp4"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".mp4"); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } MessageBox.Show("Video successfully downloaded"); } } else { File.Copy(AppPath + "\\" + FileNameNoEXT + ".mp4", SaveLoc + "\\" + FileNameNoEXT + ".mp4"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".mp4"); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } MessageBox.Show("Video successfully downloaded"); } } IsDownloadRunning = false; DownloadAudQuality = new AudQuality(); DownloadVidQuality = new VidQuality(); FileNameNoEXT = ""; } else if (DownloadVidQuality.Format == "webm" && DownloadAudQuality.Format == "webm") { if (!File.Exists(AppPath + "\\" + FileNameNoEXT + ".webm")) { StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); IsDownloadRunning = false; DownloadAudQuality = new AudQuality(); DownloadVidQuality = new VidQuality(); FileNameNoEXT = ""; MessageBox.Show("Video failed to download"); return; } if (SaveLoc == "Default") { if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + FileNameNoEXT + ".webm")) { MessageBoxResult result = MessageBox.Show("This video has been downloaded previously. Would you like to overwrite it?" + Environment.NewLine + "Otherwise its saved with a different filename", "Overwrite", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + FileNameNoEXT + ".webm"); File.Copy(AppPath + "\\" + FileNameNoEXT + ".webm", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + FileNameNoEXT + ".webm"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".webm"); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } MessageBox.Show("Video successfully downloaded to My Documents"); } else { File.Copy(AppPath + "\\" + FileNameNoEXT + ".webm", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + FileNameNoEXT + " -NEW-" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + " " + DateTime.Now.Hour + "-" + DateTime.Now.Minute + ".webm"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".webm"); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } MessageBox.Show("Video successfully downloaded to My Documents"); } } else { File.Copy(AppPath + "\\" + FileNameNoEXT + ".webm", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + FileNameNoEXT + ".webm"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".webm"); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } MessageBox.Show("Video successfully downloaded to My Documents"); } } else { if (File.Exists(SaveLoc + "\\" + FileNameNoEXT + ".webm")) { MessageBoxResult result = MessageBox.Show("This video has been downloaded previously. Would you like to overwrite it?" + Environment.NewLine + "Otherwise its saved with a different filename", "Overwrite", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { File.Delete(SaveLoc + "\\" + FileNameNoEXT + ".webm"); File.Copy(AppPath + "\\" + FileNameNoEXT + ".webm", SaveLoc + "\\" + FileNameNoEXT + ".webm"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".webm"); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } MessageBox.Show("Video successfully downloaded"); } else { File.Copy(AppPath + "\\" + FileNameNoEXT + ".webm", SaveLoc + "\\" + FileNameNoEXT + " -NEW-" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + " " + DateTime.Now.Hour + "-" + DateTime.Now.Minute + ".webm"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".webm"); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } MessageBox.Show("Video successfully downloaded"); } } else { File.Copy(AppPath + "\\" + FileNameNoEXT + ".webm", SaveLoc + "\\" + FileNameNoEXT + ".webm"); File.Delete(AppPath + "\\" + FileNameNoEXT + ".webm"); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } MessageBox.Show("Video successfully downloaded"); } } IsDownloadRunning = false; DownloadAudQuality = new AudQuality(); DownloadVidQuality = new VidQuality(); FileNameNoEXT = ""; } } }
private void Downloader_DownloadCompleted(DownloadProgress ProgData) { string documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); if (File.Exists(AppPath + "\\" + FileName)) { if (IsDefaultSaveLoc) { if (File.Exists(documents + "\\" + FileName)) { MessageBoxResult reply = MessageBox.Show("File already exists in My documents, would you like to overwrite it?", "File exists", MessageBoxButton.YesNo, MessageBoxImage.Information); if (reply == MessageBoxResult.Yes) { File.Delete(documents + "\\" + FileName); File.Copy(AppPath + "\\" + FileName, documents + "\\" + FileName); File.Delete(AppPath + "\\" + FileName); } else { File.Copy(AppPath + "\\" + FileName, documents + "\\" + FileName + "-NEW-" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + " " + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + "." + Fileformat); File.Delete(AppPath + "\\" + FileName); } } else { File.Copy(AppPath + "\\" + FileName, documents + "\\" + FileName); File.Delete(AppPath + "\\" + FileName); } } else { if (Directory.Exists(SaveLoc)) { if (File.Exists(SaveLoc + "\\" + FileName)) { MessageBoxResult result = MessageBox.Show("File already exists in save location, would you like to overwrite it?", "File exists", MessageBoxButton.YesNo, MessageBoxImage.Information); if (result == MessageBoxResult.Yes) { File.Delete(SaveLoc + "\\" + FileName); File.Copy(AppPath + "\\" + FileName, SaveLoc + "\\" + FileName); File.Delete(AppPath + "\\" + FileName); } else { File.Copy(AppPath + "\\" + FileName, SaveLoc + "\\" + FileName + "-NEW-" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + " " + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + "." + Fileformat); File.Delete(AppPath + "\\" + FileName); } } else { File.Copy(AppPath + "\\" + FileName, SaveLoc + "\\" + FileName); File.Delete(AppPath + "\\" + FileName); } } else { MessageBox.Show("Save directory could not be found, saving to My Documents", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); if (File.Exists(documents + "\\" + FileName)) { MessageBoxResult reply = MessageBox.Show("File already exists in My documents, would you like to overwrite it?", "File exists", MessageBoxButton.YesNo, MessageBoxImage.Information); if (reply == MessageBoxResult.Yes) { File.Delete(documents + "\\" + FileName); File.Copy(AppPath + "\\" + FileName, documents + "\\" + FileName); File.Delete(AppPath + "\\" + FileName); } else { File.Copy(AppPath + "\\" + FileName, documents + "\\" + FileName + "-NEW-" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + " " + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + "." + Fileformat); File.Delete(AppPath + "\\" + FileName); } } else { File.Copy(AppPath + "\\" + FileName, documents + "\\" + FileName); File.Delete(AppPath + "\\" + FileName); } } } } else { MessageBox.Show("Failed to download the following video:\nhttps://www.youtube.com/watch/?v=" + ProgData.VidID + "\nfrom the playlist", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } VideoQualityInfo CurrentVid = new VideoQualityInfo(); foreach (VideoQualityInfo info in AllVideosInfoList) { if (info.VidID == ProgData.VidID) { CurrentVid = info; } } AllVideosInfoList.Remove(CurrentVid); if (AllVideosInfoList.Count > 0) { CurrentVideo = CurrentVideo + 1; PlaylistStatus.Dispatcher.Invoke(new Action(() => PlaylistStatus.Content = "Status: [" + CurrentVideo.ToString() + "/" + TotalVideos.ToString() + "] Downloading youtube.com/watch?v=" + AllVideosInfoList[0].VidID)); downloader = new YTDownloader(); downloader.DownloadCompleted += Downloader_DownloadCompleted; downloader.DownloadProgressChanged += Downloader_DownloadProgressChanged; if (AllVideosInfoList[0].IsMP3Only) { IsdownloadingMP3 = true; if (IsUsingMP3Thumbnail) { CurrentDownloadID = AllVideosInfoList[0].VidID; CurrentDownloadType = DownloadType.MP3Pic; downloader.DownloadVideo("https://www.youtube.com/watch?v=" + AllVideosInfoList[0].VidID, DownloadType.MP3Pic); } else { CurrentDownloadID = AllVideosInfoList[0].VidID; CurrentDownloadType = DownloadType.MP3Only; downloader.DownloadVideo("https://www.youtube.com/watch?v=" + AllVideosInfoList[0].VidID, DownloadType.MP3Only); } } else { IsdownloadingMP3 = false; CurrentDownloadType = DownloadType.CustomQuality; CurrentDownloadID = AllVideosInfoList[0].VidID; VideoQualityInfo NewDownloadInfo = AllVideosInfoList[0]; AudQuality aQuality = new AudQuality(); aQuality.AudNo = NewDownloadInfo.SelectedAudQuality.ToString(); VidQuality vQuality = new VidQuality(); vQuality.VidNo = NewDownloadInfo.SelectedVidQuality.ToString(); foreach (VidQuality quality in NewDownloadInfo.VidQualityList) { if (quality.VidNo == vQuality.VidNo) { vQuality.Format = quality.Format; } } foreach (AudQuality quality in NewDownloadInfo.AudQualityList) { if (quality.AudNo == aQuality.AudNo) { aQuality.Format = quality.Format; } } IsCrossFormat = NewDownloadInfo.IsCrossFormat; CurrentAudQuality = aQuality; CurrentVidQuality = vQuality; downloader.DownloadVideo("https://www.youtube.com/watch/?v=" + NewDownloadInfo.VidID, DownloadType.CustomQuality, aQuality, vQuality); } } else { PlaylistStatus.Dispatcher.Invoke(new Action(() => PlaylistStatus.Content = "Status:")); MessageBox.Show("Completed playlist download", "Finished", MessageBoxButton.OK, MessageBoxImage.Information); } }
private void VideoAudioSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { Slider slider = sender as Slider; UIElement CurrentItem = (UIElement)ListOfVideos.ItemContainerGenerator.ContainerFromItem(ListOfVideos.Items.Count - 1); string videoTitleText = ""; foreach (object item in ListOfVideos.Items) { UIElement currentItem = (UIElement)ListOfVideos.ItemContainerGenerator.ContainerFromItem(item); ContentPresenter currentContentPresenter = (ContentPresenter)currentItem; DataTemplate currentDataTemplate = currentContentPresenter.ContentTemplate; Slider itemSlider = (Slider)currentDataTemplate.FindName("VideoAudioSlider", currentContentPresenter); if (itemSlider == slider) { Label videoTitle = (Label)currentDataTemplate.FindName("VideoTitleLabel", currentContentPresenter); videoTitleText = videoTitle.Content.ToString(); CurrentItem = currentItem; } } VideoQualityInfo CurrentVid = new VideoQualityInfo(); VideoQualityInfo CurrentVidUpdated = new VideoQualityInfo(); foreach (VideoQualityInfo EachVid in VidQualityInfoList) { if (videoTitleText == EachVid.VidTitle) { CurrentVid = EachVid; CurrentVidUpdated = EachVid; } } if (CurrentVid.IsMP3Only) { return; } CurrentVidUpdated.HasSelectedAudio = true; int value = (int)slider.Value; CurrentVidUpdated.SelectedAudQuality = int.Parse(CurrentVidUpdated.AudQualityList[value - 1].AudNo); if (CurrentVidUpdated.HasSelectedAudio && CurrentVidUpdated.HasSelectedVideo) { AudQuality SelectedAudQuality = new AudQuality(); VidQuality SelectedVidQuality = new VidQuality(); foreach (AudQuality quality in CurrentVidUpdated.AudQualityList) { if (quality.AudNo == CurrentVidUpdated.SelectedAudQuality.ToString()) { SelectedAudQuality = quality; } } foreach (VidQuality quality in CurrentVidUpdated.VidQualityList) { if (quality.VidNo == CurrentVidUpdated.SelectedVidQuality.ToString()) { SelectedVidQuality = quality; } } if ((SelectedAudQuality.Format == "webm" && SelectedVidQuality.Format == "mp4") || (SelectedAudQuality.Format == "m4a" && SelectedVidQuality.Format == "webm")) { CurrentVidUpdated.IsCrossFormat = true; } if (CurrentItem.TryFindVisualChildByName("VideoFileSizeLabel", out Label label)) { label.Content = "Total File Size: " + SelectedVidQuality.FileSize + " (VIDEO) + " + SelectedAudQuality.FileSize + " (AUDIO)"; } } VidQualityInfoList.Remove(CurrentVid); VidQualityInfoList.Add(CurrentVidUpdated); AllVideosInfoList = VidQualityInfoList; }
private void VideoComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { //MessageBox.Show(ListOfVideos.Items.CurrentPosition.ToString()); //from https://docs.microsoft.com/en-us/dotnet/framework/wpf/data/how-to-find-datatemplate-generated-elements ComboBox VideoComboBox = sender as ComboBox; UIElement CurrentItem = (UIElement)ListOfVideos.ItemContainerGenerator.ContainerFromItem(ListOfVideos.Items.Count - 1); string videoTitleText = ""; string selectedItemText = ""; foreach (object item in ListOfVideos.Items) { UIElement currentItem = (UIElement)ListOfVideos.ItemContainerGenerator.ContainerFromItem(item); ContentPresenter currentContentPresenter = (ContentPresenter)currentItem; DataTemplate currentDataTemplate = currentContentPresenter.ContentTemplate; ComboBox itemComboBox = (ComboBox)currentDataTemplate.FindName("VideoComboBox", currentContentPresenter); if (itemComboBox == VideoComboBox) { Label videoTitle = (Label)currentDataTemplate.FindName("VideoTitleLabel", currentContentPresenter); videoTitleText = videoTitle.Content.ToString(); // MessageBox.Show(videoTitleText); CurrentItem = currentItem; selectedItemText = itemComboBox.SelectedItem.ToString(); } } if (CurrentItem != null) //This check needs to be replaced with a proper one that actually works. Also, need to change it to get the Comboboxes from the Utils class { VideoQualityInfo CurrentVid = new VideoQualityInfo(); VideoQualityInfo CurrentVidUpdated = new VideoQualityInfo(); foreach (VideoQualityInfo EachVid in VidQualityInfoList) { if (videoTitleText == EachVid.VidTitle) { CurrentVid = EachVid; CurrentVidUpdated = EachVid; } } if (selectedItemText == "MP3 Only") { CurrentVidUpdated.IsMP3Only = true; } else { CurrentVidUpdated.IsMP3Only = false; string[] output0 = Regex.Split(selectedItemText, "ID:"); string[] output1 = output0[1].Split(')'); CurrentVidUpdated.SelectedVidQuality = int.Parse(output1[0]); CurrentVidUpdated.HasSelectedVideo = true; } if (CurrentVidUpdated.IsMP3Only) { if (CurrentItem.TryFindVisualChildByName("VideoFileSizeLabel", out Label label)) { label.Content = "Total File Size: " + CurrentVidUpdated.AudQualityList[CurrentVidUpdated.AudQualityList.Count - 1].FileSize + " (AUDIO ONLY)"; } } else { if (CurrentVidUpdated.HasSelectedAudio && CurrentVidUpdated.HasSelectedVideo) { AudQuality SelectedAudQuality = new AudQuality(); VidQuality SelectedVidQuality = new VidQuality(); foreach (AudQuality quality in CurrentVidUpdated.AudQualityList) { if (quality.AudNo == CurrentVidUpdated.SelectedAudQuality.ToString()) { SelectedAudQuality = quality; } } foreach (VidQuality quality in CurrentVidUpdated.VidQualityList) { if (quality.VidNo == CurrentVidUpdated.SelectedVidQuality.ToString()) { SelectedVidQuality = quality; } } if ((SelectedAudQuality.Format == "webm" && SelectedVidQuality.Format == "mp4") || (SelectedAudQuality.Format == "m4a" && SelectedVidQuality.Format == "webm")) { CurrentVidUpdated.IsCrossFormat = true; } if (CurrentItem.TryFindVisualChildByName("VideoFileSizeLabel", out Label label)) { label.Content = "Total File Size: " + SelectedVidQuality.FileSize + " (VIDEO) + " + SelectedAudQuality.FileSize + " (AUDIO)"; } } } VidQualityInfoList.Remove(CurrentVid); VidQualityInfoList.Add(CurrentVidUpdated); AllVideosInfoList = VidQualityInfoList; } //ContentPresenter CurrentContentPresenter = /*FindVisualChild<ContentPresenter>(CurrentItem)*/ //(ContentPresenter)CurrentItem; /*DataTemplate CurrentDataTemplate = CurrentContentPresenter.ContentTemplate; * Label VideoTitle = (Label)CurrentDataTemplate.FindName("VideoTitleLabel", CurrentContentPresenter); * string VideoTitleText = VideoTitle.Content.ToString(); * MessageBox.Show(VideoTitleText);*/ /* var listView = sender as ListView; * object item = ListOfVideos.Items.CurrentItem; * var itemContainer = ListOfVideos.ItemContainerGenerator.ContainerFromItem(item) as ListViewItem; * * if (itemContainer.TryFindVisualChildByName("VideoTitleLabel", out Label label)) * { * var videoTitleText = label.Content as string; * MessageBox.Show(videoTitleText); * }*/ }
public void ConvertFromMKV(string filename, bool IsToMP4) { ConvertVid = new Process(); ProcessStartInfo ConvertVidInfo = new ProcessStartInfo(AppPath + "\\ConvertDownload.bat"); StreamWriter editBAt = new StreamWriter(AppPath + "\\ConvertDownload.bat"); if (IsToMP4) { editBAt.WriteLine("ffmpeg -i " + '"' + FileNameNoEXT + ".mkv" + '"' + " " + '"' + FileNameNoEXT + ".mp4" + '"'); } else { editBAt.WriteLine("ffmpeg -i " + '"' + FileNameNoEXT + ".mkv" + '"' + " " + '"' + FileNameNoEXT + ".webm" + '"'); } editBAt.Close(); ConvertVidInfo.UseShellExecute = false; ConvertVidInfo.RedirectStandardError = true; ConvertVidInfo.CreateNoWindow = true; ConvertVidInfo.WindowStyle = ProcessWindowStyle.Hidden; ConvertVid.StartInfo = ConvertVidInfo; ConvertVid.ErrorDataReceived += ConvertVid_ErrorDataReceived; ConvertVid.Start(); ConvertVid.BeginErrorReadLine(); ConvertVid.WaitForExit(); ConvertVid.Close(); if (IsToMP4) { if (File.Exists(AppPath + "\\" + FileNameNoEXT + ".mp4")) { SaveDownloadedFile(isDefaultSaveLoc, FileFormats.MP4, FileNameNoEXT, SaveLoc); File.Delete(AppPath + "\\" + FileNameNoEXT + ".mkv"); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } } else { MessageBox.Show("Failed to download video"); } } else { if (File.Exists(AppPath + "\\" + FileNameNoEXT + ".webm")) { SaveDownloadedFile(isDefaultSaveLoc, FileFormats.WEBM, FileNameNoEXT, SaveLoc); File.Delete(AppPath + "\\" + FileNameNoEXT + ".mkv"); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } } else { MessageBox.Show("Failed to download video"); } } DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); IsDownloadRunning = false; DownloadAudQuality = new AudQuality(); DownloadVidQuality = new VidQuality(); FileNameNoEXT = ""; }
private void VidDownloader_DownloadCompleted(DownloadProgress ProgData) { //throw new NotImplementedException(); //MessageBox.Show(ProgData.ProgressInfo + " " + ProgData.ProgType.ToString() + " " + ProgData.DownType + " " + ProgData.ProgressPercentage + "%"); if (IsDownloadingMP3) { //IsDownloadRunning = false; string savepath = ""; string message = ""; if (SaveLoc == "Default") { savepath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); message = " to My Documents"; } else { savepath = SaveLoc; } if (File.Exists(AppPath + "\\" + FileNameNoEXT)) { //MessageBox.Show(FileNameNoEXT); SaveDownloadedFile(isDefaultSaveLoc, FileFormats.MP3, FileNameNoEXT, SaveLoc); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); IsDownloadRunning = false; DownloadAudQuality = new AudQuality(); DownloadVidQuality = new VidQuality(); FileNameNoEXT = ""; //MessageBox.Show("MP3 Downloaded successfully and saved" + message); } else { // MessageBox.Show(FileNameNoEXT); StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); IsDownloadRunning = false; DownloadAudQuality = new AudQuality(); DownloadVidQuality = new VidQuality(); FileNameNoEXT = ""; MessageBox.Show("MP3 failed to download"); } } else { if ((DownloadVidQuality.Format == "mp4" && DownloadAudQuality.Format == "webm") || (DownloadVidQuality.Format == "webm" && DownloadAudQuality.Format == "m4a")) { if (DownloadVidQuality.Format == "mp4") { StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "Converting to MP4")); ConvertingThread = new Thread(() => ConvertFromMKV(FileNameNoEXT, true)); ConvertingThread.Start(); } else { StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "Converting to WEBM")); ConvertingThread = new Thread(() => ConvertFromMKV(FileNameNoEXT, false)); ConvertingThread.Start(); } } else if (DownloadVidQuality.Format == "mp4" && DownloadAudQuality.Format == "m4a") { if (!File.Exists(AppPath + "\\" + FileNameNoEXT + ".mp4")) { StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); IsDownloadRunning = false; DownloadAudQuality = new AudQuality(); DownloadVidQuality = new VidQuality(); FileNameNoEXT = ""; MessageBox.Show("Video failed to download"); return; } SaveDownloadedFile(isDefaultSaveLoc, FileFormats.MP4, FileNameNoEXT, SaveLoc); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); IsDownloadRunning = false; DownloadAudQuality = new AudQuality(); DownloadVidQuality = new VidQuality(); FileNameNoEXT = ""; } else if (DownloadVidQuality.Format == "webm" && DownloadAudQuality.Format == "webm") { if (!File.Exists(AppPath + "\\" + FileNameNoEXT + ".webm")) { StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); IsDownloadRunning = false; DownloadAudQuality = new AudQuality(); DownloadVidQuality = new VidQuality(); FileNameNoEXT = ""; MessageBox.Show("Video failed to download"); return; } SaveDownloadedFile(isDefaultSaveLoc, FileFormats.WEBM, FileNameNoEXT, SaveLoc); if (UsePostDownloadCmd) { Process.Start("cmd.exe", CmdText); } StatusText.Dispatcher.Invoke(new Action(() => StatusText.Content = "")); DownloadProgressBar.Dispatcher.Invoke(new Action(() => DownloadProgressBar.Value = 0)); DownloadStatus.Dispatcher.Invoke(new Action(() => DownloadStatus.Content = "")); IsDownloadRunning = false; DownloadAudQuality = new AudQuality(); DownloadVidQuality = new VidQuality(); FileNameNoEXT = ""; } } }