void Worker_Youtube_DoWork(object sender, DoWorkEventArgs e) { try { Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + Youtube2MP.GetVideoId(YouTubeEntry)); Video video = Youtube2MP.request.Retrieve <Video>(videoEntryUrl); Feed <Comment> comments = Youtube2MP.request.GetComments(video); string cm = "\n------------------------------------------\n"; foreach (Comment c in comments.Entries) { cm += c.Author + " : " + c.Content + "------------------------------------------\n"; } GUIPropertyManager.SetProperty("#Youtube.fm.Info.Video.Comments", cm); string vidimg = GetBestUrl(YouTubeEntry.Media.Thumbnails); string vidfile = Youtube2MP.GetLocalImageFileName(vidimg); if (!string.IsNullOrEmpty(vidimg)) { if (!File.Exists(vidfile)) { GUIPropertyManager.SetProperty("#Youtube.fm.Info.Video.Image", " "); Youtube2MP.DownloadFile(vidimg, vidfile); } } GUIPropertyManager.SetProperty("#Youtube.fm.Info.Video.Image", vidfile); } catch (Exception exception) { Log.Error(exception); } }
void item_OnRetrieveArt(GUIListItem item) { YouTubeEntry entry = item.MusicTag as YouTubeEntry; string imageFile = Youtube2MP.GetLocalImageFileName(GetBestUrl(entry.Media.Thumbnails)); if (File.Exists(imageFile)) { item.ThumbnailImage = imageFile; item.IconImage = imageFile; item.IconImageBig = imageFile; } }
void playBeginWorker_DoWork(object sender, DoWorkEventArgs e) { try { GUIPropertyManager.SetProperty("#Play.Current.Artist", GUIPropertyManager.GetProperty("#Youtube.fm.NowPlaying.Artist.Name")); GUIPropertyManager.SetProperty("#Play.Current.Title", GUIPropertyManager.GetProperty("#Youtube.fm.NowPlaying.Video.Title")); if (Youtube2MP.NowPlayingEntry.Media != null) { GUIPropertyManager.SetProperty("#Play.Current.Thumb", Youtube2MP.GetLocalImageFileName( GetBestUrl(Youtube2MP.NowPlayingEntry.Media.Thumbnails))); } if (Youtube2MP.NowPlayingEntry.Rating != null) { GUIPropertyManager.SetProperty("#Play.Current.Rating", (Youtube2MP.NowPlayingEntry.Rating.Average * 2).ToString()); } SetLabels(Youtube2MP.NowPlayingEntry, "NowPlaying"); SetLabels(Youtube2MP.NextPlayingEntry, "Next"); DatabaseProvider.InstanInstance.SavePlayData(Youtube2MP.NowPlayingEntry, DateTime.Now); ArtistManager.Instance.SetSkinProperties(Youtube2MP.NowPlayingEntry, "NowPlaying", true, true); ArtistManager.Instance.SetSkinProperties(Youtube2MP.NextPlayingEntry, "Next", true, true); relatated.Clear(); similar.Clear(); if (GUIWindowManager.ActiveWindow == (int)GetID) { if (listControl != null) { GUIControl.ClearControl(GetID, listControl.GetID); } if (listsimilar != null) { GUIControl.ClearControl(GetID, listsimilar.GetID); } } if (Youtube2MP._settings.LastFmNowPlay) { Youtube2MP.LastFmProfile.NowPlaying(Youtube2MP.NowPlayingEntry); } infoTimer.Enabled = true; _lastFmTimer.Stop(); _lastFmTimer.Start(); Track.TrackPlay(); } catch (Exception exception) { Log.Error(exception); } }
public void OnDownloadTimedEvent() { if (!Client.IsBusy && downloaQueue.Count > 0) { curentDownlodingFile = (DownloadFileObject)downloaQueue.Dequeue(); try { if (curentDownlodingFile.ListItem != null) { SiteItemEntry siteItemEntry = curentDownlodingFile.ListItem.MusicTag as SiteItemEntry; if (siteItemEntry != null && !string.IsNullOrEmpty(siteItemEntry.GetValue("id"))) { ArtistItem artistItem = ArtistManager.Instance.GetArtistsById(siteItemEntry.GetValue("id")); if (string.IsNullOrEmpty(curentDownlodingFile.Url) || curentDownlodingFile.Url.Contains("@") || curentDownlodingFile.Url.Contains("ytimg.com")) { try { Artist artist = new Artist(artistItem.Name, Youtube2MP.LastFmProfile.Session); artistItem.Img_url = artist.GetImageURL(ImageSize.Huge); ArtistManager.Instance.Save(artistItem); curentDownlodingFile.Url = artistItem.Img_url; curentDownlodingFile.FileName = Youtube2MP.GetLocalImageFileName(curentDownlodingFile.Url); } catch { } } } } if (!string.IsNullOrEmpty(curentDownlodingFile.FileName) && !File.Exists(curentDownlodingFile.FileName)) { try { Client.DownloadFileAsync(new Uri(curentDownlodingFile.Url), Path.GetTempPath() + @"\station.png"); } catch { downloaQueue.Enqueue(curentDownlodingFile); } } else { OnDownloadTimedEvent(null, null); } } catch (Exception ex) { Log.Error(ex); } } }
public string DownloadImage(string Url, GUIListItem listitem) { if (string.IsNullOrEmpty(Url)) { return(string.Empty); } string localFile = Youtube2MP.GetLocalImageFileName(Url); if (!File.Exists(localFile) && !string.IsNullOrEmpty(Url)) { downloaQueue.Enqueue(new DownloadFileObject(localFile, Url, listitem)); } return(localFile); }
protected ArtistItem LoadSimilarArtists(YouTubeEntry entry) { //if (listsimilar != null) //{ similar.Clear(); ArtistItem artistItem = GetArtist(entry); string artistname = ArtistManager.Instance.GetArtistName(entry); if (!string.IsNullOrEmpty(artistname)) { List <ArtistItem> items = ArtistManager.Instance.Grabber.GetSimilarArtists(artistname); foreach (ArtistItem aitem in items) { GUIListItem item = new GUIListItem(); // and add station name & bitrate item.Label = aitem.Name; item.Label2 = ""; item.IsFolder = true; string imageFile = Youtube2MP.GetLocalImageFileName(aitem.Img_url); if (File.Exists(imageFile)) { item.ThumbnailImage = imageFile; item.IconImage = imageFile; item.IconImageBig = imageFile; } else { MediaPortal.Util.Utils.SetDefaultIcons(item); DownloadImage(aitem.Img_url, item); } item.MusicTag = aitem; similar.Add(item); } OnDownloadTimedEvent(null, null); } if (listsimilar != null) { FillSimilarList(); } //} return(artistItem); }
protected void addVideos(YouTubeFeed videos, YouTubeQuery qu) { downloaQueue.Clear(); foreach (YouTubeEntry entry in videos.Entries) { GUIListItem item = new GUIListItem(); // and add station name & bitrate item.Label = entry.Title.Text; //ae.Entry.Author.Name + " - " + ae.Entry.Title.Content; item.Label2 = ""; item.IsFolder = false; try { item.Duration = Convert.ToInt32(entry.Duration.Seconds, 10); if (entry.Rating != null) { item.Rating = (float)entry.Rating.Average; } } catch { } string imageFile = Youtube2MP.GetLocalImageFileName(GetBestUrl(entry.Media.Thumbnails)); if (File.Exists(imageFile)) { item.ThumbnailImage = imageFile; item.IconImage = imageFile; item.IconImageBig = imageFile; } else { MediaPortal.Util.Utils.SetDefaultIcons(item); item.OnRetrieveArt += item_OnRetrieveArt; DownloadImage(GetBestUrl(entry.Media.Thumbnails), item); //DownloadImage(GetBestUrl(entry.Media.Thumbnails), item); } item.MusicTag = entry; relatated.Add(item); } //OnDownloadTimedEvent(null, null); }
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); // } //} } }