コード例 #1
0
ファイル: Artist.cs プロジェクト: mitchhymel/YoutubeMusicApi
        public static ReleaseList FromMusicCarouselShelfRenderer(MusicCarouselShelfRenderer renderer)
        {
            ReleaseList releases = new ReleaseList();

            var browseIdRuns = renderer.Header.MusicCarouselShelfBasicHeaderRenderer.Title.Runs;

            if (browseIdRuns[0].NavigationEndpoint != null)
            {
                releases.BrowseId = browseIdRuns[0].NavigationEndpoint.BrowseEndpoint.BrowseId;
                releases.Params   = browseIdRuns[0].NavigationEndpoint.BrowseEndpoint.Params;
            }

            foreach (var content in renderer.Contents)
            {
                releases.Results.Add(Release.FromMusicTwoRowItemRenderer(content.MusicTwoRowItemRenderer));
            }


            return(releases);
        }
コード例 #2
0
ファイル: Artist.cs プロジェクト: mitchhymel/YoutubeMusicApi
        public static Artist FromBrowseResponse(BrowseResponse response)
        {
            Artist artist = new Artist();

            var header = response.Header.MusicImmersiveHeaderRenderer;

            artist.Name       = header.Title.Runs[0].Text;
            artist.Thumbnails = header.Thumbnail.MusicThumbnailRenderer.Thumbnail.Thumbnails;

            // TODO:
            //artist.Description = ;
            //artist.Views = ;

            var subscribeButton = header.SubscriptionButton.SubscribeButtonRenderer;

            artist.ChannelId   = subscribeButton.ChannelId;
            artist.Subscribers = subscribeButton.SubscriberCountText.Runs[0].Text;
            artist.Subscribed  = subscribeButton.Subscribed;

            var contents = response.Contents.SingleColumnBrowseResultsRenderer.Tabs[0].TabRenderer.Content.SectionListRenderer.Contents;

            // first item will be songs... if the api returns any
            int indexToStart = 1;

            if (contents[0].MusicShelfRenderer != null)
            {
                artist.Songs = Songs.FromMusicShelfRenderer(contents[0].MusicShelfRenderer);
            }
            else
            {
                // if there are no songs, then the rest of our information will be moved up
                // one index
                indexToStart = 0;
            }

            for (int i = indexToStart; i < contents.Count; i++)
            {
                var    content = contents[i];
                string type    = content.MusicCarouselShelfRenderer.Header.MusicCarouselShelfBasicHeaderRenderer.Title.Runs[0].Text;
                switch (type)
                {
                case "Albums":
                    artist.Albums = ReleaseList.FromMusicCarouselShelfRenderer(contents[indexToStart].MusicCarouselShelfRenderer);
                    break;

                case "Singles":
                    artist.Singles = ReleaseList.FromMusicCarouselShelfRenderer(contents[indexToStart + 1].MusicCarouselShelfRenderer);
                    break;

                case "Videos":
                    artist.Videos = Videos.FromMusicCarouselShelfRenderer(contents[indexToStart + 2].MusicCarouselShelfRenderer);
                    break;

                case "Featured on":
                    artist.Playlists = ArtistPlaylists.FromMusicCarouselShelfRenderer(contents[indexToStart + 3].MusicCarouselShelfRenderer);
                    break;

                case "Fans might also like":
                    artist.RelatedArtists = RelatedArtists.FromMusicCarouselShelfRenderer(contents[indexToStart + 4].MusicCarouselShelfRenderer);
                    break;

                default:
                    throw new Exception($"Unsupported content type found {type}");
                }
            }

            return(artist);
        }