コード例 #1
0
        private string GetCopyrightHolder(TrackLyricResponse trackLyrics)
        {
            var lyrics = trackLyrics.Message.Body?.MacroCalls?.TrackLyric?.Message?.Body?.Lyrics;

            return(lyrics?.LyricsCopyright ?? string.Empty);
        }
コード例 #2
0
        private List <RenderElement> GetLyricLines(TrackLyricResponse trackLyrics)
        {
            List <TextElement> lines = null;

            if (!string.IsNullOrEmpty(trackLyrics.Message.Body.MacroCalls.TrackRichsync?.Message?.Body?.Richsync?.RichsyncBody))
            {
                var richSync   = trackLyrics.Message.Body.MacroCalls.TrackRichsync.Message.Body.Richsync;
                var richLyrics = JsonConvert.DeserializeObject <List <TrackRichSyncLyric> >(richSync.RichsyncBody);

                lines = richLyrics.Select(x => new TextElement
                {
                    Text    = x.Lyric,
                    StartAt = (uint)(x.StartAt * 1000),
                }).ToList();
            }

            else if ((trackLyrics.Message.Body?.MacroCalls?.TrackSubtitle?.Message.Body?.SubtitleList.Any() ?? false))
            {
                var subtitle = trackLyrics.Message.Body.MacroCalls.TrackSubtitle.Message.Body.SubtitleList.First();
                if (!string.IsNullOrEmpty(subtitle.Subtitle.SubtitleBody))
                {
                    var lyricSubtitle = JsonConvert.DeserializeObject <List <LyricSubtitle> >(subtitle.Subtitle.SubtitleBody);
                    lines = lyricSubtitle.Select(x => new TextElement
                    {
                        StartAt = (uint)(x.Time.Total * 1000),
                        Text    = x.Text
                    }).ToList();
                }
            }

            else if (trackLyrics.Message.Body?.MacroCalls?.TrackLyric?.Message.Body?.Lyrics != null)
            {
                var lyrics = trackLyrics.Message.Body.MacroCalls.TrackLyric.Message.Body.Lyrics;
                if (string.IsNullOrEmpty(lyrics.LyricsBody))
                {
                    return(lines?.Select(x => x as RenderElement).ToList() ?? new List <RenderElement>());
                }

                lines = lyrics.LyricsBody
                        .Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)
                        .Select(x => new TextElement
                {
                    Text = x.Trim(),
                }).ToList();
            }

            lines = lines ?? new List <TextElement>();
            for (int i = 0; i < lines.Count; i++)
            {
                lines[i].Duration = (i == lines.Count - 1) ?
                                    uint.MaxValue / 2 - lines[i - 1].EndAt :
                                    lines[i + 1].StartAt - lines[i].StartAt;

                lines[i].AutoSize            = false;
                lines[i].FontName            = Fixed.DefaultFontName;
                lines[i].FontSize            = Fixed.DefaultFontSize;
                lines[i].Dock                = ElementDock.Fill;
                lines[i].HorizontalAlignment = TextHorizontalAlignment.Center;
                lines[i].VerticalAlignment   = TextVerticalAlignment.Center;
            }

            return(lines.Select(x => x as RenderElement).ToList());
        }