Ejemplo n.º 1
0
        private (Lrc, int) ParseLyric(JToken json)
        {
            string lyric   = (string)json["lyric"];
            var    lrc     = string.IsNullOrEmpty(lyric) ? null : Lrc.UnsafeParse(lyric);
            int    version = (int)json["version"];

            return(lrc, version);
        }
Ejemplo n.º 2
0
 public NcmLyric(int id, bool isCollected, bool isAbsoluteMusic, Lrc raw, int rawVersion, Lrc translated, int translatedVersion)
 {
     _id                = id;
     _isCollected       = isCollected;
     _isAbsoluteMusic   = isAbsoluteMusic;
     _raw               = raw;
     _rawVersion        = rawVersion;
     _translated        = translated;
     _translatedVersion = translatedVersion;
 }
Ejemplo n.º 3
0
        public static Lrc InitLrc(string[] array)
        {
            Lrc lrc = new Lrc();
            Dictionary <double, string> dicword = new Dictionary <double, string>();

            for (int i = 0; array[i] != ""; i++)
            {
                if (array[i].StartsWith("[ti:"))
                {
                    lrc.Title = SplitInfo(array[i]);
                }
                else if (array[i].StartsWith("[ar:"))
                {
                    lrc.Artist = SplitInfo(array[i]);
                }
                else if (array[i].StartsWith("[al:"))
                {
                    lrc.Album = SplitInfo(array[i]);
                }
                else if (array[i].StartsWith("[by:"))
                {
                    lrc.LrcBy = SplitInfo(array[i]);
                }
                else if (array[i].StartsWith("[offset:"))
                {
                    lrc.Offset = SplitInfo(array[i]);
                }
                else
                {
                    try
                    {
                        Regex           regexword = new Regex(@".*\](.*)");
                        Match           mcw       = regexword.Match(array[i]);
                        string          word      = mcw.Groups[1].Value;
                        Regex           regextime = new Regex(@"\[([0-9.:]*)\]", RegexOptions.Compiled);
                        MatchCollection mct       = regextime.Matches(array[i]);
                        foreach (Match item in mct)
                        {
                            double time = TimeSpan.Parse("00:" + item.Groups[1].Value).TotalSeconds;
                            dicword.Add(time, word);
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
            lrc.LrcWord = dicword.OrderBy(t => t.Key).ToDictionary(t => t.Key, p => p.Value);
            return(lrc);
        }
Ejemplo n.º 4
0
        private static Lrc MergeLyric(Lrc rawLrc, Lrc translatedLrc)
        {
            if (rawLrc == null)
            {
                throw new ArgumentNullException(nameof(rawLrc));
            }
            if (translatedLrc == null)
            {
                throw new ArgumentNullException(nameof(translatedLrc));
            }

            Lrc mergedLrc;

            mergedLrc = new Lrc {
                Offset = rawLrc.Offset,
                Title  = rawLrc.Title
            };
            foreach (KeyValuePair <TimeSpan, string> rawLyric in rawLrc.Lyrics)
            {
                mergedLrc.Lyrics.Add(rawLyric.Key, rawLyric.Value);
            }
            foreach (KeyValuePair <TimeSpan, string> translatedLyric in translatedLrc.Lyrics)
            {
                string rawLyric;

                if (translatedLyric.Value.Length == 0)
                {
                    // 如果翻译歌词是空字符串,跳过
                    continue;
                }
                if (!mergedLrc.Lyrics.ContainsKey(translatedLyric.Key))
                {
                    // 如果没有对应的未翻译字符串,直接添加
                    mergedLrc.Lyrics.Add(translatedLyric.Key, translatedLyric.Value);
                    continue;
                }
                rawLyric = mergedLrc.Lyrics[translatedLyric.Key];
                if (rawLyric.Length == 0)
                {
                    // 如果未翻译歌词是空字符串,表示上一句歌词的结束,那么跳过
                    continue;
                }
                mergedLrc.Lyrics[translatedLyric.Key] = $"{rawLyric} 「{translatedLyric.Value}」";
            }
            return(mergedLrc);
        }
Ejemplo n.º 5
0
        public static Lrc FormatLyricResult(string json)
        {
            if (string.IsNullOrWhiteSpace(json))
            {
                return(null);
            }
            var result = new Lrc();

            result.Text2 = new List <KeyValuePair <int, int> >();
            var text = Regex.Match(json, "\"lyric\":\"(.+?)\"\\}").Groups[1].Value;

            if (!string.IsNullOrEmpty(text))
            {
                var strs  = text.Split("\\n", StringSplitOptions.RemoveEmptyEntries);
                var htmls = new StringBuilder();
                var reg   = new Regex("\\[(.+?)\\](.*)");
                for (int i = 0; i < strs.Length; i++)
                {
                    var str = strs[i];
                    if (reg.IsMatch(str))
                    {
                        var mc      = reg.Match(str);
                        var timeStr = mc.Groups[1].Value;
                        var lineStr = mc.Groups[2].Value;

                        timeStr = timeStr.Replace(".00", ".000"); //毫秒处理
                        timeStr = "00:" + timeStr;                //添加分钟
                        var ts = new TimeSpan();
                        if (TimeSpan.TryParse(timeStr, out ts))   //时间转换
                        {
                            if (!string.IsNullOrWhiteSpace(lineStr))
                            {
                                lineStr = lineStr.Trim();
                            }
                            htmls.Append("<p>" + lineStr + "</p>");

                            result.Text2.Add(new KeyValuePair <int, int>((i + 1), (int)ts.TotalSeconds));
                        }
                    }
                }

                result.Text = htmls.ToString();
            }
            return(result);
        }
Ejemplo n.º 6
0
        void MainFormLoad(object sender, EventArgs e)
        {
            myShowLrc = ShowLrc;
            lrc       = new Lrc();

            lrcDic = new Dictionary <string, string>();

            TextBox txtBox = new TextBox();

            txtBox.Name     = "lrcTxtBox";
            txtBox.Width    = 200;
            txtBox.Location = new Point(20, 100);

            txtBox.BorderStyle = BorderStyle.None;

            panel1.Controls.Add(txtBox);
            txtBox.Hide();
        }
Ejemplo n.º 7
0
 private void LoadLrc(Lrc lrcdata)
 {
     LrcData = lrcdata;
     lrcdatapanel.Children.Clear();
     LrcTimeLines.Clear();
     foreach (var item in lrcdata.LrcWord)
     {
         var textblock = new TextBlock();
         textblock.Style = (Style)Resources["unlrcview"];
         textblock.Text  = item.Value;
         LrcTimeLines.Add(TimeSpan.FromMilliseconds(item.Key));
         lrcdatapanel.Children.Add(textblock);
     }
     if (Class.MediaControl.GetCurrent().CurrentState == Windows.Media.Playback.MediaPlayerState.Playing)
     {
         LrcUpdateTimer.Start();
     }
 }
Ejemplo n.º 8
0
        public string Getcontent(string JsonText)
        {
            Lrc l = new Lrc();

            try
            {
                JsonValue obj = JsonObject.Parse(JsonText);

                string content = obj["content"].ToString();

                content = content.Replace(@"""", "");

                return(content);
            }
            catch (Exception)
            {
            }
            return(null);
        }
Ejemplo n.º 9
0
        public Lrc getLrc(string LrcJsonText)
        {
            Lrc l = new Lrc();

            try
            {
                JsonValue obj       = JsonObject.Parse(LrcJsonText);
                string    id        = obj["candidates"][0]["id"].ToString();
                string    accesskey = obj["candidates"][0]["accesskey"].ToString();
                id          = id.Replace(@"""", "");
                accesskey   = accesskey.Replace(@"""", "");
                l.Accesskey = accesskey;
                l.Id        = id;
                return(l);
            }
            catch (Exception)
            {
            }
            return(null);
        }
Ejemplo n.º 10
0
        public async void getLyric(string title, string artist)
        {
            HttpClient http = new HttpClient();
            String     url  = "http://geci.me/api/lyric/" + title + "/" + artist;

            try
            {
                lyric.Text = "";
                HttpResponseMessage response = await http.GetAsync(url);

                String responseJson = await response.Content.ReadAsStringAsync();

                JObject jobject = JObject.Parse(responseJson);
                string  lyr     = jobject["result"][0]["lrc"].ToString();
                //lyric.Text = lyr;
                HttpResponseMessage Response = await http.GetAsync(lyr);

                String lrc = await Response.Content.ReadAsStringAsync();

                //lyric.Text = lrc;
                var array = lrc.Split('\n');
                //for (int i = 0; array[i] != ""; i++)
                //lyric.Text += array[i];
                Lrc lrcinit = InitLrc(array);
                //lyric.Text += lrcinit.Title;
                Dictionary <double, string> .ValueCollection valueCol = lrcinit.LrcWord.Values;

                foreach (string value in valueCol)
                {
                    lyric.Text += value;
                }
            }
            catch
            {
                lyric.Text = "暂无歌词";
            }
        }
Ejemplo n.º 11
0
        } //确认修改

        public void Update()
        {
            var file = new FileInfo(MainWindow.Lrcpath);
            var lrcs = new List <_Lrc>();

            if (file.Extension == ".lrc")
            {
                使用Title输出.IsEnabled     = true;
                使用Title输出.IsChecked     = false;
                C1.Foreground           = new SolidColorBrush(Colors.White);
                使用SubTitle输出.IsEnabled  = true;
                使用SubTitle输出.IsChecked  = false;
                C2.Foreground           = new SolidColorBrush(Colors.White);
                使用ActionBar输出.IsEnabled = true;
                使用ActionBar输出.IsChecked = false;
                C3.Foreground           = new SolidColorBrush(Colors.White);
                使用Tellraw输出.IsEnabled   = true;
                使用Tellraw输出.IsChecked   = false;
                C4.Foreground           = new SolidColorBrush(Colors.White);
                var _l = new Lrc().Serialize(file.FullName);
                foreach (var n in _l.Lrcs)
                {
                    lrcs.Add(new _Lrc()
                    {
                        Content = n.Content, Time = n.Start + " t", appearT = n.Start
                    });
                }
            }
            else if (file.Extension == ".amlrc")
            {
                使用Title输出.IsEnabled     = false;
                使用Title输出.IsChecked     = true;
                C1.Foreground           = new SolidColorBrush(Colors.DarkGray);
                使用SubTitle输出.IsEnabled  = false;
                使用SubTitle输出.IsChecked  = true;
                C2.Foreground           = new SolidColorBrush(Colors.DarkGray);
                使用ActionBar输出.IsEnabled = false;
                使用ActionBar输出.IsChecked = false;
                C3.Foreground           = new SolidColorBrush(Colors.DarkGray);
                使用Tellraw输出.IsEnabled   = false;
                使用Tellraw输出.IsChecked   = false;
                C4.Foreground           = new SolidColorBrush(Colors.DarkGray);
                var _l = new AMLrc().Serialize(file.FullName);
                foreach (var n in _l.Bars)
                {
                    var g = n.Main.Concat(n.Sub);
                    foreach (var _n in g)
                    {
                        lrcs.Add(new _Lrc()
                        {
                            Content = _n.Content, Time = _n.AppearTime + " t", appearT = _n.AppearTime
                        });
                    }
                }
            }
            var _lrcs = from l in lrcs orderby l.appearT select l;

            歌词列表.ItemsSource        = _lrcs;
            使用Title输出.IsChecked     = MainWindow.LyricMode.Title;
            使用SubTitle输出.IsChecked  = MainWindow.LyricMode.SubTitle;
            使用ActionBar输出.IsChecked = MainWindow.LyricMode.ActionBar;
            使用Tellraw输出.IsChecked   = MainWindow.LyricMode.Tellraw;
        }