public void Load() { Items.Clear(); string filename = Config.GetFile(Config.Dir.Config, "youtube.xml"); XmlDocument doc = new XmlDocument(); if (File.Exists(filename)) { try { doc.Load(filename); XmlNode ver = doc.DocumentElement.SelectSingleNode("/LocalFileEnumerator"); XmlNodeList fileList = ver.SelectNodes("Items"); foreach (XmlNode nodefile in fileList) { LocalFileStruct lfs = new LocalFileStruct(); lfs.LocalFile = nodefile.SelectSingleNode("LocalFile").InnerText; lfs.Title = nodefile.SelectSingleNode("Title").InnerText; lfs.VideoId = nodefile.SelectSingleNode("VideoId").InnerText; Items.Add(lfs); } } catch (Exception ex) { Log.Error(ex); } } }
public void Load() { Items.Clear(); string filename = Config.GetFile(Config.Dir.Config, "youtube.xml"); XmlDocument doc = new XmlDocument(); if (File.Exists(filename)) { try { doc.Load(filename); XmlNode ver = doc.DocumentElement.SelectSingleNode("/LocalFileEnumerator"); XmlNodeList fileList = ver.SelectNodes("Items"); foreach (XmlNode nodefile in fileList) { LocalFileStruct lfs = new LocalFileStruct(); lfs.LocalFile = nodefile.SelectSingleNode("LocalFile").InnerText; lfs.Title = nodefile.SelectSingleNode("Title").InnerText; lfs.VideoId = nodefile.SelectSingleNode("VideoId").InnerText; Items.Add(lfs); } } catch(Exception ex) { Log.Error(ex); } } }
private void DoListSelection() { GUIListItem selectedItem = listControl.SelectedListItem; if (selectedItem != null) { if (selectedItem.Label != "..") { YouTubeQuery qu = selectedItem.MusicTag as YouTubeQuery; if (qu != null) { YouTubeFeed vidr = service.Query(qu); Log.Debug("Next page: {0}", qu.Uri.ToString()); if (vidr.Entries.Count > 0) { SaveListState(true); addVideos(vidr, false, qu); UpdateGui(); } } //-------------------- LocalFileStruct file = selectedItem.MusicTag as LocalFileStruct; YouTubeEntry vide; if (file != null) { Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + file.VideoId); Video video = Youtube2MP.request.Retrieve <Video>(videoEntryUrl); vide = video.YouTubeEntry; } else { vide = selectedItem.MusicTag as YouTubeEntry; } if (vide != null) { if (vide.VideoId == null) { ShowVevo(vide.Authors[0].Name); } else { DoPlay(vide, true, listControl.ListView); } } } else { DoBack(); } } GUIWaitCursor.Hide(); //throw new Exception("The method or operation is not implemented."); }
public void AddItemToPlayList(GUIListItem pItem, ref PlayList playList, VideoInfo qa) { if (playList == null || pItem == 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) { 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; playlistItem.Duration = pItem.Duration; playlistItem.MusicTag = qa; playList.Add(playlistItem); } }
/// <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; } }
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, 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 SetLabels(YouTubeEntry vid, string type) { if (vid == null) { ClearLabels(type, false); return; } if (vid == label_last_entry && type == label_last_type) { return; } ClearLabels(type, false); label_last_entry = vid; label_last_type = type; try { if (vid.Duration != null && vid.Duration.Seconds != null) { int sec = int.Parse(vid.Duration.Seconds); int min = sec / 60; GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.Duration", string.Format("{0}:{1:0#}", min, (sec - (min * 60)))); } LocalFileStruct fileStruct = Youtube2MP._settings.LocalFile.Get(Youtube2MP.GetVideoId(vid)); GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.IsDownloaded", fileStruct != null ? "true" : "false"); int watchcount = DatabaseProvider.InstanInstance.GetWatchCount(vid); GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.WatchCount", watchcount.ToString("0,0")); GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.IsWatched", watchcount > 0 ? "true" : "false"); GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.PublishDate", vid.Published.ToShortDateString()); if (vid.Authors != null && vid.Authors.Count > 0) { GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.Autor", vid.Authors[0].Name); } if (vid.Rating != null) { GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.Rating", (vid.Rating.Average * 2).ToString()); GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.RatingText", (vid.Rating.Average * 2).ToString("0.0") + "/10"); } if (vid.Statistics != null) { if (vid.Statistics.ViewCount != null) { GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.ViewCount", Youtube2MP.FormatNumber(vid.Statistics.ViewCount)); } if (vid.Statistics.FavoriteCount != null) { GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.FavoriteCount", Youtube2MP.FormatNumber(vid.Statistics.FavoriteCount)); } } GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.Image", Youtube2MP.GetLocalImageFileName(GetBestUrl(vid.Media.Thumbnails))); if (vid.Media.Description != null) { GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.Summary", vid.Media.Description.Value); } if (vid.YtRating != null && !string.IsNullOrEmpty(vid.YtRating.NumLikes) && !string.IsNullOrEmpty(vid.YtRating.NumDislikes)) { GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.NumLike", Youtube2MP.FormatNumber(vid.YtRating.NumLikes)); GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.NumDisLike", Youtube2MP.FormatNumber(vid.YtRating.NumDislikes)); double numlike = Convert.ToDouble(vid.YtRating.NumLikes); double numdislike = Convert.ToDouble(vid.YtRating.NumDislikes); if (numlike + numdislike > 0) { double proc = numlike / (numdislike + numlike) * 100; GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.PercentLike", proc.ToString()); } } bool ishd = vid.ExtensionElements.Any( extensionElementFactory => extensionElementFactory.XmlPrefix == "yt" && extensionElementFactory.XmlName == "hd"); GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.IsHD", ishd ? "true" : "false"); } catch (Exception ex) { Log.Error(ex); } if (vid.Title.Text.Contains("-")) { GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.Title", vid.Title.Text.Split('-')[1].Trim()); if (type == "NowPlaying") { GUIPropertyManager.SetProperty("#Play.Current.Title", vid.Title.Text.Split('-')[1].Trim().Trim()); } GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Artist.Name", vid.Title.Text.Split('-')[0].Trim()); GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.FanArt", GetFanArtImage(vid.Title.Text.Split('-')[0]).Trim()); } else { GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Video.Title", vid.Title.Text); GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Artist.Name", " "); } if (type != "Curent" || type != "Current") { ArtistManager.Instance.SetSkinProperties(vid, type, false, false); //GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Artist.Name", GetArtistName(vid)); //string imgurl = // ArtistManager.Instance.GetArtistsImgUrl(GUIPropertyManager.GetProperty("#Youtube.fm." + type + ".Artist.Name")); //string artistimg = Youtube2MP.GetLocalImageFileName(imgurl); //if (!string.IsNullOrEmpty(imgurl)) //{ // DownloadFile(imgurl, artistimg); // if (File.Exists(artistimg)) // { // GUIPropertyManager.SetProperty("#Youtube.fm." + type + ".Artist.Image", artistimg); // } //} } }