优化多线程环境下的解析

This commit is contained in:
nilaoda 2022-07-06 15:37:55 +08:00
parent aea058dfbe
commit 17e3a0c4ab
1 changed files with 21 additions and 4 deletions

View File

@ -19,6 +19,7 @@ namespace N_m3u8DL_RE.Parser
private IExtractor extractor; private IExtractor extractor;
private ParserConfig parserConfig = new ParserConfig(); private ParserConfig parserConfig = new ParserConfig();
private string rawText; private string rawText;
private static SemaphoreSlim semaphore = new SemaphoreSlim(1, 1);
public StreamExtractor() public StreamExtractor()
{ {
@ -79,8 +80,16 @@ namespace N_m3u8DL_RE.Parser
/// <returns></returns> /// <returns></returns>
public async Task<List<StreamSpec>> ExtractStreamsAsync() public async Task<List<StreamSpec>> ExtractStreamsAsync()
{ {
Logger.Info(ResString.parsingStream); try
return await extractor.ExtractStreamsAsync(rawText); {
await semaphore.WaitAsync();
Logger.Info(ResString.parsingStream);
return await extractor.ExtractStreamsAsync(rawText);
}
finally
{
semaphore.Release();
}
} }
/// <summary> /// <summary>
@ -89,8 +98,16 @@ namespace N_m3u8DL_RE.Parser
/// <param name="streamSpecs"></param> /// <param name="streamSpecs"></param>
public async Task FetchPlayListAsync(List<StreamSpec> streamSpecs) public async Task FetchPlayListAsync(List<StreamSpec> streamSpecs)
{ {
Logger.Info(ResString.parsingStream); try
await extractor.FetchPlayListAsync(streamSpecs); {
await semaphore.WaitAsync();
Logger.Info(ResString.parsingStream);
await extractor.FetchPlayListAsync(streamSpecs);
}
finally
{
semaphore.Release();
}
} }
} }
} }