Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="folderPath">".\\"或"C:\sss\"</param>
        /// <param name="filenamePatern">"[title].lrc"支援[track number][title][artist][album]</param>
        public LyricsFileWriter(string folderPath, string filenamePatern, NeteaseMusic.Music music, string fileEncoding = "UTF-8", int totalWidth = 2)
        {
            if (!folderPath.EndsWith(@"\"))
            {
                folderPath += @"\";
            }
            this.folderPath = folderPath;
            if (!System.IO.Directory.Exists(folderPath))
            {
                System.IO.Directory.CreateDirectory(folderPath);
            }
            this.fileEncoding = fileEncoding;

            //当获取不到Title的时候,直接以ID号命名。
            if (music.Title == null || music.Title == "")
            {
                fileName = music.ID.ToString() + ".lrc";
                return;
            }

            fileName = filenamePatern;//结尾应该为.lrc
            fileName = fileName.Replace("[track number]", music.Index.ToString().PadLeft(totalWidth, '0'));
            fileName = fileName.Replace("[title]", music.Title);
            fileName = fileName.Replace("[artist]", music.Artist);
            fileName = fileName.Replace("[album]", music.Album);
            fileName = FormatFileName.CleanInvalidFileName(fileName);
        }
 private void listView1_SelectedIndexChanged(object sender, EventArgs e)
 {
     var lv = (ListView)sender;
     if (lv.SelectedItems.Count > 0)
     {
         var lvi = lv.SelectedItems[0];
         FormatFileName FFN = new FormatFileName();
         textBox1.Text = FFN.OutputFormat(taskInfo, lvi.SubItems[1].Text);
     }
 }
Exemple #3
0
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            var lv = (ListView)sender;

            if (lv.SelectedItems.Count > 0)
            {
                var            lvi = lv.SelectedItems[0];
                FormatFileName FFN = new FormatFileName();
                textBox1.Text = FFN.OutputFormat(taskInfo, lvi.SubItems[1].Text);
            }
        }
Exemple #4
0
 const string Bar = "SongNum|SongID      |SongName                                          |LrcSts         |ErrorInfo"; //string.Format("{0,-7}|{1,-12}|{2,-50}|{3,-15}|ErrorInfo", "SongNum", "SongID", "SongName", "LrcSts");
 public LogFileWriter(string folderPath, string fileName = "Log.txt", string fileEncoding = "UTF-8")
 {
     if (!folderPath.EndsWith(@"\"))
     {
         folderPath += @"\";
     }
     this.folderPath = folderPath;
     if (!System.IO.Directory.Exists(folderPath))
     {
         System.IO.Directory.CreateDirectory(folderPath);
     }
     fileName          = FormatFileName.CleanInvalidFileName(fileName);
     this.fileName     = fileName;
     this.fileEncoding = fileEncoding;
     log.Add(HEAD_DESCRIPTION);
     for (int i = 0; i < 2; i++)
     {
         log.Add("");
     }
 }
Exemple #5
0
        public void AnalysisTask(TaskInfo taskInfo)
        {
            var t = new Thread(() =>
            {
                try
                {
                    taskInfo.Status = DownloadStatus.TaskAnalysis;
                    PreDelegates.Refresh(new ParaRefresh(taskInfo));


                    if (taskInfo.Analysis())
                    {
                        taskInfo.Status = DownloadStatus.AnalysisComplete;
                        if (taskInfo.CustomFileName == "Unknow")
                        {
                            FormatFileName FFN      = new FormatFileName();
                            taskInfo.CustomFileName = FFN.OutputFormat(taskInfo, CoreManager.ConfigManager.Settings.SelectFormat);
                        }
                        PreDelegates.Refresh(new ParaRefresh(taskInfo));
                    }
                    else
                    {
                        taskInfo.Status = DownloadStatus.AnalysisFailed;
                        PreDelegates.Refresh(new ParaRefresh(taskInfo));
                    }
                }
                catch (Exception ex)
                {
                    CoreManager.LogManager.Debug(ex.ToString());
                    taskInfo.Status = DownloadStatus.Error;
                    PreDelegates.Refresh(new ParaRefresh(taskInfo));
                    CoreManager.LogManager.Debug(ex.ToString());
                }
            })
            {
                IsBackground = true
            };

            t.Start();
        }
        public void AnalysisTask(TaskInfo taskInfo)
        {
            var t = new Thread(() =>
            {
                try
                {
                    taskInfo.Status = DownloadStatus.TaskAnalysis;
                    PreDelegates.Refresh(new ParaRefresh(taskInfo));

                    if (taskInfo.Analysis())
                    {
                        taskInfo.Status = DownloadStatus.AnalysisComplete;
                        if (taskInfo.CustomFileName == "Unknow")
                        {
                            FormatFileName FFN = new FormatFileName();
                            taskInfo.CustomFileName = FFN.OutputFormat(taskInfo, CoreManager.ConfigManager.Settings.SelectFormat);
                        }
                        PreDelegates.Refresh(new ParaRefresh(taskInfo));
                    }
                    else
                    {
                        taskInfo.Status = DownloadStatus.AnalysisFailed;
                        PreDelegates.Refresh(new ParaRefresh(taskInfo));
                    }

                }
                catch (Exception ex)
                {
                    CoreManager.LogManager.Debug(ex.ToString());
                    taskInfo.Status = DownloadStatus.Error;
                    PreDelegates.Refresh(new ParaRefresh(taskInfo));
                    CoreManager.LogManager.Debug(ex.ToString());
                }

            }) {IsBackground = true};
            t.Start();
        }
 private void richTextBox1_TextChanged(object sender, EventArgs e)
 {
     FormatFileName FFN = new FormatFileName();
     textBox2.Text = FFN.OutputFormat(taskInfo, richTextBox1.Text);
 }
Exemple #8
0
        private void GETbutton_Click(object sender, EventArgs e)
        {
            string filenamePattern = FilenamePatterncomboBox.Text;

            GETbutton.Enabled               = false;
            StatusInfolabel.Text            = "StatusInfo";
            StatusPDFinishedCountlabel.Text = "0";
            StatusPDTotalCountlabel.Text    = "0";
            Stopwatch sw = new Stopwatch();

            sw.Start();
            int id         = Convert.ToInt32(IDtextBox.Text);
            int modelIndex = Convert.ToInt32(LyricsStylenumericUpDown.Value);
            int delayMsec  = Convert.ToInt32(DelayMsecnumericUpDown.Value);

            if (MusicradioButton.Checked)
            {
                Music        m      = new Music(id);
                string       Log    = "";
                LyricsStatus status = LyricsStatus.UNSURED;
                if (ReviseRawcheckBox.Checked == false)
                {
                    Log = DownloadLrc(".\\", filenamePattern, m, modelIndex, delayMsec, out status, out string filePath);//正常的自动化操作
                }
                else
                {
                    HttpRequest hr = new HttpRequest();
                    string      sContentOriLyrics = hr.GetContent("https://music.163.com/api/song/media?id=" + id);
                    Clipboard.SetText(sContentOriLyrics, TextDataFormat.UnicodeText);
                    if (MessageBox.Show("OriLyrics raw text has been set is in the clipboard. Please follow these guide below." + Environment.NewLine + Environment.NewLine + "==========" + Environment.NewLine + @"1. Use Notepad++ to read(such as ""paste"") text from the clipboard." + Environment.NewLine + @"2. Try to revise the text. The most mistake we face is wrong typo. (You can search "".lrc guidance"" to learn more.)" + Environment.NewLine + @"3. After revising, please set revised text to the clipboard(such as ""copy"")" + Environment.NewLine + @"4. Click ""Yes"" button. Software will use the revised text instead of the raw text." + Environment.NewLine + "==========" + Environment.NewLine + Environment.NewLine + @"**If you don't know why you're seeing this messagebox now or you don't know what to do, just click ""No"" button. Don't worry, nothing wrong will happen.**" + Environment.NewLine + @"You can click the blue label ""Need Help?"" in the LrcDownloader Form to learn more about this function.", "OriLyrics raw text - ReviseRaw(Func)_Step 1", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        sContentOriLyrics = Clipboard.GetText(TextDataFormat.UnicodeText);
                    }

                    string sContentTransLyrics = hr.GetContent("https://music.163.com/api/song/lyric?os=pc&id=" + id + "&tv=-1");
                    Clipboard.SetText(sContentTransLyrics, TextDataFormat.UnicodeText);
                    if (MessageBox.Show("TransLyrics raw text has been set is in the clipboard. Please follow these guide below." + Environment.NewLine + Environment.NewLine + "==========" + Environment.NewLine + @"1. Use Notepad++ to read(such as ""paste"") text from the clipboard." + Environment.NewLine + @"2. Try to revise the text. The most mistake we face is wrong typo. (You can search "".lrc guidance"" to learn more.)" + Environment.NewLine + @"3. After revising, please set revised text to the clipboard(such as ""copy"")" + Environment.NewLine + @"4. Click ""Yes"" button. Software will use the revised text instead of the raw text." + Environment.NewLine + "==========" + Environment.NewLine + Environment.NewLine + @"**If you don't know why you're seeing this messagebox now or you don't know what to do, just click ""No"" button. Don't worry, nothing wrong will happen.**" + Environment.NewLine + @"You can click the blue label ""Need Help?"" in the LrcDownloader Form to learn more about this function.", "TransLyrics raw text - ReviseRaw(Func)_Step 2", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        sContentTransLyrics = Clipboard.GetText(TextDataFormat.UnicodeText);
                    }

                    Log = DownloadLrc(".\\", filenamePattern, m, modelIndex, delayMsec, out status, out string filePath, revisedsContentOriLyricsForUserReviseFunc: sContentOriLyrics, revisedsContentTransLyricsForUserReviseFunc: sContentTransLyrics);
                }
                sw.Stop();
                if (Log == "")
                {
                    StatusInfolabel.Text = "Done Status:" + status + "\r\nUsed Time:" + Math.Round(sw.Elapsed.TotalSeconds, 3) + "sec";
                }
                else
                {
                    StatusInfolabel.Text = Log + " Status:" + status + "\r\nUsed Time:" + Math.Round(sw.Elapsed.TotalSeconds, 3) + "sec";
                }
                GETbutton.Enabled = true;
                IDtextBox.Clear();
            }
            else if (PlaylistradioButton.Checked)
            {
                cancelToken = new CancellationTokenSource();
                ParallelOptions parOpts = new ParallelOptions()
                {
                    CancellationToken      = cancelToken.Token,
                    MaxDegreeOfParallelism = System.Environment.ProcessorCount//上面三行针对TPL并行类库
                };
                Task.Factory.StartNew(() =>
                {
                    Playlist pl             = new Playlist(id);
                    LogFileWriter logWriter = new LogFileWriter(@".\\" + FormatFileName.CleanInvalidFileName(pl.Name) + @"\");
                    List <long> idList      = pl.SongidInPlaylist;
                    logWriter.AppendLyricsDownloadTaskDetail();
                    logWriter.AppendLyricsDownloadTaskDetail(pl.SongidInPlaylist.Count);
                    this.Invoke((Action) delegate
                    {
                        StatusPDTotalCountlabel.Text = idList.Count.ToString(); //写Status
                        Cancelbutton.Enabled         = true;                    //下面使用TPL类库,可以取消
                    });
                    try
                    {
                        Parallel.For(0, idList.Count, parOpts, i =>

                        {
                            parOpts.CancellationToken.ThrowIfCancellationRequested();
                            string ErrorLog     = "";
                            LyricsStatus status = LyricsStatus.UNSURED;
                            string filePath     = "";
                            Music m             = new Music(idList[i], i + 1);
                            try
                            {
                                ErrorLog = DownloadLrc(@".\\" + FormatFileName.CleanInvalidFileName(pl.Name) + @"\", filenamePattern, m, modelIndex, delayMsec, out status, out filePath);
                            }
                            catch (Exception ex)
                            {
                                ErrorLog += "<" + ex.Message + ">";
                            }
                            finally
                            {
                                if (System.IO.File.Exists(filePath))
                                {
                                    logWriter.AppendLyricsDownloadTaskDetail(i + 1, idList[i], m.Title, status.ToString(), "√" + ErrorLog);
                                }
                                else
                                {
                                    logWriter.AppendLyricsDownloadTaskDetail(i + 1, idList[i], m.Title, status.ToString(), "×" + ErrorLog);
                                }
                                this.Invoke((Action) delegate
                                {
                                    StatusPDFinishedCountlabel.Text = (Convert.ToInt32(StatusPDFinishedCountlabel.Text) + 1).ToString();
                                });
                                m = null;
                            }
                        });
                    }
                    catch (OperationCanceledException)
                    {
                        //
                    }
                    finally
                    {
                        this.Invoke((Action) delegate
                        {
                            Cancelbutton.Enabled = false;
                            GETbutton.Enabled    = true;
                            IDtextBox.Clear();
                        });
                    }

                    sw.Stop();
                    logWriter.AppendHeadInformation("Playlist", id, pl.Name, idList.Count, cancelToken.IsCancellationRequested == true ? "Canceled" : "Finished");
                    logWriter.AppendBottomInformation(Math.Round(sw.Elapsed.TotalSeconds, 3));
                    logWriter.WriteFIle();
                    this.Invoke((Action) delegate
                    {
                        StatusInfolabel.Text = (cancelToken.IsCancellationRequested == true ? "Canceled" : "Finished") + "\r\nRead Log.txt to learn more.";
                    });
                    cancelToken.Dispose();
                    pl = null;
                });
            }
            else if (AlbumradioButton.Checked)
            {
                cancelToken = new CancellationTokenSource();
                ParallelOptions parOpts = new ParallelOptions()
                {
                    CancellationToken      = cancelToken.Token,
                    MaxDegreeOfParallelism = System.Environment.ProcessorCount//上面三行针对TPL并行类库
                };
                Task.Factory.StartNew(() =>
                {
                    Album a = new Album(id);
                    LogFileWriter logWriter = new LogFileWriter(@".\\" + FormatFileName.CleanInvalidFileName(a.Name) + @"\");
                    List <long> idList      = a.SongidInAlbum;
                    logWriter.AppendLyricsDownloadTaskDetail();
                    logWriter.AppendLyricsDownloadTaskDetail(a.SongidInAlbum.Count);
                    this.Invoke((Action) delegate
                    {
                        StatusPDTotalCountlabel.Text = idList.Count.ToString(); //写Status
                        Cancelbutton.Enabled         = true;                    //下面使用TPL类库,可以取消
                    });
                    try
                    {
                        Parallel.For(0, idList.Count, parOpts, i =>
                        {
                            parOpts.CancellationToken.ThrowIfCancellationRequested();
                            Music m             = new Music(idList[i], i + 1);
                            string ErrorLog     = "";
                            LyricsStatus status = LyricsStatus.UNSURED;
                            string filePath     = "";
                            try
                            {
                                ErrorLog = DownloadLrc(@".\\" + FormatFileName.CleanInvalidFileName(a.Name) + @"\", filenamePattern, m, modelIndex, delayMsec, out status, out filePath);
                            }
                            catch (Exception ex)
                            {
                                ErrorLog += "<" + ex.Message + ">";
                            }
                            finally
                            {
                                if (System.IO.File.Exists(filePath))
                                {
                                    logWriter.AppendLyricsDownloadTaskDetail(i + 1, idList[i], m.Title, status.ToString(), "√" + ErrorLog);
                                }
                                else
                                {
                                    logWriter.AppendLyricsDownloadTaskDetail(i + 1, idList[i], m.Title, status.ToString(), "×" + ErrorLog);
                                }
                                this.Invoke((Action) delegate
                                {
                                    StatusPDFinishedCountlabel.Text = (Convert.ToInt32(StatusPDFinishedCountlabel.Text) + 1).ToString();
                                });
                                m = null;
                            }
                        });
                    }
                    catch (OperationCanceledException)
                    {
                        //
                    }
                    finally
                    {
                        this.Invoke((Action) delegate
                        {
                            Cancelbutton.Enabled = false;
                            GETbutton.Enabled    = true;
                            IDtextBox.Clear();
                        });
                    }
                    sw.Stop();
                    logWriter.AppendHeadInformation("Album", id, a.Name, idList.Count, cancelToken.IsCancellationRequested == true ? "Canceled" : "Finished");
                    logWriter.AppendBottomInformation(Math.Round(sw.Elapsed.TotalSeconds, 3));
                    logWriter.WriteFIle();
                    this.Invoke((Action) delegate
                    {
                        StatusInfolabel.Text = (cancelToken.IsCancellationRequested == true ? "Canceled" : "Finished") + "\r\nRead Log.txt to learn more.";
                    });
                    cancelToken.Dispose();
                    a = null;
                });
            }
        }
 internal string GetFolderName()
 {
     return(FormatFileName.CleanInvalidFileName(Name));
 }
Exemple #10
0
        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            FormatFileName FFN = new FormatFileName();

            textBox2.Text = FFN.OutputFormat(taskInfo, richTextBox1.Text);
        }