Ejemplo n.º 1
0
 public void CreateFeedEntryTest()
 {
     Uri uriBase = null; // TODO: Initialize to an appropriate value
     IService iService = null; // TODO: Initialize to an appropriate value
     YouTubeFeed target = new YouTubeFeed(uriBase, iService); // TODO: Initialize to an appropriate value
     YouTubeEntry entry  = target.CreateFeedEntry() as YouTubeEntry;
     Assert.IsNotNull(entry);
 }
        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);
        }
        void addVideos(YouTubeFeed videos, bool level,YouTubeQuery qu)
        {
            int count = 0;
              if (level)
              {
            GUIListItem item = new GUIListItem();
            item.Label = "..";
            item.IsFolder = true;
            Utils.SetDefaultIcons(item);
            listControl.Add(item);
              }
              //GUIPropertyManager.SetProperty("#currentmodule", "Youtube.Fm/" + videos.Title.Text);
              GUIPropertyManager.SetProperty("#currentmodule",  videos.Title.Text);
              updateStationLogoTimer.Enabled = false;
              downloaQueue.Clear();
              foreach (YouTubeEntry entry in videos.Entries)
              {
            if (filterVideoContens(entry))
            {
              GUIListItem item = new GUIListItem();
              // and add station name & bitrate
              item.Label = entry.Title.Text;
              item.IsFolder = false;
              count++;
              try
              {
            if (entry.Duration != null)
              item.Duration = Convert.ToInt32(entry.Duration.Seconds, 10);
            item.Label2 = Utils.SecondsToHMSString(item.Duration);
            if (entry.Rating != null)
              item.Rating = (float) entry.Rating.Average*2;
              }
              catch
              {

              }

              string imageFile = Youtube2MP.GetLocalImageFileName(GetBestUrl(entry.Media.Thumbnails));
              if (File.Exists(imageFile))
              {
            item.ThumbnailImage = imageFile;
            item.IconImage = imageFile;
            item.IconImageBig = imageFile;
              }
              else
              {
            Utils.SetDefaultIcons(item);
            DownloadImage(GetBestUrl(entry.Media.Thumbnails), item);
              }
              item.MusicTag = entry;
              item.OnItemSelected+=item_OnItemSelected;
              listControl.Add(item);
            }
              }
              if (qu.NumberToRetrieve > 0 && videos.TotalResults > qu.NumberToRetrieve)
              {
            GUIListItem item = new GUIListItem();
            item.Label = string.Format(Translation.NextPage+" {0} - {1} ", qu.StartIndex + count, qu.StartIndex + qu.NumberToRetrieve + count);
            qu.StartIndex += qu.NumberToRetrieve;
            item.Label = "";
            item.Label2 = Translation.NextPage;
            item.IsFolder = true;
            Utils.SetDefaultIcons(item);
            item.MusicTag = qu;
            listControl.Add(item);
              }
              GUIPropertyManager.SetProperty("#itemcount", (level ? listControl.Count - 1 : listControl.Count).ToString());
              GUIPropertyManager.SetProperty("#itemtype", Translation.Videos);
              _lastItemType = ItemType.Video;
              SetLayout(ItemType.Video);
              listControl.SelectedListItemIndex = 0;
              UpdateGui();
              ShowPanel();
              OnDownloadTimedEvent(null, null);
        }
Ejemplo n.º 4
0
 private void _exec_query()
 {
     _feed = null;
     try { _feed = _service.Query(_query); }
     catch (GDataRequestException e) { RequestException(e); }
     catch (AuthenticationException e) { AuthenticationException(e); }
     catch (Exception e) { GeneralException(e); }
 }
Ejemplo n.º 5
0
 private static void GetPlaylistEntriesAsCategories(Category parentCategory, YouTubeFeed feed)
 {
     foreach (PlaylistsEntry entry in feed.Entries)
     {
         RssLink playlistLink = new RssLink();
         playlistLink.Name = entry.Title.Text;
         playlistLink.EstimatedVideoCount = (uint)entry.CountHint;
         XmlExtension playlistExt = entry.FindExtension(YouTubeNameTable.PlaylistId, YouTubeNameTable.NSYouTube) as XmlExtension;
         if (playlistExt != null)
         {
             playlistLink.Url = string.Format(PLAYLIST_FEED, playlistExt.Node.InnerText);
             parentCategory.SubCategories.Add(playlistLink);
             playlistLink.ParentCategory = parentCategory;
         }
     }
     // if there are more results add a new NextPageCategory
     if (feed.NextChunk != null)
     {
         parentCategory.SubCategories.Add(new NextPageCategory() { ParentCategory = parentCategory, Url = feed.NextChunk });
     }
 }
Ejemplo n.º 6
0
 public void YouTubeFeedConstructorTest()
 {
     Uri uriBase = null; // TODO: Initialize to an appropriate value
     IService iService = null; // TODO: Initialize to an appropriate value
     YouTubeFeed target = new YouTubeFeed(uriBase, iService);
     Assert.IsNotNull(target);
 }
        bool AddRandomSongToPlaylist(ref Song song, ref YouTubeFeed vidr)
        {
            //check duplication
            PlayList playlist = playlistPlayer.GetPlaylist(_playlistType);
            for (int i = 0; i < playlist.Count; i++)
            {
                PlayListItem item = playlist[i];
                if (item.FileName == song.FileName)
                    return false;
            }

            //add to playlist
            PlayListItem playlistItem = new PlayListItem();
            playlistItem.Type = PlayListItem.PlayListItemType.Video; //Playlists.PlayListItem.PlayListItemType.Audio;
            StringBuilder sb = new StringBuilder();

            playlistItem.FileName = song.FileName;
            //sb.Append(song.Track);
            //sb.Append(". ");
            sb.Append(song.Artist);
            if (!string.IsNullOrEmpty(song.Title))
            {
                sb.Append(" - ");
                sb.Append(song.Title);
            }
            playlistItem.Description = sb.ToString();
            playlistItem.Duration = song.Duration;

            MusicTag tag = new MusicTag();
            tag = song.ToMusicTag();
            foreach (YouTubeEntry entry in vidr.Entries)
            {
                if (Youtube2MP.PlaybackUrl(entry) == playlistItem.FileName)
                {
                    playlistItem.MusicTag = entry;
                    if (!Youtube2MP._settings.UseYouTubePlayer)
                    {
                        playlistItem.FileName = Youtube2MP.StreamPlaybackUrl(entry, new VideoInfo());
                    }
                }
            }

            playlistPlayer.GetPlaylist(_playlistType).Add(playlistItem);
            return true;
        }
        void addVideos(YouTubeFeed videos, YouTubeQuery qu)
        {
            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);
              item.Rating = (float)entry.Rating.Average;
            }
            catch
            {

            }

            string imageFile = GetLocalImageFileName(GetBestUrl(entry.Media.Thumbnails));
            if (File.Exists(imageFile))
            {
              item.ThumbnailImage = imageFile;
              item.IconImage = "defaultVideoBig.png";
              item.IconImageBig = imageFile;
            }
            else
            {
              MediaPortal.Util.Utils.SetDefaultIcons(item);
              item.OnRetrieveArt += new GUIListItem.RetrieveCoverArtHandler(item_OnRetrieveArt);
              DownloadImage(GetBestUrl(entry.Media.Thumbnails), item);
              //DownloadImage(GetBestUrl(entry.Media.Thumbnails), item);
            }
            item.MusicTag = entry;
            listControl.Add(item);
            relatated.Add(item);
              }
              updateStationLogoTimer.Enabled = true; ;
        }
        public static bool GetSongsByArtist(string artist,ref List<Song> songs,ref YouTubeFeed vidr)
        {
            Log.Debug("Youtube GetSongsByArtist for : {0}", artist);
              YouTubeQuery query = new YouTubeQuery(YouTubeQuery.DefaultVideoUri);
              //query.VQ = artist;
              query.Query = artist;
              //order results by the number of views (most viewed first)
              query.OrderBy = "relevance";
              //exclude restricted content from the search
              query.NumberToRetrieve = 20;
              //query.Racy = "exclude";
              query.SafeSearch = YouTubeQuery.SafeSearchValues.Strict;
              query.Categories.Add(new QueryCategory("Music", QueryCategoryOperator.AND));

              vidr = service.Query(query);
              foreach (YouTubeEntry entry in vidr.Entries)
              {
            if (entry.Title.Text.ToUpper().Contains(artist.ToUpper().Trim())&&entry.Title.Text.Contains("-"))
              songs.Add(YoutubeEntry2Song(entry));
              }
              return true;
        }
Ejemplo n.º 10
0
 private static void parseFeed(YouTubeFeed feed, List<Item> videos)
 {
     string description = "";
     string url = null;
     foreach(YouTubeEntry entry in feed.Entries)
     {
         description = "";
         url = String.Format(youtubeWatchUrlTemplate, entry.VideoId);
         if (entry.Media.Description != null)
         {
             description = entry.Media.Description.Value;
         }
         YoutubeVideoItem video = new YoutubeVideoItem(entry.Title.Text, url, description);
         videos.Add(video);
     }
 }
 YouTubeEntry GetVideFromFeed(string videoId,YouTubeFeed videos)
 {
     if (videos == null)
     return null;
       foreach (YouTubeEntry youTubeEntry in videos.Entries)
       {
     if (Youtube2MP.GetVideoId(youTubeEntry) == videoId)
       return youTubeEntry;
       }
       return null;
 }
 void addVideos(YouTubeFeed videos, bool level,YouTubeQuery qu)
 {
     int count = 0;
       if (level)
       {
     GUIListItem item = new GUIListItem();
     item.Label = "..";
     item.IsFolder = true;
     MediaPortal.Util.Utils.SetDefaultIcons(item);
     listControl.Add(item);
       }
       GUIPropertyManager.SetProperty("#header.title", videos.Title.Text);
       updateStationLogoTimer.Enabled = false;
       downloaQueue.Clear();
       foreach (YouTubeEntry entry in videos.Entries)
       {
     if (filterVideoContens(entry))
     {
       GUIListItem item = new GUIListItem();
       // and add station name & bitrate
       item.Label = entry.Title.Text;
       item.Label2 = "";
       item.IsFolder = false;
       count++;
       try
       {
     item.Duration = Convert.ToInt32(entry.Duration.Seconds, 10);
       item.Rating = (float) entry.Rating.Average*2;
       }
       catch (Exception ex)
       {
     Log.Error(ex);
       }
       if (entry.Media != null)
       {
     string imageFile = GetLocalImageFileName(GetBestUrl(entry.Media.Thumbnails));
     if (File.Exists(imageFile))
     {
       item.ThumbnailImage = imageFile;
       //item.IconImage = "defaultVideoBig.png";
       item.IconImage = imageFile;
       item.IconImageBig = imageFile;
     }
     else
     {
       Utils.SetDefaultIcons(item);
       DownloadImage(GetBestUrl(entry.Media.Thumbnails), item);
     }
       }
       item.MusicTag = entry;
       item.OnItemSelected+=item_OnItemSelected;
       listControl.Add(item);
     }
       }
       if (qu.NumberToRetrieve > 0 && videos.TotalResults > qu.NumberToRetrieve)
       {
     GUIListItem item = new GUIListItem();
     item.Label = string.Format("Next Page {0} - {1} ", qu.StartIndex + count, qu.StartIndex + qu.NumberToRetrieve + count);
     qu.StartIndex += qu.NumberToRetrieve;
     item.Label = "";
     item.Label2 = "Next page";
     item.IsFolder = true;
     MediaPortal.Util.Utils.SetDefaultIcons(item);
     item.MusicTag = qu;
     listControl.Add(item);
       }
       UpdateGui();
       updateStationLogoTimer.Enabled = true;
 }
 public static GenericListItem GetPager(SiteItemEntry entry, YouTubeFeed videos)
 {
     if (videos.TotalResults > videos.StartIndex + ITEM_IN_LIST)
       {
     SiteItemEntry newEntry = entry.Copy();
     newEntry.StartItem += ITEM_IN_LIST;
     GenericListItem listItem = new GenericListItem()
                              {
                                Title = Translation.NextPage,
                                IsFolder = true,
                                DefaultImage = "NextPage.png",
                                Tag = newEntry
                              };
     return listItem;
       }
       return null;
 }