Пример #1
0
        public static ArtistSongsResult FromMusicResponsiveListItemRenderer(MusicResponsiveListItemRenderer renderer)
        {
            ArtistSongsResult song = new ArtistSongsResult();

            song.Thumbnails = renderer.Thumbnail.MusicThumbnailRenderer.Thumbnail.Thumbnails;

            var trackRuns = renderer.FlexColumns[0].MusicResponsiveListItemFlexColumnRenderer.Text.Runs[0];

            song.Title   = trackRuns.Text;
            song.VideoId = trackRuns.NavigationEndpoint.WatchEndpoint.VideoId;

            var artistRuns = renderer.FlexColumns[1].MusicResponsiveListItemFlexColumnRenderer.Text.Runs;

            foreach (var run in artistRuns)
            {
                if (run.NavigationEndpoint != null && run.Text != ", ")
                {
                    song.Artists.Add(new IdNamePair(run.NavigationEndpoint.BrowseEndpoint.BrowseId, run.Text));
                }
            }

            var albumRuns = renderer.FlexColumns[2].MusicResponsiveListItemFlexColumnRenderer.Text.Runs;

            song.Album = new IdNamePair(albumRuns[0].NavigationEndpoint.BrowseEndpoint.BrowseId, albumRuns[0].Text);

            song.LikeStatus = (LikeStatus)Enum.Parse(typeof(LikeStatus), renderer.Menu.MenuRenderer.TopLevelButtons[0].LikeButtonRenderer.LikeStatus);

            return(song);
        }
Пример #2
0
        public static PlaylistTrack FromMusicResponsiveListItemRenderer(MusicResponsiveListItemRenderer renderer)
        {
            PlaylistTrack track = new PlaylistTrack();

            // if this is not your playlist, it won't have setvideoids for tracks because you can't edit it
            if (renderer.PlaylistItemData != null)
            {
                track.SetVideoId = renderer.PlaylistItemData.PlaylistSetVideoId;
            }

            track.Thumbnails = renderer.Thumbnail.MusicThumbnailRenderer.Thumbnail.Thumbnails;
            track.Duration   = renderer.FixedColumns[0].MusicResponsiveListItemFixedColumnRenderer.Text.Runs[0].Text;

            track.Title   = renderer.FlexColumns[0].MusicResponsiveListItemFlexColumnRenderer.Text.Runs[0].Text;
            track.VideoId = renderer.FlexColumns[0].MusicResponsiveListItemFlexColumnRenderer.Text.Runs[0].NavigationEndpoint.WatchEndpoint.VideoId;

            var artistRuns = renderer.FlexColumns[1].MusicResponsiveListItemFlexColumnRenderer.Text.Runs;

            foreach (var run in artistRuns)
            {
                if (run.NavigationEndpoint != null && run.Text != ", ")
                {
                    track.Artists.Add(new IdNamePair(run.NavigationEndpoint.BrowseEndpoint.BrowseId, run.Text));
                }
            }

            // sometimes album is not included
            var albumRuns = renderer.FlexColumns[2].MusicResponsiveListItemFlexColumnRenderer.Text.Runs;

            if (albumRuns != null && albumRuns[0].Text != null && albumRuns[0].NavigationEndpoint != null)
            {
                track.Album = new IdNamePair(albumRuns[0].NavigationEndpoint.BrowseEndpoint.BrowseId, albumRuns[0].Text);
            }

            track.LikeStatus = (LikeStatus)Enum.Parse(typeof(LikeStatus), renderer.Menu.MenuRenderer.TopLevelButtons[0].LikeButtonRenderer.LikeStatus, true);

            return(track);
        }