-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
72 lines (60 loc) · 2.65 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using Lyrics;
using Lyrics.Downloader;
using Lyrics.Json;
using Lyrics.Models;
using Lyrics.Processor;
using System.Diagnostics.CodeAnalysis;
internal partial class Program
{
private static List<ILyric> _lyrics = [];
private static List<ISong> _songs = [];
public static bool RETRY_FAILED_LYRICS { get; private set; }
public static List<ILyric> Lyrics => _lyrics;
[RequiresUnreferencedCode("Calls Lyrics.Downloader.LyricsDownloader.LyricsDownloader(CloudMusicApi)")]
public static async Task Main()
{
Startup.Configure(out int MAX_COUNT,
out bool _RETRY_FAILED_LYRICS,
out List<(string VideoId, int StartTime)> excludeSongs,
out List<string> excludeTitles,
out List<ILyric> lyricsFromENV);
RETRY_FAILED_LYRICS = _RETRY_FAILED_LYRICS;
try
{
(_songs, _lyrics) = await JsonFileProcessor.ReadJsonFilesAsync();
LyricsDownloader lyricsDownloader = new(new());
LyricsProcessor lyricsProcessor = new(lyricsDownloader, ref _songs, ref _lyrics);
lyricsProcessor.ProcessLyricsFromENV(lyricsFromENV);
lyricsProcessor.RemoveExcludeSongs(excludeSongs);
lyricsProcessor.RemoveSongsContainSpecifiedTitle(excludeTitles);
List<ILyric> removed = [
.. lyricsProcessor.RemoveLyricsNotContainsInSongs(),
.. lyricsProcessor.RemoveDuplicatesLyrics()
];
List<ISong> diffList = lyricsProcessor.FilterNewSongs();
Console.WriteLine($"Get {diffList.Count} new songs.");
if (diffList.Count > MAX_COUNT)
{
Console.WriteLine($"Too many songs to process. Max: {MAX_COUNT}, Actual: {diffList.Count}");
Console.WriteLine("Please execute this program again later.");
diffList = diffList.Take(MAX_COUNT).ToList();
}
SongProcessor songProcessor = new(lyricsDownloader, ref _lyrics);
await songProcessor.ProcessNewSongs(diffList, removed);
await lyricsProcessor.DownloadMissingLyrics();
lyricsProcessor.RemoveLyricsNotInUsed();
Console.WriteLine($"Exist files count: {new DirectoryInfo("Lyrics").GetFiles().Length}");
// Lyrics.json is written when the program exits.
}
catch (Exception e)
{
Console.Error.WriteLine("Unhandled exception: " + e.Message);
Console.Error.WriteLine(e.StackTrace);
Environment.Exit(-1);
}
finally
{
Environment.Exit(0);
}
}
}