private void showLoadingDialog() { initDialog = (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS); initDialog.Reset(); initDialog.ShowProgressBar(true); initDialog.SetHeading("Loading Moving Pictures"); initDialog.SetLine(1, string.Empty); initDialog.SetLine(2, initProgressLastAction); initDialog.SetPercentage(initProgressLastPercent); initDialog.Progress(); initDialog.DoModal(GetID); }
/// <summary> /// Called when [show context menu]. /// </summary> protected override void OnShowContextMenu() { GUIListItem selectedItem = listControl.SelectedListItem; string artistName = string.Empty; YouTubeEntry videoEntry; LocalFileStruct file = selectedItem.MusicTag as LocalFileStruct; SiteItemEntry entry = selectedItem.MusicTag as SiteItemEntry; if (file != null) { Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + file.VideoId); Video video = Youtube2MP.request.Retrieve<Video>(videoEntryUrl); videoEntry = video.YouTubeEntry; } else { videoEntry = selectedItem.MusicTag as YouTubeEntry; if (videoEntry == null) { if (entry != null) { GenericListItemCollections genericListItem = Youtube2MP.GetList(entry); if (entry.Provider == "VideoItem" && genericListItem.Items.Count > 0) { videoEntry = genericListItem.Items[0].Tag as YouTubeEntry; } } } if (videoEntry == null) return; Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + Youtube2MP.GetVideoId(videoEntry)); Video video = Youtube2MP.request.Retrieve<Video>(videoEntryUrl); videoEntry = video.YouTubeEntry; } if (videoEntry == null) return; artistName = ArtistManager.Instance.GetArtistName(videoEntry.Title.Text); ArtistItem artistItem = GetArtist(videoEntry); GUIDialogMenu dlg = (GUIDialogMenu) GUIWindowManager.GetWindow((int) Window.WINDOW_DIALOG_MENU); if (dlg == null) return; dlg.Reset(); dlg.SetHeading(Translation.ContextMenu); // menu if (Youtube2MP.player.CurrentSong > -1 || Youtube2MP.temp_player.CurrentSong > -1) dlg.Add(Translation.PlayNext); dlg.Add(Translation.Info); dlg.Add(Translation.RelatedVideos); dlg.Add(Translation.VideoResponses); dlg.Add(string.Format(Translation.AllVideosFromUser, videoEntry.Authors[0].Name)); dlg.Add(Translation.AddPlaylist); dlg.Add(Translation.AddAllPlaylist); if (Youtube2MP.service.Credentials != null) { dlg.Add(Translation.AddFavorites); dlg.Add(Translation.AddWatchLater); } dlg.Add(Translation.Options); dlg.Add(Translation.DownloadVideo); if (!string.IsNullOrEmpty(artistName) && !string.IsNullOrEmpty(ArtistManager.Instance.GetArtistsByName(artistName).Name)) dlg.Add(string.Format(Translation.AllMusicVideosFrom, artistName)); if (!string.IsNullOrEmpty(artistItem.Id)) dlg.Add(Translation.SimilarArtists); dlg.DoModal(GetID); if (dlg.SelectedId == -1) return; if (dlg.SelectedLabelText == Translation.RelatedVideos) { if (videoEntry.RelatedVideosUri != null) { YouTubeQuery query = new YouTubeQuery(videoEntry.RelatedVideosUri.Content); YouTubeFeed vidr = service.Query(query); if (vidr.Entries.Count > 0) { SaveListState(true); addVideos(vidr, false, query); UpdateGui(); } else { Err_message(Translation.NoItemWasFound); } } } else if (dlg.SelectedLabelText == Translation.VideoResponses) { if (videoEntry.VideoResponsesUri != null) { YouTubeQuery query = new YouTubeQuery(videoEntry.VideoResponsesUri.Content); YouTubeFeed vidr = service.Query(query); if (vidr.Entries.Count > 0) { SaveListState(true); addVideos(vidr, false, query); UpdateGui(); } else { Err_message(Translation.NoVideoResponse); } } } else if (dlg.SelectedLabelText == string.Format(Translation.AllVideosFromUser, videoEntry.Authors[0].Name)) { SiteItemEntry newentry = new SiteItemEntry {Provider = new UserVideos().Name}; newentry.SetValue("id", videoEntry.Authors[0].Name); addVideos(Youtube2MP.GetList(newentry), true); } else if (dlg.SelectedLabelText == Translation.AddPlaylist) { VideoInfo inf = SelectQuality(videoEntry); if (inf.Quality != VideoQuality.Unknow) { AddItemToPlayList(selectedItem, inf); } } else if (dlg.SelectedLabelText == Translation.AddAllPlaylist) { VideoInfo inf = SelectQuality(videoEntry); inf.Items = new Dictionary<string, string>(); if (inf.Quality != VideoQuality.Unknow) { GUIDialogProgress dlgProgress = (GUIDialogProgress) GUIWindowManager.GetWindow((int) Window.WINDOW_DIALOG_PROGRESS); if (dlgProgress != null) { dlgProgress.Reset(); dlgProgress.SetHeading(Translation.AddAllPlaylist); dlgProgress.SetLine(1, ""); dlgProgress.SetLine(2, ""); dlgProgress.SetPercentage(0); dlgProgress.Progress(); dlgProgress.ShowProgressBar(true); dlgProgress.StartModal(GetID); } int i = 0; for (int j = 0; j < listControl.Count; j++) { GUIListItem item = listControl[j]; if (dlgProgress != null) { double pr = ((double) i/(double) listControl.Count)*100; dlgProgress.SetLine(1, item.Label); dlgProgress.SetLine(2, i.ToString() + "/" + listControl.Count.ToString()); dlgProgress.SetPercentage((int) pr); dlgProgress.Progress(); if (dlgProgress.IsCanceled) break; } i++; AddItemToPlayList(item, new VideoInfo(inf)); } if (dlgProgress != null) dlgProgress.Close(); } } else if (dlg.SelectedLabelText == Translation.AddFavorites) { try { service.Insert(new Uri(YouTubeQuery.CreateFavoritesUri(null)), videoEntry); } catch (Exception) { Err_message(Translation.WrongRequestWrongUser); } } else if (dlg.SelectedLabelText == Translation.AddWatchLater) { PlayListMember pm = new PlayListMember(); pm.Id = videoEntry.VideoId; Youtube2MP.request.Insert(new Uri("https://gdata.youtube.com/feeds/api/users/default/watch_later"), pm); } else if (dlg.SelectedLabelText == Translation.Options) { DoOptions(); } else if (dlg.SelectedLabelText == Translation.DownloadVideo) { LocalFileStruct fil = Youtube2MP._settings.LocalFile.Get(Youtube2MP.GetVideoId(videoEntry)); if (fil != null && File.Exists(fil.LocalFile)) { Err_message(Translation.ItemAlreadyDownloaded); } else { if (VideoDownloader.IsBusy) { Err_message(Translation.AnotherDonwnloadProgress); dlgProgress = (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS); if (dlgProgress != null) { dlgProgress.Reset(); dlgProgress.SetHeading(Translation.DownloadProgress); dlgProgress.SetLine(1, ""); dlgProgress.SetLine(2, ""); dlgProgress.SetPercentage(0); dlgProgress.Progress(); dlgProgress.ShowProgressBar(true); dlgProgress.DoModal(GetID); } } else { VideoInfo inf = SelectQuality(videoEntry); string streamurl = Youtube2MP.StreamPlaybackUrl(videoEntry, inf); 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); VideoDownloader.Entry = videoEntry; } } } else if (dlg.SelectedLabelText == string.Format(Translation.AllMusicVideosFrom, artistName)) { addVideos(ArtistManager.Instance.Grabber.GetArtistVideosIds(ArtistManager.Instance.GetArtistName(videoEntry)), true); } else if (dlg.SelectedLabelText == Translation.Info) { YoutubeGuiInfoEx scr = (YoutubeGuiInfoEx) GUIWindowManager.GetWindow(29053); scr.YouTubeEntry = videoEntry; //if (entry!=null) //{ // ArtistItem artistItem=ent //} GUIWindowManager.ActivateWindow(29053); } else if (dlg.SelectedLabelText == Translation.PlayNext) { PlayNext(videoEntry); } else if (dlg.SelectedLabelText == Translation.SimilarArtists) { List<ArtistItem> similarartist = new List<ArtistItem>(); similarartist = ArtistManager.Instance.Grabber.GetSimilarArtists(ArtistManager.Instance.GetArtistName(videoEntry)); GenericListItemCollections res = new GenericListItemCollections(); foreach (ArtistItem item in similarartist) { SiteItemEntry newentry = new SiteItemEntry(); newentry.Provider = "Artists"; newentry.SetValue("letter", "false"); newentry.SetValue("id", item.Id); newentry.SetValue("name", item.Name); res.ItemType = ItemType.Artist; try { GenericListItem listItem = new GenericListItem() { Title = item.Name, LogoUrl = string.IsNullOrEmpty(item.Img_url.Trim()) ? "@" : item.Img_url, IsFolder = true, DefaultImage = "defaultArtistBig.png", Tag = newentry }; res.Items.Add(listItem); } catch (Exception exception) { } } res.Title = "Artists/Similar/" + artistItem.Name; addVideos(res, true); } }
/// <summary> /// Called when [show context menu]. /// </summary> protected override void OnShowContextMenu() { GUIListItem selectedItem = listControl.SelectedListItem; YouTubeEntry videoEntry; LocalFileStruct file = selectedItem.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); videoEntry = video.YouTubeEntry; } else { videoEntry = selectedItem.MusicTag as YouTubeEntry; } if (videoEntry == null) return; GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU); if (dlg == null) return; dlg.Reset(); dlg.SetHeading(498); // menu dlg.Add("Related Videos"); dlg.Add("Video responses for this video"); dlg.Add("All videos from this user : "******"Add to playlist"); dlg.Add("Add All to playlist"); dlg.Add("Add to favorites"); dlg.Add("Options"); dlg.Add("Download Video"); dlg.DoModal(GetID); if (dlg.SelectedId == -1) return; switch (dlg.SelectedLabel) { case 0: //relatated { if (videoEntry.RelatedVideosUri != null) { YouTubeQuery query = new YouTubeQuery(videoEntry.RelatedVideosUri.Content); YouTubeFeed vidr = service.Query(query); if (vidr.Entries.Count > 0) { SaveListState(true); addVideos(vidr, false, query); UpdateGui(); } else { Err_message("No item was found !"); } } } break; case 1: //respponse { if (videoEntry.VideoResponsesUri != null) { YouTubeQuery query = new YouTubeQuery(videoEntry.VideoResponsesUri.Content); YouTubeFeed vidr = service.Query(query); if (vidr.Entries.Count > 0) { SaveListState(true); addVideos(vidr, false, query); UpdateGui(); } else { Err_message("No response was found !"); } } } break; case 2: //relatated { if (videoEntry.RelatedVideosUri != null) { Video video = Youtube2MP.request.Retrieve<Video>(new Uri("http://gdata.youtube.com/feeds/api/videos/" + videoEntry.VideoId)); YouTubeQuery query = new YouTubeQuery(string.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads", video.Author)); YouTubeFeed vidr = service.Query(query); if (vidr.Entries.Count > 0) { SaveListState(true); addVideos(vidr, false, query); UpdateGui(); } else { Err_message("No item was found !"); } } } break; case 3: { VideoInfo inf = SelectQuality(videoEntry); if (inf.Quality != VideoQuality.Unknow) { AddItemToPlayList(selectedItem, inf); } } break; case 4: { VideoInfo inf = SelectQuality(videoEntry); inf.Items = new Dictionary<string, string>(); foreach (GUIListItem item in listControl.ListView.ListItems) { AddItemToPlayList(item, new VideoInfo(inf)); } } break; case 5: { try { service.Insert(new Uri(YouTubeQuery.CreateFavoritesUri(null)), videoEntry); } catch (Exception) { Err_message("Wrong request or wrong user identification"); } } break; case 6: DoOptions(); break; case 7: // download { if (Youtube2MP._settings.LocalFile.Get(videoEntry.VideoId) != null) { Err_message("Item already downloaded !"); } else { if (VideoDownloader.IsBusy) { Err_message("Another donwnload is in progress"); dlgProgress = (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS); if (dlgProgress != null) { dlgProgress.Reset(); dlgProgress.SetHeading("Download progress"); dlgProgress.SetLine(1, ""); dlgProgress.SetLine(2, ""); dlgProgress.SetPercentage(0); dlgProgress.Progress(); dlgProgress.ShowProgressBar(true); dlgProgress.DoModal(GetID); } } else { VideoInfo inf = SelectQuality(videoEntry); string streamurl = Youtube2MP.StreamPlaybackUrl(videoEntry, inf); VideoDownloader.AsyncDownload(streamurl, Youtube2MP._settings.DownloadFolder + "\\" + Utils.GetFilename(videoEntry.Title.Text + "{" + videoEntry.VideoId + "}") + Path.GetExtension(streamurl)); VideoDownloader.Entry = videoEntry; } } } break; } }