1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- using System;
- using System.Net;
- using System.Text;
- using System.Threading;
- using System.Web;
- using System.Windows.Forms;
- namespace LrcTool
- {
- public partial class LrcFetcherPage : UserControl
- {
- public LrcFetcherPage()
- {
- InitializeComponent();
- }
- private void PasteLinkLabel_Click(object sender, EventArgs e)
- {
- var text = Clipboard.GetText();
- var uri = new Uri(text);
- var queryString = HttpUtility.ParseQueryString(uri.Query);
- var songId = queryString["id"];
- SongUrlTextBox.Text = text;
- SongIdTextBox.Text = songId;
- LrcApiTextBox.Text = $"http://music.163.com/api/song/media?id={songId}";
- }
- private delegate void Action();
- private void FireButton_Click(object sender, EventArgs e)
- {
- var url = LrcApiTextBox.Text;
- FireButton.Enabled = false;
- new Thread(() =>
- {
- void Log(string text)
- {
- Invoke(new Action(() =>
- {
- LeftRichTextBox.AppendText($"{text}{Environment.NewLine}");
- LeftRichTextBox.SelectionStart = LeftRichTextBox.Text.Length;
- LeftRichTextBox.ScrollToCaret();
- }));
- }
- try
- {
- Log($"Fetching {url}");
- var json = new WebClient { Encoding = Encoding.UTF8 }.DownloadString(url);
- Log($"Result: {json}");
- var jsonObject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(json);
- Log("Parsing...");
- var lrc = jsonObject.Value<string>("lyric");
- Log("Output...");
- Invoke(new Action(() => RightRichTextBox.Text = lrc));
- Log("OK");
- }
- catch (Exception exception)
- {
- Log("---- BEGIN EXCEPTION ----");
- Log(exception.ToString());
- Log("---- END EXCEPTION ----");
- }
- Invoke(new Action(() => FireButton.Enabled = true));
- }).Start();
- }
- private void CopyButton_Click(object sender, EventArgs e)
- {
- Clipboard.SetText(RightRichTextBox.Text);
- }
- }
- }
|