private void Downloader_DownloadFinished(object sender, EventArgs e) { Dispatcher.CurrentDispatcher.Invoke((Action)async delegate // <--- HERE { var videoInfo = ((VideoDownloader)sender).Video; var video = VideoDetails.FirstOrDefault(a => a.Titel == videoInfo.Title); if (video != null) { if (video.ProgressPercentage == 100) { if (video.CaptionTracksEnabled) { using (FetchSubtitelURL sub = new FetchSubtitelURL()) sub.DownloadSubtitel(video, videoInfo.ListCaptionTracks); } video.DownlaodStatus = DownlaodStatus.End; } else { video.DownlaodStatus = DownlaodStatus.Cancel; } await Loging.SaveList(VideoDetails); if (IsDownloadAll && video.ProgressPercentage == 100) { startDownload(false); } } }); //Thread t = new Thread(() => { // w = new NotificationWin(); // w.Show(); //}); //t.SetApartmentState(ApartmentState.STA); //t.Start(); }
private void configRelayCommand_FetchVideoCommand() { FetchVideoCommand = new RelayCommand(o => { var copyText = ""; if (string.IsNullOrWhiteSpace(FullUrl)) { copyText = System.Windows.Clipboard.GetText(System.Windows.TextDataFormat.Text); if (Porter.Model.Helper.UrlIsValid(copyText)) { FullUrl = copyText; } } if (Porter.Model.Helper.UrlIsValid(FullUrl)) { var childWindow = new PorterTube.ChildWindowView.ChildWindowView(); childWindow.Closed += (list => { customDownloadResolver(list); if (list.Count > 0) { System.Windows.Application.Current.Dispatcher.Invoke(async() => { for (int i = VideoDetails.Count - 1; i >= 0; i--) { var videoID = VideoDetails[i].VideoID; bool any = list.ToList().Any(l => l.VideoID == videoID); if (any) { VideoDetails.RemoveAt(i); } } list.ToList().ForEach(a => VideoDetails.Add(a)); await Loging.SaveList(VideoDetails); }); } }); //------------------- var type = DownloadModel.GetUrlType(FullUrl); KeyValuePair <UrlType, string> urlType = new KeyValuePair <UrlType, string>(); if (type != null) { if (type.Count == 2) { var ruslt = System.Windows.Forms.MessageBox.Show(text: "This video is a part of a playlist. Would you like to download play list?", caption: "PorterTube Application.", buttons: MessageBoxButtons.YesNoCancel); if (ruslt.ToString() == "Yes") { urlType = type.FirstOrDefault(a => a.Key == UrlType.List); childWindow.Show(urlType); } else if (ruslt.ToString() == "No") { urlType = type.FirstOrDefault(a => a.Key == UrlType.Video); childWindow.Show(urlType); } } else if (type.Count == 1) { var resultKVP = (from kvp in type select new KeyValuePair <UrlType, string>(kvp.Key, kvp.Value)).FirstOrDefault(); childWindow.Show(resultKVP); } } //------------------- } else { System.Windows.Forms.MessageBox.Show("Invalid URL"); } }, o => true); }