コード例 #1
0
        public override void Play(SearchResultItem resultItem)
        {
            YouTubeEntry entry = resultItem.MetaData["entry"] as YouTubeEntry;

            YoutubeGUIBase.SetLabels(entry, "NowPlaying");
            Youtube2MP.NowPlayingEntry = entry;
            VideoInfo info = new VideoInfo();

            g_Player.PlayVideoStream(Youtube2MP.StreamPlaybackUrl(entry, info));
            if (g_Player.Playing)
            {
                if (Youtube2MP._settings.ShowNowPlaying)
                {
                    GUIWindowManager.ActivateWindow(29052);
                }
                else
                {
                    g_Player.ShowFullScreenWindow();
                }
            }

            if (!g_Player.Playing)
            {
                GUIDialogOK dlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
                if (dlgOK != null)
                {
                    dlgOK.SetHeading(25660);
                    dlgOK.SetLine(1, "Unable to playback the item ! ");
                    dlgOK.SetLine(2, "");
                    dlgOK.DoModal(GUIWindowManager.ActiveWindow);
                }
            }
        }
コード例 #2
0
        void player_PlayBegin(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;
                item.FileName = Youtube2MP.StreamPlaybackUrl(en, info);
                Song song = Youtube2MP.YoutubeEntry2Song(en);

                Youtube2MP.NowPlayingEntry = en;
                Youtube2MP.NowPlayingSong  = song;
                SetLabels(en, "NowPlaying");
                if (listControl != null)
                {
                    GUIControl.ClearControl(GetID, listControl.GetID);
                    relatated.Clear();
                }
                infoTimer.Enabled = true;
            }
            catch
            {
            }
        }
コード例 #3
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);
     }
 }
コード例 #4
0
        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);
        }
コード例 #5
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);
            }
        }
コード例 #6
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);
            }
        }
コード例 #7
0
 private void button7_Click(object sender, EventArgs e)
 {
     if (list_startpage.SelectedItems.Count > 0)
     {
         SiteItemEntry entry = list_startpage.SelectedItems[0].Tag as SiteItemEntry;
         FormItemList  dlg   = new FormItemList(Youtube2MP.GetList(entry));
         dlg.ShowDialog();
     }
 }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        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;
            }
        }
コード例 #10
0
        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);
                }
            }
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
            }
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }
コード例 #15
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();
 }
コード例 #16
0
        public void AddItemToPlayList(YouTubeEntry vid, ref PlayList playList, VideoInfo qa)
        {
            if (playList == null || vid == null)
            {
                return;
            }
            string PlayblackUrl = "";

            List <GUIListItem> list = new List <GUIListItem>();

            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 = vid.Title.Text;
                try
                {
                    playlistItem.Duration = Convert.ToInt32(vid.Duration.Seconds, 10);
                }
                catch
                {
                }
                playlistItem.MusicTag = qa;
                playList.Add(playlistItem);
            }
        }
コード例 #17
0
        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);
                //  }
                //}
            }
        }
コード例 #18
0
        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);
            }
        }
コード例 #19
0
        public VideoInfo SelectQuality(YouTubeEntry vid)
        {
            VideoInfo info = new VideoInfo();

            info.Get(Youtube2MP.getIDSimple(vid.AlternateUri.Content));
            if (!string.IsNullOrEmpty(info.Reason))
            {
                Err_message(info.Reason);
                info.Quality = VideoQuality.Unknow;
                return(info);
            }

            switch (Youtube2MP._settings.VideoQuality)
            {
            case 0:
                info.Quality = VideoQuality.Normal;
                break;

            case 1:
                info.Quality = VideoQuality.High;
                break;

            case 2:
                info.Quality = VideoQuality.HD;
                break;

            case 3:
                info.Quality = VideoQuality.FullHD;
                break;

            case 4:
            {
                string title = vid.Title.Text;
                if (info.FmtMap.Contains("18"))
                {
                    info.Quality = VideoQuality.High;
                }
                if (info.FmtMap.Contains("22"))
                {
                    info.Quality = VideoQuality.HD;
                }
                if (info.FmtMap.Contains("37"))
                {
                    info.Quality = VideoQuality.FullHD;
                }
                break;
            }

            case 5:
            {
                GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
                if (dlg == null)
                {
                    info.Quality = VideoQuality.Normal;
                }
                dlg.Reset();
                dlg.SetHeading("Select video quality");
                dlg.Add("Normal quality");
                dlg.Add("High quality");
                if (info.FmtMap.Contains("22/"))
                {
                    dlg.Add("HD quality");
                }
                if (info.FmtMap.Contains("37"))
                {
                    dlg.Add("Full HD quality");
                }
                dlg.DoModal(GetID);
                if (dlg.SelectedId == -1)
                {
                    info.Quality = VideoQuality.Unknow;
                }
                switch (dlg.SelectedLabel)
                {
                case 0:
                    info.Quality = VideoQuality.Normal;
                    break;

                case 1:
                    info.Quality = VideoQuality.High;
                    break;

                case 2:
                    info.Quality = VideoQuality.HD;
                    break;

                case 3:
                    info.Quality = VideoQuality.FullHD;
                    break;
                }
            }
            break;
            }
            return(info);
        }
コード例 #20
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);
            }
        }
コード例 #21
0
 public VideoInfo SelectQuality(YouTubeEntry vid)
 {
     return(Youtube2MP.SelectQuality(vid));
 }
コード例 #22
0
        void Worker_FanArt_DoWork(object sender, DoWorkEventArgs e)
        {
            if (string.IsNullOrEmpty(GUIPropertyManager.GetProperty("#Youtube.fm.Info.Artist.Name").Trim()))
            {
                return;
            }
            try
            {
                string file = GetFanArtImage(GUIPropertyManager.GetProperty("#Youtube.fm.Info.Artist.Name"));

                if (File.Exists(file) && imgFanArt != null)
                {
                    Log.Debug("Youtube.Fm local fanart {0} loaded ", file);
                    imgFanArt.Visible  = true;
                    imgFanArt.FileName = file;
                    imgFanArt.DoUpdate();
                    return;
                }

                if (Youtube2MP._settings.LoadOnlineFanart && !Client.IsBusy)
                {
                    HTBFanArt fanart = new HTBFanArt();
                    //file = GetFanArtImage(GUIPropertyManager.GetProperty("#Youtube.fm.Info.Artist.Name"));
                    if (!File.Exists(file))
                    {
                        fanart.Search(GUIPropertyManager.GetProperty("#Youtube.fm.Info.Artist.Name"));
                        Log.Debug("Youtube.Fm found {0} online fanarts for {1}", fanart.ImageUrls.Count,
                                  GUIPropertyManager.GetProperty("#Youtube.fm.Info.Artist.Name"));
                        if (fanart.ImageUrls.Count > 0)
                        {
                            Log.Debug("Youtube.Fm fanart download {0} to {1}  ", fanart.ImageUrls[0].Url, file);
                            Youtube2MP.DownloadFile(fanart.ImageUrls[0].Url, file);
                            GUIPropertyManager.SetProperty("#Youtube.fm.Info.Video.FanArt", file);
                            Log.Debug("Youtube.Fm fanart {0} loaded ", file);
                            if (imgFanArt != null)
                            {
                                imgFanArt.Visible  = true;
                                imgFanArt.FileName = file;
                                imgFanArt.DoUpdate();
                            }
                        }
                        else
                        {
                            if (imgFanArt != null)
                            {
                                imgFanArt.Visible = false;
                            }
                        }
                    }
                    else
                    {
                        GUIPropertyManager.SetProperty("#Youtube.fm.Info.Video.FanArt", file);
                        if (imgFanArt != null)
                        {
                            imgFanArt.Visible  = true;
                            imgFanArt.FileName = file;
                            imgFanArt.DoUpdate();
                        }
                    }
                }
                else
                {
                    if (imgFanArt != null)
                    {
                        imgFanArt.Visible = false;
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }
コード例 #23
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();
            }
        }
コード例 #24
0
        /// <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;
            }
        }
コード例 #25
0
 public void Err_message(string message)
 {
     Youtube2MP.Err_message(message);
 }