Пример #1
0
        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);
            }
        }
Пример #2
0
 protected void LoadRelatated(YouTubeEntry entry)
 {
     try
     {
         //Youtube2MP.getIDSimple(Youtube2MP.NowPlayingEntry.Id.AbsoluteUri));
         //GUIControl.ClearControl(GetID, listControl.GetID);
         string relatatedUrl = string.Format("http://gdata.youtube.com/feeds/api/videos/{0}/related",
                                             Youtube2MP.GetVideoId(entry));
         relatated.Clear();
         YouTubeQuery query = new YouTubeQuery(relatatedUrl);
         YouTubeFeed  vidr  = Youtube2MP.service.Query(query);
         // time to time this query return nothing, maybe the quata limit ..
         if (vidr.Entries.Count == 0)
         {
             vidr = Youtube2MP.service.Query(query);
         }
         if (vidr.Entries.Count > 0)
         {
             addVideos(vidr, query);
         }
         if (listControl != null)
         {
             FillRelatedList();
         }
     }
     catch (Exception exception)
     {
         Log.Debug("[YouTube.Fm]Error {0}\n{1}", exception.Message, exception.StackTrace);
     }
 }
        protected ArtistItem GetArtist(YouTubeEntry entry)
        {
            ArtistItem artistItem = DatabaseProvider.InstanInstance.GetArtist(entry);

            if (artistItem != null)
            {
                return(artistItem);
            }
            string vidId = Youtube2MP.GetVideoId(entry);

            artistItem = ArtistManager.Instance.SitesCache.GetByVideoId(vidId) != null
                                ? ArtistManager.Instance.Grabber.GetFromVideoSite(
                ArtistManager.Instance.SitesCache.GetByVideoId(vidId).SIte)
                                : ArtistManager.Instance.Grabber.GetFromVideoId(vidId);

            if (string.IsNullOrEmpty(artistItem.Id) && entry.Title.Text.Contains("-"))
            {
                artistItem =
                    ArtistManager.Instance.GetArtistsByName(entry.Title.Text.Split('-')[0].TrimEnd());
            }

            if (!string.IsNullOrEmpty(artistItem.Id))
            {
                ArtistManager.Instance.Save(artistItem);
                DatabaseProvider.InstanInstance.Save(entry, artistItem);
            }
            return(artistItem);
        }
Пример #4
0
 protected override void OnPageLoad()
 {
     GUIPropertyManager.SetProperty("#currentmodule", "Youtube.Fm/Info");
     if (OldYouTubeEntry == null || (OldYouTubeEntry != null && Youtube2MP.GetVideoId(OldYouTubeEntry) != Youtube2MP.GetVideoId(YouTubeEntry)))
     {
         OldYouTubeEntry = YouTubeEntry;
         ClearInfoLabels();
         //GUIWaitCursor.Init();
         GUIWaitCursor.Show();
         if (!Worker_Fast.IsBusy)
         {
             Worker_Fast.RunWorkerAsync();
         }
         else
         {
             // not a really good method need some rework using Worker_Fast.CancelAsync();
             System.Threading.Thread.Sleep(2000);
             Worker_Fast.RunWorkerAsync();
         }
     }
     base.OnPageLoad();
 }
Пример #5
0
        void updateStationLogoTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            backgroundWorker.RunWorkerAsync();
            WebClient fanartclient = new WebClient();

            try
            {
                infoTimer.Enabled = false;
                lock (locker)
                {
                    string file = GetFanArtImage(GUIPropertyManager.GetProperty("#Youtube.fm.NowPlaying.Artist.Name").Trim());

                    if (File.Exists(file))
                    {
                        GUIPropertyManager.SetProperty("#Youtube.fm.NowPlaying.Video.FanArt", file);
                    }
                    else
                    {
                        if (Youtube2MP._settings.LoadOnlineFanart)
                        {
                            HTBFanArt fanart = new HTBFanArt();
                            if (!File.Exists(file))
                            {
                                fanart.Search(GUIPropertyManager.GetProperty("#Youtube.fm.NowPlaying.Artist.Name").Trim());
                                if (fanart.ImageUrls.Count > 0)
                                {
                                    Log.Debug("Youtube.Fm fanart download {0} to {1}  ", fanart.ImageUrls[0].Url, file);
                                    fanartclient.DownloadFile(fanart.ImageUrls[0].Url, file);
                                    GUIPropertyManager.SetProperty("#Youtube.fm.NowPlaying.Video.FanArt", file);
                                }
                            }
                            else
                            {
                                GUIPropertyManager.SetProperty("#Youtube.fm.NowPlaying.Video.FanArt", file);
                            }
                        }
                    }

                    if (Youtube2MP.NowPlayingEntry != null)
                    {
                        Uri videoEntryUrl =
                            new Uri("http://gdata.youtube.com/feeds/api/videos/" + Youtube2MP.GetVideoId(Youtube2MP.NowPlayingEntry));
                        Video video = Youtube2MP.request.Retrieve <Video>(videoEntryUrl);
                        GUIPropertyManager.SetProperty("#Play.Current.PlotOutline", video.Description);
                        try
                        {
                            Feed <Comment> comments = Youtube2MP.request.GetComments(video);
                            string         cm       = "\n------------------------------------------\n";
                            foreach (Comment c in comments.Entries)
                            {
                                cm += c.Author + " : " + c.Content + "\n------------------------------------------\n";
                            }
                            GUIPropertyManager.SetProperty("#Play.Current.Plot", video.Description + cm);
                            GUIPropertyManager.SetProperty("#Youtube.fm.NowPlaying.Video.Comments", video.Description + cm);
                        }
                        catch (Exception ex)
                        {
                            //Log.Error(ex);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }
Пример #6
0
        void player_PlayBegin(YoutubePlaylistPlayer playlit, PlayListItem item)
        {
            try
            {
                //ClearLabels("NowPlaying");
                VideoInfo info = item.MusicTag as VideoInfo;
                if (info == null)
                {
                    return;
                }

                Log.Debug("YouTube.fm playback started");
                YouTubeEntry en = info.Entry;

                if (en.Authors.Count == 0)
                {
                    Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + Youtube2MP.GetVideoId(en));
                    try
                    {
                        Video video = Youtube2MP.request.Retrieve <Video>(videoEntryUrl);
                        en = video.YouTubeEntry;
                    }
                    catch (Exception)
                    {
                        //vid = null;
                    }
                }

                en.Title.Text = item.Description;
                item.FileName = Youtube2MP.StreamPlaybackUrl(en, info);
                ClearLabels("NowPlaying", true);
                ClearLabels("Next", true);
                Youtube2MP.NowPlayingEntry  = en;
                Youtube2MP.NextPlayingEntry = null;
                //ArtistManager.Instance.SetSkinProperties(Youtube2MP.NextPlayingEntry, "NowPlaying", false, false);
                if (playlit.GetNextItem() != null)
                {
                    VideoInfo nextinfo = playlit.GetNextItem().MusicTag as VideoInfo;
                    if (nextinfo != null)
                    {
                        Youtube2MP.NextPlayingEntry = nextinfo.Entry;
                        //ArtistManager.Instance.SetSkinProperties(Youtube2MP.NextPlayingEntry, "Next", false, false);
                    }
                }
                BackgroundWorker playBeginWorker = new BackgroundWorker();
                playBeginWorker.DoWork += playBeginWorker_DoWork;
                playBeginWorker.RunWorkerAsync();
                Youtube2MP.YouTubePlaying = true;
                GUIPropertyManager.SetProperty("#Youtube.fm.FullScreen.ShowTitle", "true");
                GUIPropertyManager.SetProperty("#Youtube.fm.FullScreen.ShowNextTitle",
                                               Youtube2MP.NextPlayingEntry != null ? "true" : "false");
                _labelTimer.Stop();
                _labelTimer.Start();
            }
            catch (Exception exception)
            {
                Log.Error("Youtube play begin exception");
                Log.Error(exception);
            }
        }
Пример #7
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 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);
                //  }
                //}
            }
        }