public LyricParser.LyricEntry UpdateLyrics() { var lyrics = _interface.NowPlaying_GetLyrics(); if (lyrics != _lastLyrics) { _lyrics = LyricParser.ParseLyric(lyrics); _lastLyrics = lyrics; } if (_lyrics == null) { return(new LyricParser.LyricEntry(0.0, _interface.NowPlaying_GetFileTag(Plugin.MetaDataType.TrackTitle) + " - " + _interface.NowPlaying_GetFileTag(Plugin.MetaDataType.Artist), null)); } var time = _interface.Player_GetPosition(); var nTime = time + _lyrics.Offset; var entries = _lyrics.Entries; for (var i = 0; i < entries.Count; i++) { if (entries[i].TimeMs > nTime && i > 0) { return(entries[i - 1]); } } if (entries.Count <= 0) { return(null); } return(entries[entries.Count - 1]); }
private static void Bot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e) { if (e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Text) { if (e.Message.Text.StartsWith("/lyrics") && e.Message.Text.Length > 7) { var songTitle = GetSong(e.Message.Text); var artist = GetArtist(e.Message.Text); var parser = new LyricParser(artist, songTitle); var result = parser.GetLyricsAsync().GetAwaiter().GetResult(); Bot.SendTextMessageAsync(e.Message.Chat.Id, result ?? "No such artist or song π"); } else { switch (e.Message.Text) { case "/start": Bot.SendTextMessageAsync(e.Message.Chat.Id, "Hi, I'm LyricsBot, here you can find your fav song lyrics π"); break; case "/help": Bot.SendTextMessageAsync(e.Message.Chat.Id, "To find song lyrics, use command π»: /lyrics artist songname\n" + "Write artist and song name without spaces and separators π\n" + "Simple example π: /lyrics metallica theunforgiven"); break; default: Bot.SendTextMessageAsync(e.Message.Chat.Id, "Unknown command π"); break; } } } }
public ActionResult GetLyricListByDocumentId(Int32 documentId) { Document document = entities.Document.Find(documentId); //解ζζθ― Lyric lyric = LyricParser.Parse(document.Lyrics); List <Line> lines = new List <Line>(); Regex regex = new Regex(@"\<[\s\S]*\>"); foreach (var item in lyric.Lines) { Line line = new Line(); line.TimeLabel = item.Key; line.Original = item.Value.IndexOf('<') > 0 ? item.Value.Substring(0, item.Value.IndexOf('<')) : item.Value; line.Translate = regex.Match(item.Value).Value.Replace("<", "").Replace(">", ""); lines.Add(line); } //解ζδΈθ±ζ return(Json(new { code = 200, desc = "ζ₯θ―’ζε", info = lines.Select(o => new { Name = o.Original, o.TimeLabel.TotalMilliseconds, o.Translate, o.Original }) })); }
public ActionResult Detail(int id) { Document doc = db.Document.FirstOrDefault(m => m.Id == id); Lyric lyric = LyricParser.Parse(doc.Lyrics); ViewBag.Lrcs = lyric; ViewData.Model = doc; return(View()); }
public ActionResult GetById(Int32 id) { Document document = entities.Document.Find(id); if (document == null) { return(Json(new { code = 201, desc = "ζζ‘£δΈεε¨" })); } //解ζζθ― Lyric lyric = LyricParser.Parse(document.Lyrics); List <Line> lines = new List <Line>(); Regex regex = new Regex(@"\<[\s\S]*\>"); foreach (var item in lyric.Lines) { Line line = new Line(); line.TimeLabel = item.Key; line.Original = item.Value.IndexOf('<') > 0 ? item.Value.Substring(0, item.Value.IndexOf('<')) : item.Value; line.Translate = regex.Match(item.Value).Value.Replace("<", "").Replace(">", ""); lines.Add(line); } return(Json(new { code = 200, desc = "ζ₯θ―’ζε", info = new { document.Id, document.Sort, document.Title, document.TitleTwo, TitleCn = document.Title, TitleEn = document.TitleTwo, document.TitlePy, document.Category, document.SoundPath, document.TitleSubCn, document.TitleSubEn, document.TitleSubPy, Lyrics = lines.Select(o => new { o.Original, o.Translate, o.TimeLabel.TotalMilliseconds }), document.FolderId, Folder = (document.FolderId.HasValue ? new { document.Folder.Id, document.Folder.Name, document.Folder.NameEn, document.Folder.Sort } : null) } })); }
//[HttpPost] public ActionResult DocById(int id) { var temp = db.Document.Find(id); Lyric lyric = LyricParser.Parse(temp.Lyrics); List <Line> lines = new List <Line>(); Regex regex = new Regex(@"\<[\s\S]*\>"); foreach (var item in lyric.Lines) { Line line = new Line(); line.TimeLabel = item.Key; line.Original = item.Value.IndexOf('<') > 0 ? item.Value.Substring(0, item.Value.IndexOf('<')) : item.Value; line.Translate = regex.Match(item.Value).Value.Replace("<", "").Replace(">", ""); lines.Add(line); } var data = new { temp.Id, temp.Title, TitleOne = temp.Title, temp.TitleTwo, TitleCn = temp.Title, TitleEn = temp.TitleTwo, temp.Category, temp.Cover, Lyrics = lines.Select(t => new { TimeLabel = t.TimeLabel.TotalMilliseconds, t.Original, t.Translate }), temp.SoundPath, temp.Length, temp.Duration, temp.LengthString, temp.AddDate, Date = (temp.AuditDate == null ? "" : temp.AddDate.Value.ToString("yyyy-MM-dd")), Size = temp.Length, Time = temp.LengthString, Folder = (temp.FolderId.HasValue ? new { temp.Folder.Id, temp.Folder.Name, temp.Folder.NameEn, temp.Folder.NameSubCn, temp.Folder.NameSubEn } : null) }; return(Json(data, JsonRequestBehavior.AllowGet)); }