示例#1
0
        /// <summary>
        /// 并行下载歌词任务
        /// </summary>
        /// <param name="down">插件</param>
        /// <param name="list">待下载列表</param>
        private async void parallelDownLoadLryic(Dictionary <int, MusicInfoModel> list, IPlug_Lrc down)
        {
            setBottomStatusText(StatusHeadEnum.NORMAL, "正在下载歌词...");
            progress_DownLoad.Maximum = list.Count; progress_DownLoad.Value = 0;
            await Task.Run(() =>
            {
                disEnabledButton();
                Parallel.ForEach(list, new ParallelOptions()
                {
                    MaxDegreeOfParallelism = SettingManager.SetValue.DownloadThreadNum
                }, (item) =>
                {
                    string _path = Path.GetDirectoryName(item.Value.Path) + @"\" + Path.GetFileNameWithoutExtension(item.Value.Path) + ".lrc";
                    if (SettingManager.SetValue.IsIgnoreExitsFile && File.Exists(_path))
                    {
                        listView_MusicInfos.Items[item.Key].SubItems[6].Text = "略过";
                    }
                    else
                    {
                        byte[] _lrcData;
                        if (down.DownLoad(item.Value.Artist, item.Value.SongName, out _lrcData, SettingManager.SetValue.IsDownTranslate))
                        {
                            string _lrcPath = null;

                            #region > 输出方式 <
                            if (SettingManager.SetValue.UserDirectory.Equals(string.Empty)) // 同目录
                            {
                                _lrcPath = Path.GetDirectoryName(item.Value.Path) + @"\" + Path.GetFileNameWithoutExtension(item.Value.Path) + ".lrc";
                            }
                            else // 自定义目录
                            {
                                _lrcPath = Path.Combine(SettingManager.SetValue.UserDirectory, Path.GetFileNameWithoutExtension(item.Value.Path) + ".lrc");
                            }
                            #endregion

                            EncodingConverter _convert = getEncodingConvert();
                            _lrcData = _convert.ConvertBytes(_lrcData, SettingManager.SetValue.EncodingName);

                            FileUtils.WriteFile(_lrcPath, _lrcData);
                            listView_MusicInfos.Items[item.Key].SubItems[6].Text = "成功";
                        }
                        else
                        {
                            listView_MusicInfos.Items[item.Key].SubItems[6].Text = "失败";
                        }
                    }
                    progress_DownLoad.Value += 1;
                });
                setBottomStatusText(StatusHeadEnum.SUCCESS, "歌词下载完成!");
                enabledButton();
            });
        }
示例#2
0
        /// <summary>
        /// 并行下载歌词任务
        /// </summary>
        /// <param name="down">插件</param>
        /// <param name="list">待下载列表</param>
        private void parallelDownLoadLryic(Dictionary <int, MusicInfoModel> list, IPlug_Lrc down)
        {
            setBottomStatusText(StatusHeadEnum.NORMAL, "正在下载歌词...");
            disenabledButton();
            progress_DownLoad.Maximum = list.Count;
            progress_DownLoad.Value   = 0;

            Parallel.ForEach(list.Where(x => !x.Value.IsSuccess), new ParallelOptions()
            {
                MaxDegreeOfParallelism = SettingManager.SetValue.DownloadThreadNum
            }, (item) =>
            {
                progress_DownLoad.Value += 1;

                string _path = FileUtils.BuildLrcPath(item.Value.Path);
                if (SettingManager.SetValue.IsIgnoreExitsFile && File.Exists(_path))
                {
                    listView_MusicInfos.Items[item.Key].SubItems[6].Text = "略过";
                    return;
                }

                try
                {
                    bool _isSuccess = down.DownLoad(item.Value.Artist, item.Value.SongName, out byte[] _lrcData, SettingManager.SetValue.IsDownTranslate);

                    if (!_isSuccess)
                    {
                        listView_MusicInfos.Items[item.Key].SubItems[6].Text = "失败";
                        return;
                    }

                    string _lrcPath = FileUtils.BuildLrcPath(item.Value.Path, SettingManager.SetValue.UserDirectory);
                    _lrcData        = encodingConvert(_lrcData);
                    FileUtils.WriteFile(_lrcPath, _lrcData);

                    item.Value.IsSuccess = true;
                    listView_MusicInfos.Items[item.Key].SubItems[6].Text = "成功";
                }