protected override void OnShowContextMenu() { if (Youtube2MP.NowPlayingEntry == null) { base.OnShowContextMenu(); return; } YouTubeEntry videoEntry = Youtube2MP.NowPlayingEntry; GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU); if (dlg == null) { return; } dlg.Reset(); dlg.SetHeading(Translation.ContextMenu); // menu dlg.AddLocalizedString(941); dlg.AddLocalizedString(970); dlg.Add(Translation.Info); if (Youtube2MP.service.Credentials != null) { dlg.Add(Translation.AddFavorites); } dlg.Add(Translation.DownloadVideo); dlg.DoModal(GetID); if (dlg.SelectedId == -1) { return; } if (dlg.SelectedLabelText == Translation.Info) { YoutubeGuiInfoEx scr = (YoutubeGuiInfoEx)GUIWindowManager.GetWindow(29053); scr.YouTubeEntry = videoEntry; GUIWindowManager.ActivateWindow(29053); } if (dlg.SelectedLabelText == Translation.AddFavorites) { try { Youtube2MP.service.Insert(new Uri(YouTubeQuery.CreateFavoritesUri(null)), videoEntry); } catch (Exception) { Youtube2MP.Err_message(Translation.WrongRequestWrongUser); } } if (dlg.SelectedLabelText == Translation.DownloadVideo) { LocalFileStruct fil = Youtube2MP._settings.LocalFile.Get(Youtube2MP.GetVideoId(videoEntry)); if (fil != null && File.Exists(fil.LocalFile)) { Youtube2MP.Err_message(Translation.ItemAlreadyDownloaded); } else { if (Youtube2MP.VideoDownloader.IsBusy) { Youtube2MP.Err_message(Translation.AnotherDonwnloadProgress); } else { VideoInfo inf = Youtube2MP.SelectQuality(videoEntry); string streamurl = Youtube2MP.StreamPlaybackUrl(videoEntry, inf); Youtube2MP.VideoDownloader.AsyncDownload(streamurl, Youtube2MP._settings.DownloadFolder + "\\" + Utils.MakeFileName(Utils.GetFilename(videoEntry.Title.Text + "{" + Youtube2MP.GetVideoId(videoEntry) + "}")) + Path.GetExtension(streamurl) + ".___"); GUIPropertyManager.SetProperty("#Youtube.fm.IsDownloading", "true"); GUIPropertyManager.SetProperty("#Youtube.fm.Download.Progress", "0"); GUIPropertyManager.SetProperty("#Youtube.fm.Download.Item", videoEntry.Title.Text); DatabaseProvider.InstanInstance.Save(videoEntry); Youtube2MP.VideoDownloader.Entry = videoEntry; } } } if (dlg.SelectedId == 941) { ShowAspectRatioMenu(); } if (dlg.SelectedId == 970) { GUIWindowManager.IsOsdVisible = false; GUIGraphicsContext.IsFullScreenVideo = false; GUIWindowManager.ShowPreviousWindow(); } }
public void AddItemToPlayList(GUIListItem pItem, VideoInfo qa) { PlayList playList = Youtube2MP.player.GetPlaylist(PlayListType.PLAYLIST_MUSIC_VIDEO); AddItemToPlayList(pItem, ref playList, qa); }
public VideoInfo SelectQuality(YouTubeEntry vid) { VideoInfo info = new VideoInfo(); info.Get(Youtube2MP.getIDSimple(vid.AlternateUri.Content)); if (!string.IsNullOrEmpty(info.Reason)) { Err_message(info.Reason); info.Quality = VideoQuality.Unknow; return(info); } switch (Youtube2MP._settings.VideoQuality) { case 0: info.Quality = VideoQuality.Normal; break; case 1: info.Quality = VideoQuality.High; break; case 2: info.Quality = VideoQuality.HD; break; case 3: info.Quality = VideoQuality.FullHD; break; case 4: { string title = vid.Title.Text; if (info.FmtMap.Contains("18")) { info.Quality = VideoQuality.High; } if (info.FmtMap.Contains("22")) { info.Quality = VideoQuality.HD; } if (info.FmtMap.Contains("37")) { info.Quality = VideoQuality.FullHD; } break; } case 5: { GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (dlg == null) { info.Quality = VideoQuality.Normal; } dlg.Reset(); dlg.SetHeading("Select video quality"); dlg.Add("Normal quality"); dlg.Add("High quality"); if (info.FmtMap.Contains("22/")) { dlg.Add("HD quality"); } if (info.FmtMap.Contains("37")) { dlg.Add("Full HD quality"); } dlg.DoModal(GetID); if (dlg.SelectedId == -1) { info.Quality = VideoQuality.Unknow; } switch (dlg.SelectedLabel) { case 0: info.Quality = VideoQuality.Normal; break; case 1: info.Quality = VideoQuality.High; break; case 2: info.Quality = VideoQuality.HD; break; case 3: info.Quality = VideoQuality.FullHD; break; } } break; } return(info); }
public void AddItemToPlayList(GUIListItem pItem, ref PlayList playList, VideoInfo qa, bool check) { if (playList == null || pItem == null) { return; } if (pItem.MusicTag == null) { return; } string PlayblackUrl = ""; YouTubeEntry vid; LocalFileStruct file = pItem.MusicTag as LocalFileStruct; if (file != null) { Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + file.VideoId); Video video = Youtube2MP.request.Retrieve <Video>(videoEntryUrl); vid = video.YouTubeEntry; } else { vid = pItem.MusicTag as YouTubeEntry; if (vid == null && check) { SiteItemEntry entry = pItem.MusicTag as SiteItemEntry; if (entry != null) { GenericListItemCollections genericListItem = Youtube2MP.GetList(entry); if (entry.Provider == "VideoItem" && genericListItem.Items.Count > 0) { vid = genericListItem.Items[0].Tag as YouTubeEntry; } } } if (vid != null && vid.Authors.Count == 0 && check) { Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + Youtube2MP.GetVideoId(vid)); try { Video video = Youtube2MP.request.Retrieve <Video>(videoEntryUrl); vid = video.YouTubeEntry; } catch (Exception) { vid = null; } } } if (vid != null) { if (vid.Media.Contents.Count > 0) { PlayblackUrl = string.Format("http://www.youtube.com/v/{0}", Youtube2MP.getIDSimple(vid.Id.AbsoluteUri)); } else { PlayblackUrl = vid.AlternateUri.ToString(); } PlayListItem playlistItem = new PlayListItem(); playlistItem.Type = PlayListItem.PlayListItemType.VideoStream; // Playlists.PlayListItem.PlayListItemType.Audio; qa.Entry = vid; playlistItem.FileName = PlayblackUrl; playlistItem.Description = pItem.Label; if (vid.Duration != null && vid.Duration.Seconds != null) { playlistItem.Duration = Convert.ToInt32(vid.Duration.Seconds, 10); } playlistItem.MusicTag = qa; playList.Add(playlistItem); } }
public void BackGroundDoPlay(object param_) { PlayParams param = (PlayParams)param_; YouTubeEntry vid = param.vid; bool fullscr = param.fullscr; GUIFacadeControl facade = param.facade; if (vid != null) { GUIWaitCursor.Hide(); VideoInfo qa = SelectQuality(vid); if (qa.Quality == VideoQuality.Unknow) { Youtube2MP.PlayBegin = false; return; } GUIWaitCursor.Show(); Youtube2MP.temp_player.Reset(); Youtube2MP.temp_player.RepeatPlaylist = true; Youtube2MP.temp_player.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC_VIDEO; PlayList playlist = Youtube2MP.temp_player.GetPlaylist(PlayListType.PLAYLIST_MUSIC_VIDEO); playlist.Clear(); g_Player.PlayBackStopped -= g_Player_PlayBackStopped; g_Player.PlayBackEnded -= g_Player_PlayBackEnded; g_Player.PlayBackStopped += g_Player_PlayBackStopped; g_Player.PlayBackEnded += g_Player_PlayBackEnded; int selected = 0; if (facade != null) { int dif = 0; qa.Items = new Dictionary <string, string>(); if (facade[0].IsFolder) { dif++; } selected = facade.SelectedListItemIndex - dif; for (int i = 0; i < facade.Count; i++) { try { AddItemToPlayList(facade[i], ref playlist, new VideoInfo(qa), false); } catch (Exception ex) { Log.Error(ex); } } } else { AddItemToPlayList(vid, ref playlist, qa, -1); Youtube2MP.temp_player.RepeatPlaylist = false; } PlayListPlayer.SingletonPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_NONE; Youtube2MP.player.CurrentPlaylistType = PlayListType.PLAYLIST_NONE; g_Player.Stop(); Youtube2MP.temp_player.Play(selected); GUIWaitCursor.Hide(); if (g_Player.Playing && fullscr) { if (_setting.ShowNowPlaying) { if (GUIWindowManager.ActiveWindow != 29052) { GUIWindowManager.ActivateWindow(29052); } } else { g_Player.ShowFullScreenWindow(); } } if (!g_Player.Playing) { Err_message("Unable to playback the item ! "); } } GUIWaitCursor.Hide(); Youtube2MP.PlayBegin = false; }
public static string StreamPlaybackUrl(string vidurl, VideoInfo qu) { return(youtubecatch1("/" + getIDSimple(vidurl), qu)); }