Ejemplo n.º 1
0
        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
                })
            }));
        }
Ejemplo n.º 2
0
        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());
        }
Ejemplo n.º 3
0
        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)
                }
            }));
        }
Ejemplo n.º 4
0
        //[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));
        }