Example #1
0
 private static async Task LoadAllAudioInfoCandidates(AudioInfo[] audioInfoCandidates, Action <AudioInfo> callback)
 {
     foreach (var candidate in audioInfoCandidates)
     {
         FastConsole.WriteInfo($"开始获取文件\"{Path.GetFileName(candidate.Path)}\"的网易云音乐ID。");
         TrackInfo trackInfo;
         try {
             trackInfo = await SearchTrackAsync(candidate.Album, candidate.Track);
         }
         catch (Exception ex) {
             FastConsole.WriteException(ex);
             trackInfo = null;
         }
         if (trackInfo is null)
         {
             FastConsole.WriteWarning($"无法找到文件\"{Path.GetFileName(candidate.Path)}\"的网易云音乐ID!");
         }
         else
         {
             FastConsole.WriteInfo($"已获取文件\"{Path.GetFileName(candidate.Path)}\"的网易云音乐ID: {trackInfo.Id}。");
             candidate.TrackInfo = new TrackInfo(candidate.Track, candidate.Album, trackInfo.Id);
             _database.TrackInfos.Add(candidate.TrackInfo);
         }
         callback?.Invoke(candidate);
         FastConsole.WriteNewLine();
     }
 }
Example #2
0
        public static async Task ExecuteAsync(Arguments arguments)
        {
            Task   loginTask;
            string databasePath;

            AudioInfo[] audioInfos;

            FastConsole.WriteLine("程序会自动过滤相似度为0的结果与歌词未被收集的结果!!!", ConsoleColor.Green);
            loginTask    = LoginIfNeedAsync(arguments);
            databasePath = Path.Combine(arguments.Directory, ".nlyric");
            LoadDatabase(databasePath);
            audioInfos = LoadAllAudioInfos(arguments.Directory);
            await loginTask;

            // 登录同时进行
            foreach (AudioInfo audioInfo in audioInfos)
            {
                TrackInfo trackInfo;

                if (!(audioInfo.TrackInfo is null))
                {
                    continue;
                }
                FastConsole.WriteInfo($"开始获取文件\"{Path.GetFileName(audioInfo.Path)}\"的网易云音乐ID。");
                try {
                    trackInfo = await SearchTrackAsync(audioInfo.Album, audioInfo.Track);
                }
                catch (Exception ex) {
                    FastConsole.WriteException(ex);
                    trackInfo = null;
                }
                if (trackInfo is null)
                {
                    FastConsole.WriteWarning($"无法找到文件\"{Path.GetFileName(audioInfo.Path)}\"的网易云音乐ID!");
                }
                else
                {
                    FastConsole.WriteInfo($"已获取文件\"{Path.GetFileName(audioInfo.Path)}\"的网易云音乐ID: {trackInfo.Id}。");
                    audioInfo.TrackInfo = new TrackInfo(audioInfo.Track, audioInfo.Album, trackInfo.Id);
                }
                SaveDatabaseCore(databasePath);
                FastConsole.WriteNewLine();
            }
            if (arguments.UseBatch)
            {
                PrepareAllLyrics(audioInfos);
            }
            foreach (AudioInfo audioInfo in audioInfos)
            {
                if (!(audioInfo.TrackInfo is null))
                {
                    await TryDownloadLyricAsync(audioInfo);
                }
            }
            SaveDatabase(databasePath);
        }
Example #3
0
		private static bool CanSkip(string audioPath, string lrcPath) {
			string extension = Path.GetExtension(audioPath);
			if (!IsAudioFile(extension))
				return true;
			if (File.Exists(lrcPath) && !_lyricSettings.AutoUpdate && !_lyricSettings.Overwriting) {
				FastConsole.WriteInfo($"文件\"{Path.GetFileName(audioPath)}\"的歌词已存在,并且自动更新与覆盖已被禁止,正在跳过。");
				return true;
			}
			return false;
		}