private async void OnCurrentTrack(Song value)
        {
            ellStoryboard.Stop();
            ellStoryboard.Begin();
            if (!IsOpen || !ViewModelLocator.Instance.Main.PlayerSession.IsPlaying)
            {
                ellStoryboard.Pause();
            }
            string ImgPath = value?.PictureUrl;
            var    action  = BlurCanvas.RunOnGameLoopThreadAsync(async() =>
            {
                await ReflashBackground(BlurCanvas, ImgPath);
                BlurCanvas.Invalidate();
            });
            //  if (!string.IsNullOrEmpty(value?.Lyric))
            //   {
            //TODO analyse Lyric url is a local url or a web file,to get
            // var file = await StorageFile.GetFileFromPathAsync(value.Lyric));

            var file = await KnownFolders.MusicLibrary.GetFileAsync("12.lrc");    // StorageFile.GetFileFromApplicationUriAsync(new Uri( value.Lyric));

            var filetext = await FileIO.ReadTextAsync(file);

            _lyricModel           = LrcFile.FromText(filetext);
            lb_Lyrics.ItemsSource = _lyricModel.Lyrics;
            //  }
        }
예제 #2
0
        public void TestBracketLyrics(string lrcText, string expectedLyric, string maker)
        {
            var lrcFile = LrcFile.FromText(lrcText, true);

            Assert.AreEqual(expectedLyric, lrcFile[0].Content);
            Assert.AreEqual(maker, lrcFile.Metadata.Maker);
        }
예제 #3
0
        public void TestAfterOrAt(string lrcText, double seconds, string expectedLyric)
        {
            var lrcFile = LrcFile.FromText(lrcText);
            var result  = lrcFile.AfterOrAt(TimeSpan.FromSeconds(seconds));

            Assert.AreEqual(expectedLyric, result == null ? null : result.Content);
        }
예제 #4
0
 public void TestArgumentNullException()
 {
     // ReSharper disable once ObjectCreationAsStatement
     Assert.Catch <ArgumentNullException>(() => new LrcFile(null, Enumerable.Empty <IOneLineLyric>(), true));
     // ReSharper disable once ObjectCreationAsStatement
     Assert.Catch <ArgumentNullException>(() => new LrcFile(new Mock <ILrcMetadata>().Object, null, true));
     Assert.Catch <ArgumentNullException>(() => LrcFile.FromText(null));
 }
예제 #5
0
        public void TestEmptyContent(string lrcText, int count)
        {
            var lrcFile = LrcFile.FromText(lrcText);

            Assert.IsNotNull(lrcFile.Lyrics);
            Assert.AreEqual(count, lrcFile.Lyrics.Count);
            Assert.AreEqual(lrcFile.Lyrics.Count, lrcFile.Lyrics.Select(l => l.Timestamp).Distinct().Count());
            Assert.IsTrue(lrcFile.Lyrics.All(l => l.Content == string.Empty));
        }
예제 #6
0
        public void TestMetadata(string lrcText, string expectedTitle, string expectedArtist, string expectedAlbum, double?expectedMilliseconds, string expectedMaker)
        {
            var lrcFile = LrcFile.FromText(lrcText);

            Assert.IsNotNull(lrcFile.Metadata);
            Assert.AreEqual(expectedTitle, lrcFile.Metadata.Title);
            Assert.AreEqual(expectedArtist, lrcFile.Metadata.Artist);
            Assert.AreEqual(expectedAlbum, lrcFile.Metadata.Album);
            Assert.AreEqual(expectedMilliseconds, lrcFile.Metadata.Offset == null ? (double?)null : lrcFile.Metadata.Offset.Value.TotalMilliseconds);
        }
예제 #7
0
파일: Main.cs 프로젝트: miidas/ITMHelper
        private void Main_TrackChanged(object currentTrackObj)
        {
            if (currentTrackObj != null)
            {
                // Clear current displayed text
                //displayForm.currentText = "";
                //displayForm.RefreshText();
                lyricsWindow.UpdateText("");

                var currentTrack = (dynamic)currentTrackObj;

                try
                {
                    this.TitleTextBox.Text  = currentTrack.Name;
                    this.AlbumTextBox.Text  = currentTrack.Album;
                    this.ArtistTextBox.Text = currentTrack.Artist;
                }
                catch (COMException ex)
                {
                    return;
                }

                var lyricsDir = System.Environment.CurrentDirectory + "\\Lyrics";
                if (Directory.Exists(lyricsDir))
                {
                    try
                    {
                        // Use escaped filename instead of TrackDatabaseID for readability
                        this.lrcPath = $"{lyricsDir}\\"
                                       + String.Join(
                            "_",
                            $"{currentTrack.Name} - {currentTrack.Artist}.lrc"
                            .Split(System.IO.Path.GetInvalidFileNameChars(), StringSplitOptions.RemoveEmptyEntries)
                            )
                                       .TrimEnd('.');
                        var lrcText = System.IO.File.ReadAllText(this.lrcPath);

                        var lrcFile = LrcFile.FromText(lrcText);
                        //displayForm.lrcFile = lrcFile;
                        lyricsWindow.SetLrcFile(lrcFile);
                    }
                    catch (Exception ex) // TODO
                    {
                        //displayForm.lrcFile = null;
                        lyricsWindow.SetLrcFile(null);
                    }
                }
            }
            else
            {
                this.TitleTextBox.Text  = "";
                this.AlbumTextBox.Text  = "";
                this.ArtistTextBox.Text = "";
            }
        }
예제 #8
0
 private void TryAnalyzeLyrics(string lyrics)
 {
     if (!string.IsNullOrEmpty(lyrics))
     {
         try
         {
             LyricModel = LrcFile.FromText(lyrics);
         }
         catch { }
     }
 }
예제 #9
0
        public void TestMultipleTimestamps(string lrcText, int count)
        {
            var lrcFile = LrcFile.FromText(lrcText);

            Assert.IsNotNull(lrcFile.Lyrics);
            Assert.AreEqual(count, lrcFile.Lyrics.Count);
            Assert.AreEqual(lrcFile.Lyrics.Count, lrcFile.Lyrics.Select(l => l.Timestamp).Distinct().Count());
            var contents = lrcFile.Lyrics.Select(l => l.Content).Distinct().ToList();

            Assert.AreEqual(1, contents.Count);
            Assert.AreEqual("lyrics text", contents[0]);
        }
예제 #10
0
        private async void OnCurrentTrackChanged(Song value)
        {
            if (string.IsNullOrEmpty(value?.Lyric))
            {
                //TODO analyse Lyric url is a local url or a web file,to get

                var file = await StorageFile.GetFileFromPathAsync(value.Lyric);

                var filetext = await FileIO.ReadTextAsync(file);

                LyricModel = LrcFile.FromText(filetext);
            }
        }
예제 #11
0
        public void TestTimestampFormats(string lrcText, int count)
        {
            var lrcFile = LrcFile.FromText(lrcText);

            Assert.IsNotNull(lrcFile.Lyrics);
            Assert.AreEqual(count, lrcFile.Lyrics.Count);
            var timestamps = lrcFile.Lyrics.Select(l => l.Timestamp);

            foreach (var timestamp in timestamps)
            {
                Assert.AreNotEqual(TimeSpan.Zero, timestamp);
            }
        }
예제 #12
0
        public static void Main(string[] args)
        {
            var file = LrcFile.FromText(File.ReadAllText(args[0]));

            var root             = JsonConvert.DeserializeObject <JObject>(File.ReadAllText("base.json"));
            var transitionLength = (float)root["transition_length"];

            root.Remove("transition_length");
            var offset = (float)root["offset"];

            root.Remove("offset");
            var texts = new JArray();

            foreach (var oneLineLyric in file.Lyrics)
            {
                var start = oneLineLyric.Timestamp.TotalSeconds - transitionLength + offset;
                var text  = new JObject();
                text["template"] = "lyrics";
                text["text"]     = oneLineLyric.Content;
                text["time"]     = start;
                var states  = new JArray();
                var inState = new JObject();
                inState["template"] = "in";
                var outState = new JObject();
                outState["template"] = "out";
                var preOutState = new JObject();
                var nextLyric   = file.After(oneLineLyric.Timestamp);
                if (nextLyric != null)
                {
                    preOutState["add_time"] = nextLyric.Timestamp.TotalSeconds - oneLineLyric.Timestamp.TotalSeconds - transitionLength * 2;
                }
                else
                {
                    preOutState["add_time"] = 5;
                }
                states.Add(inState);
                states.Add(preOutState);
                states.Add(outState);
                text["states"] = states;
                texts.Add(text);
            }

            root["texts"] = texts;
            File.WriteAllText("storyboard.json", JsonConvert.SerializeObject(root));
        }
예제 #13
0
        public ActionResult Detail(int id, String mainbody, int Score)
        {
            var com = new Comment()
            {
                DocumentId = id, MainBody = mainbody, Score = Score
            };

            db.Comment.Add(com);
            db.SaveChanges();

            Document doc     = db.Document.FirstOrDefault(m => m.Id == id);
            ILrcFile lrcFile = LrcFile.FromText(doc.Lyrics);

            ViewBag.Lrcs   = lrcFile;
            ViewData.Model = doc;

            // return View();
            // return Content("true");
            //  return Json(json);
            return(Json(new { status = 200, message = "提交成功", score = com.Score, mainbody = com.MainBody }));
        }
예제 #14
0
        public void TestFromText(string lrcText, int count)
        {
            var lrcFile = LrcFile.FromText(lrcText);

            Assert.IsNotNull(lrcFile);
            Assert.IsNotNull(lrcFile.Metadata);
            Assert.IsNotNull(lrcFile.Lyrics);
            Assert.AreEqual(count, lrcFile.Lyrics.Count);
            foreach (var oneLineLyric in lrcFile.Lyrics)
            {
                Assert.AreNotEqual(TimeSpan.Zero, oneLineLyric.Timestamp);
                Assert.IsNotNullOrEmpty(oneLineLyric.Content);
            }
            for (var i = 0; i < lrcFile.Lyrics.Count; i++)
            {
                if (i > 0)
                {
                    Assert.Less(lrcFile.Lyrics[i - 1].Timestamp, lrcFile.Lyrics[i].Timestamp);
                }
                Assert.AreNotEqual(TimeSpan.Zero, lrcFile.Lyrics[i].Timestamp);
                Assert.IsNotNullOrEmpty(lrcFile.Lyrics[i].Content);
            }
        }
예제 #15
0
 public void TestInvalidLyrics(string lrcText)
 {
     Assert.Catch <FormatException>(() => LrcFile.FromText(lrcText));
 }
예제 #16
0
 public void TestDuplicateTimestamp(string lrcText)
 {
     Assert.Catch <FormatException>(() => LrcFile.FromText(lrcText));
 }
예제 #17
0
 public void TestCharacterEscape(string lrcText, double expectedSeconds, string expectedContent)
 {
     Assert.Catch <FormatException>(() => LrcFile.FromText(lrcText));
 }
예제 #18
0
        public void TestTimestampIndex(string lrcText, double seconds, string expectedLyric)
        {
            var lrcFile = LrcFile.FromText(lrcText);

            Assert.AreEqual(expectedLyric, lrcFile[TimeSpan.FromSeconds(seconds)]);
        }
예제 #19
0
        public void TestIntegerIndex(string lrcText, int index, string expectedLyric)
        {
            var lrcFile = LrcFile.FromText(lrcText);

            Assert.AreEqual(expectedLyric, lrcFile[index].Content);
        }