コード例 #1
0
 public void Add(GenericListItemCollections collections)
 {
     foreach (GenericListItem item in collections.Items)
     {
         Items.Add(item);
     }
 }
 public void Add(GenericListItemCollections collections)
 {
     foreach (GenericListItem item in collections.Items)
       {
     Items.Add(item);
       }
 }
コード例 #3
0
 public FormItemList(GenericListItemCollections listItems)
 {
     InitializeComponent();
       foreach (GenericListItem item in listItems.Items)
       {
     ListViewItem listViewItem = new ListViewItem(item.Title);
     listViewItem.Tag = item;
     listView1.Items.Add(listViewItem);
       }
 }
コード例 #4
0
        void addVideos(GenericListItemCollections itemCollections, bool level)
        {
            List<GUIListItem> guiListItems = new List<GUIListItem>();
              int selectedidx = listControl.SelectedListItemIndex;
              if (itemCollections.Items.Count < 1)
              {
            Err_message(Translation.NoItemToDisplay);
            return;
              }

              if (!itemCollections.Paged)
              {
            SaveListState(true);
            downloaQueue.Clear();
              }
              else
              {
            for (int i = 0; i < listControl.Count-1; i++)
            {
              guiListItems.Add(listControl[i]);
            }
            GUIControl.ClearControl(GetID, listControl.GetID);
              }

              //GUIPropertyManager.SetProperty("#currentmodule", "Youtube.Fm/" + itemCollections.Title);
              GUIPropertyManager.SetProperty("#currentmodule", itemCollections.Title);
              updateStationLogoTimer.Enabled = false;
              if (level && !itemCollections.Paged)
              {
            GUIListItem item = new GUIListItem();
            item.Label = "..";
            item.IsFolder = true;
            Utils.SetDefaultIcons(item);
            item.OnItemSelected += item_OnItemSelected;
            listControl.Add(item);
              }

              foreach (GUIListItem guiListItem in guiListItems)
              {
            listControl.Add(guiListItem);
              }

              foreach (GenericListItem listItem in itemCollections.Items)
              {
            GUIListItem item = new GUIListItem();
            item.Label = listItem.Title;
            item.Label2 = listItem.Title2;
            item.Label3 = listItem.Title3;
            item.IsFolder = listItem.IsFolder;
            item.Duration = listItem.Duration;
            item.Rating = listItem.Rating;

            if (string.IsNullOrEmpty(listItem.DefaultImage))
            {
              string file = GUIGraphicsContext.Skin + "\\Media\\Youtube.Fm\\" + listItem.Title.Replace(":", "_") + ".png";
              if (File.Exists(file))
            listItem.DefaultImage = file;
            }

            if (string.IsNullOrEmpty(listItem.DefaultImage))
            {
              Utils.SetDefaultIcons(item);
            }
            else
            {
              item.ThumbnailImage = listItem.DefaultImage;
              item.IconImage = listItem.DefaultImage;
              item.IconImageBig = listItem.DefaultImage;
            }

            if (!string.IsNullOrEmpty(listItem.LogoUrl))
            {
              string imageFile = Youtube2MP.GetLocalImageFileName(listItem.LogoUrl);
              if (File.Exists(imageFile))
              {
            item.ThumbnailImage = imageFile;
            item.IconImage = imageFile;
            item.IconImageBig = imageFile;
              }
              else
              {
            DownloadImage(listItem.LogoUrl, item);
              }
            }
            item.MusicTag = listItem.Tag;
            item.OnItemSelected += item_OnItemSelected;
            //YouTubeEntry tubeEntry = listItem.Tag as YouTubeEntry;
            //if (Youtube2MP.NowPlayingEntry != null && tubeEntry != null && Youtube2MP.GetVideoId(Youtube2MP.NowPlayingEntry) == Youtube2MP.GetVideoId(tubeEntry))
            //{
            //  item.Selected = true;
            //}

            listControl.Add(item);
              }

              listControl.SelectedListItemIndex = !itemCollections.Paged ? 0 : selectedidx;

              GUIPropertyManager.SetProperty("#itemcount", (level ? listControl.Count - 1 : listControl.Count).ToString());
              GUIPropertyManager.SetProperty("#itemtype", itemCollections.ItemTypeName);
              SetLayout(itemCollections.ItemType);
              _lastItemType = itemCollections.ItemType;
              UpdateGui();
              ShowPanel();
              OnDownloadTimedEvent(null, null);
        }
コード例 #5
0
        /// <summary>
        /// Called when [show context menu].
        /// </summary>
        protected override void OnShowContextMenu()
        {
            GUIListItem selectedItem = listControl.SelectedListItem;
              string artistName = string.Empty;

              YouTubeEntry videoEntry;
              LocalFileStruct file = selectedItem.MusicTag as LocalFileStruct;
              SiteItemEntry entry = selectedItem.MusicTag as SiteItemEntry;
              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)
            {
              if (entry != null)
              {
            GenericListItemCollections genericListItem = Youtube2MP.GetList(entry);
            if (entry.Provider == "VideoItem" && genericListItem.Items.Count > 0)
            {
              videoEntry = genericListItem.Items[0].Tag as YouTubeEntry;
            }
              }
            }
            if (videoEntry == null)
              return;
            Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + Youtube2MP.GetVideoId(videoEntry));
            Video video = Youtube2MP.request.Retrieve<Video>(videoEntryUrl);
            videoEntry = video.YouTubeEntry;
              }

              if (videoEntry == null)
            return;

              artistName = ArtistManager.Instance.GetArtistName(videoEntry.Title.Text);

              ArtistItem artistItem = GetArtist(videoEntry);

              GUIDialogMenu dlg = (GUIDialogMenu) GUIWindowManager.GetWindow((int) Window.WINDOW_DIALOG_MENU);
              if (dlg == null)
            return;
              dlg.Reset();
              dlg.SetHeading(Translation.ContextMenu); // menu
              if (Youtube2MP.player.CurrentSong > -1 || Youtube2MP.temp_player.CurrentSong > -1)
            dlg.Add(Translation.PlayNext);
              dlg.Add(Translation.Info);
              dlg.Add(Translation.RelatedVideos);
              dlg.Add(Translation.VideoResponses);
              dlg.Add(string.Format(Translation.AllVideosFromUser, videoEntry.Authors[0].Name));
              dlg.Add(Translation.AddPlaylist);
              dlg.Add(Translation.AddAllPlaylist);
              if (Youtube2MP.service.Credentials != null)
              {
            dlg.Add(Translation.AddFavorites);
            dlg.Add(Translation.AddWatchLater);
              }
              dlg.Add(Translation.Options);
              dlg.Add(Translation.DownloadVideo);
              if (!string.IsNullOrEmpty(artistName) &&
              !string.IsNullOrEmpty(ArtistManager.Instance.GetArtistsByName(artistName).Name))
            dlg.Add(string.Format(Translation.AllMusicVideosFrom, artistName));
              if (!string.IsNullOrEmpty(artistItem.Id))
            dlg.Add(Translation.SimilarArtists);

              dlg.DoModal(GetID);
              if (dlg.SelectedId == -1)
            return;
              if (dlg.SelectedLabelText == Translation.RelatedVideos)
              {
            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(Translation.NoItemWasFound);
              }
            }
              }
              else if (dlg.SelectedLabelText == Translation.VideoResponses)
              {
            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(Translation.NoVideoResponse);
              }
            }

              }
              else if (dlg.SelectedLabelText == string.Format(Translation.AllVideosFromUser, videoEntry.Authors[0].Name))
              {
            SiteItemEntry newentry = new SiteItemEntry {Provider = new UserVideos().Name};
            newentry.SetValue("id", videoEntry.Authors[0].Name);
            addVideos(Youtube2MP.GetList(newentry), true);
              }
              else if (dlg.SelectedLabelText == Translation.AddPlaylist)
              {
            VideoInfo inf = SelectQuality(videoEntry);
            if (inf.Quality != VideoQuality.Unknow)
            {
              AddItemToPlayList(selectedItem, inf);
            }
              }
              else if (dlg.SelectedLabelText == Translation.AddAllPlaylist)
              {

            VideoInfo inf = SelectQuality(videoEntry);
            inf.Items = new Dictionary<string, string>();
            if (inf.Quality != VideoQuality.Unknow)
            {
              GUIDialogProgress dlgProgress =
            (GUIDialogProgress) GUIWindowManager.GetWindow((int) Window.WINDOW_DIALOG_PROGRESS);
              if (dlgProgress != null)
              {
            dlgProgress.Reset();
            dlgProgress.SetHeading(Translation.AddAllPlaylist);
            dlgProgress.SetLine(1, "");
            dlgProgress.SetLine(2, "");
            dlgProgress.SetPercentage(0);
            dlgProgress.Progress();
            dlgProgress.ShowProgressBar(true);
            dlgProgress.StartModal(GetID);
              }
              int i = 0;
              for (int j = 0; j < listControl.Count; j++)
              {
            GUIListItem item = listControl[j];
            if (dlgProgress != null)
            {
              double pr = ((double) i/(double) listControl.Count)*100;
              dlgProgress.SetLine(1, item.Label);
              dlgProgress.SetLine(2, i.ToString() + "/" + listControl.Count.ToString());
              dlgProgress.SetPercentage((int) pr);
              dlgProgress.Progress();
              if (dlgProgress.IsCanceled)
                break;
            }
            i++;
            AddItemToPlayList(item, new VideoInfo(inf));
              }
              if (dlgProgress != null)
            dlgProgress.Close();
            }
              }
              else if (dlg.SelectedLabelText == Translation.AddFavorites)
              {
            try
            {
              service.Insert(new Uri(YouTubeQuery.CreateFavoritesUri(null)), videoEntry);
            }
            catch (Exception)
            {
              Err_message(Translation.WrongRequestWrongUser);
            }
              }
              else if (dlg.SelectedLabelText == Translation.AddWatchLater)
              {
            PlayListMember pm = new PlayListMember();
            pm.Id = videoEntry.VideoId;
            Youtube2MP.request.Insert(new Uri("https://gdata.youtube.com/feeds/api/users/default/watch_later"), pm);
              }
              else if (dlg.SelectedLabelText == Translation.Options)
              {
            DoOptions();
              }
              else if (dlg.SelectedLabelText == Translation.DownloadVideo)
              {
            LocalFileStruct fil = Youtube2MP._settings.LocalFile.Get(Youtube2MP.GetVideoId(videoEntry));
            if (fil != null && File.Exists(fil.LocalFile))
            {
              Err_message(Translation.ItemAlreadyDownloaded);
            }
            else
            {
              if (VideoDownloader.IsBusy)
              {
            Err_message(Translation.AnotherDonwnloadProgress);
            dlgProgress = (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS);
            if (dlgProgress != null)
            {
              dlgProgress.Reset();
              dlgProgress.SetHeading(Translation.DownloadProgress);
              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.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);
            VideoDownloader.Entry = videoEntry;
              }
            }
              }
              else if (dlg.SelectedLabelText == string.Format(Translation.AllMusicVideosFrom, artistName))
              {
            addVideos(ArtistManager.Instance.Grabber.GetArtistVideosIds(ArtistManager.Instance.GetArtistName(videoEntry)),
                  true);
              }
              else if (dlg.SelectedLabelText == Translation.Info)
              {
            YoutubeGuiInfoEx scr = (YoutubeGuiInfoEx) GUIWindowManager.GetWindow(29053);
            scr.YouTubeEntry = videoEntry;
            //if (entry!=null)
            //{
            //  ArtistItem artistItem=ent
            //}
            GUIWindowManager.ActivateWindow(29053);
              }
              else if (dlg.SelectedLabelText == Translation.PlayNext)
              {
            PlayNext(videoEntry);
              }
              else if (dlg.SelectedLabelText == Translation.SimilarArtists)
              {
            List<ArtistItem> similarartist = new List<ArtistItem>();
            similarartist =
              ArtistManager.Instance.Grabber.GetSimilarArtists(ArtistManager.Instance.GetArtistName(videoEntry));
            GenericListItemCollections res = new GenericListItemCollections();
            foreach (ArtistItem item in similarartist)
            {
              SiteItemEntry newentry = new SiteItemEntry();
              newentry.Provider = "Artists";
              newentry.SetValue("letter", "false");
              newentry.SetValue("id", item.Id);
              newentry.SetValue("name", item.Name);
              res.ItemType = ItemType.Artist;
              try
              {
            GenericListItem listItem = new GenericListItem()
            {
              Title = item.Name,
              LogoUrl =
                string.IsNullOrEmpty(item.Img_url.Trim()) ? "@" : item.Img_url,
              IsFolder = true,
              DefaultImage = "defaultArtistBig.png",
              Tag = newentry
            };
            res.Items.Add(listItem);
              }
              catch (Exception exception)
              {
              }
            }
            res.Title = "Artists/Similar/" + artistItem.Name;
            addVideos(res, true);
              }
        }
コード例 #6
0
        YouTubeEntry GetEntry(string title)
        {
            GenericListItemCollections res = new GenericListItemCollections();
              YouTubeQuery query = new YouTubeQuery(YouTubeQuery.DefaultVideoUri);
              query.Query = title;
              query.NumberToRetrieve = 1;
              query.OrderBy = "relevance";

              if (Youtube2MP._settings.MusicFilter)
              {
            query.Categories.Add(new QueryCategory("Music", QueryCategoryOperator.AND));
              }

              YouTubeFeed videos = Youtube2MP.service.Query(query);
              foreach (YouTubeEntry youTubeEntry in videos.Entries)
              {
            return youTubeEntry;
              }
              return null;
        }
コード例 #7
0
        YouTubeEntry GetArtistEntry(string title,int length)
        {
            GenericListItemCollections res = new GenericListItemCollections();
              YouTubeQuery query = new YouTubeQuery(YouTubeQuery.DefaultVideoUri);
              query.Query = title;
              query.NumberToRetrieve = length;
              query.OrderBy = "relevance";

              if (Youtube2MP._settings.MusicFilter)
              {
            query.Categories.Add(new QueryCategory("Music", QueryCategoryOperator.AND));
              }

              YouTubeFeed videos = Youtube2MP.service.Query(query);
              if (videos.Entries.Count == 0)
            return null;
              Random random = new Random();
              int number = random.Next(0, videos.Entries.Count-1);
              return (YouTubeEntry)videos.Entries[number];
        }
コード例 #8
0
 public static GenericListItemCollections GetHomeMenu()
 {
     GenericListItemCollections res = new GenericListItemCollections();
       res.Title = "Home";
       foreach (SiteItemEntry itemEntry in _settings.MainMenu.Items)
       {
     if (String.IsNullOrEmpty(itemEntry.ParentFolder))
       res.Add(SiteItemProvider[itemEntry.Provider].HomeGetList(itemEntry));
       }
       foreach (GenericListItem genericListItem in res.Items)
       {
     string file = GUIGraphicsContext.Skin + "\\Media\\Youtube.Fm\\" + genericListItem.Title + ".png";
     if (File.Exists(file))
       genericListItem.DefaultImage = file;
       }
       return res;
 }