private void SaveVideo_Step2(DownloadList saveItems, List<String> loUrlList, bool? enque) { RemoveInvalidUrls(loUrlList); // if no valid urls were returned show error msg if (loUrlList == null || loUrlList.Count == 0) { notification.Show(Translation.Instance.Error, Translation.Instance.UnableToDownloadVideo); return; } // create download list if more than one url if (loUrlList.Count > 1) { saveItems.DownloadItems = new List<DownloadInfo>(); foreach (string url in loUrlList) { VideoInfo vi = saveItems.CurrentItem.VideoInfo.CloneForPlaylist(url, url == loUrlList[0]); string url_new = url; if (url == loUrlList[0]) { url_new = saveItems.CurrentItem.Util.GetPlaylistItemVideoUrl(vi, string.Empty); } DownloadInfo pli = DownloadInfo.Create(vi, saveItems.CurrentItem.Category, saveItems.CurrentItem.Util); pli.Title = string.Format("{0} - {1} / {2}", vi.Title, (saveItems.DownloadItems.Count + 1).ToString(), loUrlList.Count); pli.Url = url_new; pli.OverrideFolder = saveItems.CurrentItem.OverrideFolder; pli.OverrideFileName = saveItems.CurrentItem.OverrideFileName; saveItems.DownloadItems.Add(pli); } // make the first item the current to be saved now saveItems.CurrentItem = saveItems.DownloadItems[0]; loUrlList = new List<string>(new string[] { saveItems.CurrentItem.Url }); } // if multiple quality choices are available show a selection dialogue string urlToSave = loUrlList[0]; if (saveItems.CurrentItem.VideoInfo.PlaybackOptions != null && saveItems.CurrentItem.VideoInfo.PlaybackOptions.Count > 0) { string choice = null; if (saveItems.CurrentItem.VideoInfo.PlaybackOptions.Count > 1) { PlaybackChoices dlg = new PlaybackChoices(); dlg.Owner = this; dlg.lvChoices.ItemsSource = saveItems.CurrentItem.VideoInfo.PlaybackOptions.Keys; var preSelectedItem = saveItems.CurrentItem.VideoInfo.PlaybackOptions.FirstOrDefault(kvp => kvp.Value == urlToSave); if (!string.IsNullOrEmpty(preSelectedItem.Key)) dlg.lvChoices.SelectedValue = preSelectedItem.Key; if (dlg.lvChoices.SelectedIndex < 0) dlg.lvChoices.SelectedIndex = 0; if (dlg.ShowDialog() == true) choice = dlg.lvChoices.SelectedItem.ToString(); } else { choice = saveItems.CurrentItem.VideoInfo.PlaybackOptions.Keys.First(); } if (choice != null) { waitCursor.Visibility = System.Windows.Visibility.Visible; Gui2UtilConnector.Instance.ExecuteInBackgroundAndCallback(delegate() { return saveItems.CurrentItem.VideoInfo.GetPlaybackOptionUrl(choice); }, delegate(Gui2UtilConnector.ResultInfo resultInfo) { waitCursor.Visibility = System.Windows.Visibility.Hidden; if (ReactToResult(resultInfo, Translation.Instance.GettingPlaybackUrlsForVideo)) { SaveVideo_Step3(saveItems, resultInfo.ResultObject as string, enque); } }, true); } } else { SaveVideo_Step3(saveItems, urlToSave, enque); } }
private void Play_Step2(PlayListItem playItem, List<String> urlList, bool goFullScreen) { RemoveInvalidUrls(urlList); // if no valid urls were returned show error msg if (urlList == null || urlList.Count == 0) { notification.Show(Translation.Instance.Error, Translation.Instance.UnableToPlayVideo); return; } // create playlist entries if more than one url if (urlList.Count > 1) { PlayList playbackItems = new PlayList(); foreach (string url in urlList) { VideoInfo vi = playItem.Video.CloneForPlaylist(url, url == urlList[0]); string url_new = url; if (url == urlList[0]) { url_new = SelectedSite.GetPlaylistItemVideoUrl(vi, string.Empty, CurrentPlayList != null && CurrentPlayList.IsPlayAll); } playbackItems.Add(new PlayListItem(vi, playItem.Util) { FileName = url_new }); } if (CurrentPlayList == null) { CurrentPlayList = playbackItems; } else { int currentPlaylistIndex = CurrentPlayListItem != null ? CurrentPlayList.IndexOf(CurrentPlayListItem) : 0; CurrentPlayList.InsertRange(currentPlaylistIndex, playbackItems); } // make the first item the current to be played now playItem = playbackItems[0]; urlList = new List<string>(new string[] { playItem.FileName }); } // play the first or only item string urlToPlay = urlList[0]; if (playItem.Video.PlaybackOptions != null && playItem.Video.PlaybackOptions.Count > 0) { string choice = null; if (playItem.Video.PlaybackOptions.Count > 1) { PlaybackChoices dlg = new PlaybackChoices(); dlg.Owner = this; dlg.lvChoices.ItemsSource = playItem.Video.PlaybackOptions.Keys; var preSelectedItem = playItem.Video.PlaybackOptions.FirstOrDefault(kvp => kvp.Value == urlToPlay); if (!string.IsNullOrEmpty(preSelectedItem.Key)) dlg.lvChoices.SelectedValue = preSelectedItem.Key; if (dlg.lvChoices.SelectedIndex < 0) dlg.lvChoices.SelectedIndex = 0; if (dlg.ShowDialog() == true) choice = dlg.lvChoices.SelectedItem.ToString(); } else { choice = playItem.Video.PlaybackOptions.Keys.First(); } if (choice != null) { playItem.ChosenPlaybackOption = choice; Log.Info("Chosen quality: '{0}'", choice); waitCursor.Visibility = System.Windows.Visibility.Visible; Gui2UtilConnector.Instance.ExecuteInBackgroundAndCallback(delegate() { return playItem.Video.GetPlaybackOptionUrl(choice); }, delegate(Gui2UtilConnector.ResultInfo resultInfo) { waitCursor.Visibility = System.Windows.Visibility.Hidden; if (ReactToResult(resultInfo, Translation.Instance.GettingPlaybackUrlsForVideo)) { Play_Step3(playItem, resultInfo.ResultObject as string, goFullScreen); } }, true); } } else { Play_Step3(playItem, urlToPlay, goFullScreen); } }
void HandleCustomContextMenuEntry(ContextMenuEntry currentEntry, Category aCategory, VideoInfo aVideo) { List<KeyValuePair<string, ContextMenuEntry>> dialogOptions = new List<KeyValuePair<string, ContextMenuEntry>>(); while (true) { bool execute = currentEntry.Action == ContextMenuEntry.UIAction.Execute; if (currentEntry.Action == ContextMenuEntry.UIAction.GetText) { SearchDialog dlg = new SearchDialog() { Owner = this }; dlg.tbxSearch.Text = currentEntry.UserInputText ?? ""; dlg.lblHeading.Text = currentEntry.DisplayText; if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.tbxSearch.Text)) { currentEntry.UserInputText = dlg.tbxSearch.Text; execute = true; } else break; } if (currentEntry.Action == ContextMenuEntry.UIAction.ShowList) { PlaybackChoices dlg = new PlaybackChoices() { Owner = this }; dlg.lblHeading.Content = currentEntry.DisplayText; dialogOptions.Clear(); foreach (var subEntry in currentEntry.SubEntries) { dialogOptions.Add(new KeyValuePair<string, ContextMenuEntry>(subEntry.DisplayText, subEntry)); } dlg.lvChoices.ItemsSource = dialogOptions.Select(dO => dO.Key).ToList(); dlg.lvChoices.SelectedIndex = 0; if (dlg.ShowDialog() != true) break; else currentEntry = dialogOptions[dlg.lvChoices.SelectedIndex].Value; } if (execute) { waitCursor.Visibility = System.Windows.Visibility.Visible; Gui2UtilConnector.Instance.ExecuteInBackgroundAndCallback( delegate() { return SelectedSite.ExecuteContextMenuEntry(aCategory, aVideo, currentEntry); }, delegate(Gui2UtilConnector.ResultInfo resultInfo) { waitCursor.Visibility = System.Windows.Visibility.Hidden; if (ReactToResult(resultInfo, currentEntry.DisplayText)) { if (resultInfo.ResultObject is ContextMenuExecutionResult) { var cmer = resultInfo.ResultObject as ContextMenuExecutionResult; if (!string.IsNullOrEmpty(cmer.ExecutionResultMessage)) { notification.Show(currentEntry.DisplayText, cmer.ExecutionResultMessage); } if (cmer.RefreshCurrentItems) { CategorySelected(SelectedCategory); } if (cmer.ResultItems != null && cmer.ResultItems.Count > 0) { DisplaySearchResultItems(currentEntry.DisplayText, cmer.ResultItems); } } } }); break; } } }
void ShowContextMenuForVideo(VideoInfo video) { List<KeyValuePair<string, ContextMenuEntry>> dialogOptions = new List<KeyValuePair<string, ContextMenuEntry>>(); if (!(SelectedSite is DownloadedVideoUtil)) { dialogOptions.Add(new KeyValuePair<string, ContextMenuEntry>(string.Format("{0} ({1})", Translation.Instance.Download, Translation.Instance.Concurrent), null)); dialogOptions.Add(new KeyValuePair<string, ContextMenuEntry>(string.Format("{0} ({1})", Translation.Instance.Download, Translation.Instance.Queued), null)); if (!(SelectedSite is FavoriteUtil) && OnlineVideoSettings.Instance.FavDB != null) { dialogOptions.Add(new KeyValuePair<string, ContextMenuEntry>(Translation.Instance.AddToFavourites, null)); } } foreach (var entry in SelectedSite.GetContextMenuEntries(SelectedCategory, video)) { dialogOptions.Add(new KeyValuePair<string, ContextMenuEntry>(entry.DisplayText, entry)); } if (dialogOptions.Count > 0) { PlaybackChoices dlg = new PlaybackChoices() { Owner = this }; dlg.lblHeading.Content = string.Format("{0}: {1}", Translation.Instance.Actions, video.Title); dlg.lvChoices.ItemsSource = dialogOptions.Select(dO => dO.Key).ToList(); dlg.lvChoices.SelectedIndex = 0; if (dlg.ShowDialog() == true) { if (dialogOptions[dlg.lvChoices.SelectedIndex].Value == null) { if (dlg.lvChoices.SelectedItem.ToString().Contains(Translation.Instance.Concurrent)) { SaveVideo_Step1(DownloadList.Create(DownloadInfo.Create(video, SelectedCategory, SelectedSite))); } else if (dlg.lvChoices.SelectedItem.ToString().Contains(Translation.Instance.Queued)) { SaveVideo_Step1(DownloadList.Create(DownloadInfo.Create(video, SelectedCategory, SelectedSite)), true); } else if (dlg.lvChoices.SelectedItem.ToString().Contains(Translation.Instance.AddToFavourites)) { AddFavoriteVideo(video); } } else HandleCustomContextMenuEntry(dialogOptions[dlg.lvChoices.SelectedIndex].Value, SelectedCategory, video); } } }
void HandleItemAction() { var prop = lvChoices.SelectedValue as OnlineVideos.Reflection.FieldPropertyDescriptorByRef; string value = site.GetConfigValueAsString(prop); if (prop.IsBool) { var dlgTrueFalse = new PlaybackChoices() { Owner = this }; dlgTrueFalse.lblHeading.Content = string.Format("{0}: {1}", site.Settings.Name, prop.DisplayName); dlgTrueFalse.lvChoices.ItemsSource = new string[] { true.ToString(), false.ToString() }; dlgTrueFalse.lvChoices.SelectedValue = value; if (dlgTrueFalse.ShowDialog() == true) { if (value != dlgTrueFalse.lvChoices.SelectedValue.ToString()) { site.SetConfigValueFromString(prop, dlgTrueFalse.lvChoices.SelectedValue.ToString()); changes = true; GenerateOptions(lvChoices.SelectedIndex); } } } else if (prop.IsEnum) { var dlgEnum = new PlaybackChoices() { Owner = this }; dlgEnum.lblHeading.Content = string.Format("{0}: {1}", site.Settings.Name, prop.DisplayName); dlgEnum.lvChoices.ItemsSource = prop.GetEnumValues(); dlgEnum.lvChoices.SelectedValue = value; if (dlgEnum.ShowDialog() == true) { if (value != dlgEnum.lvChoices.SelectedValue.ToString()) { site.SetConfigValueFromString(prop, dlgEnum.lvChoices.SelectedValue.ToString()); changes = true; GenerateOptions(lvChoices.SelectedIndex); } } } else { var dlgText = new SearchDialog() { Owner = this }; dlgText.tbxSearch.Text = value ?? ""; dlgText.lblHeading.Text = string.Format("{0}: {1}", site.Settings.Name, prop.DisplayName); if (prop.IsPassword) { dlgText.tbxSearch.Visibility = System.Windows.Visibility.Collapsed; dlgText.tbxPasswrd.Visibility = System.Windows.Visibility.Visible; dlgText.tbxPasswrd.Focus(); } if (dlgText.ShowDialog() == true) { var newValue = (prop.IsPassword ? dlgText.tbxPasswrd.Password : dlgText.tbxSearch.Text); if (value != newValue) { try { site.SetConfigValueFromString(prop, newValue); changes = true; GenerateOptions(lvChoices.SelectedIndex); } catch (Exception ex) { MessageBox.Show(this, ex.Message, Translation.Instance.Error); } } } } }