Exemple #1
0
        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 VideoInfo SelectQuality(YouTubeEntry vid)
 {
     return(Youtube2MP.SelectQuality(vid));
 }