Пример #1
0
 private static async Task LoginIfNeedAsync(Arguments arguments)
 {
     if (string.IsNullOrEmpty(arguments.Account) || string.IsNullOrEmpty(arguments.Password))
     {
         FastConsole.WriteLine("登录可避免出现大部分API错误!!!当前是免登录状态,若软件出错请尝试登录!!!", ConsoleColor.Green);
         FastConsole.WriteLine("强烈建议登录使用软件:\"NLyric.exe -d C:\\Music -a [email protected] -p 123456\"", ConsoleColor.Green);
     }
     else
     {
         FastConsole.WriteLine("登录中...", ConsoleColor.Green);
         if (await _cloudMusic.LoginAsync(arguments.Account, arguments.Password))
         {
             FastConsole.WriteLine("登录成功!", ConsoleColor.Green);
         }
         else
         {
             FastConsole.WriteError("登录失败,输入任意键以免登录模式运行或重新运行尝试再次登录!");
             try {
                 FastConsole.ReadKey(true);
             }
             catch {
             }
         }
     }
     FastConsole.WriteNewLine();
 }
Пример #2
0
        private static async Task Main(string[] args)
        {
            if (args is null || args.Length == 0)
            {
                CommandLine.ShowUsage <Arguments>();
                return;
            }

            Arguments arguments;

            try {
                Console.Title = GetTitle();
            }
            catch {
            }
            if (!CommandLine.TryParse(args, out arguments))
            {
                CommandLine.ShowUsage <Arguments>();
                return;
            }
            AllSettings.Default = JsonConvert.DeserializeObject <AllSettings>(File.ReadAllText("Settings.json"));
            await NLyricImpl.ExecuteAsync(arguments);

            FastConsole.WriteLine("完成", ConsoleColor.Green);
            FastConsole.Synchronize();
            if (IsN00bUser() || Debugger.IsAttached)
            {
                Console.WriteLine("按任意键继续...");
                try {
                    Console.ReadKey(true);
                }
                catch {
                }
            }
        }
Пример #3
0
        public static async Task ExecuteAsync(Arguments arguments)
        {
            FastConsole.WriteLine("程序会自动过滤相似度为0的结果与歌词未被收集的结果!!!", ConsoleColor.Green);
            var    loginTask    = LoginIfNeedAsync(arguments);
            string databasePath = Path.Combine(arguments.Directory, ".nlyric");

            LoadDatabase(databasePath);
            var   audioInfos          = LoadAllAudioInfos(arguments.Directory);
            var   audioInfoCandidates = audioInfos.Where(t => t.TrackInfo is null).ToArray();
            await loginTask;

            // 登录同时进行
            if (!arguments.UpdateOnly)
            {
                if (arguments.UseBatch)
                {
                    _ = AccelerateAllTracksAsync(audioInfoCandidates);
                }
                await LoadAllAudioInfoCandidates(audioInfoCandidates, _ => SaveDatabaseCore(databasePath));
            }
            audioInfos = audioInfos.Where(t => !(t.TrackInfo is null)).ToArray();
            if (arguments.UseBatch)
            {
                _ = AccelerateAllLyricsAsync(audioInfos);
            }
            await DownloadLyricsAsync(audioInfos);

            SaveDatabase(databasePath);
        }
Пример #4
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);
        }