优化多线程环境下的解析
This commit is contained in:
parent
aea058dfbe
commit
17e3a0c4ab
|
@ -19,6 +19,7 @@ namespace N_m3u8DL_RE.Parser
|
|||
private IExtractor extractor;
|
||||
private ParserConfig parserConfig = new ParserConfig();
|
||||
private string rawText;
|
||||
private static SemaphoreSlim semaphore = new SemaphoreSlim(1, 1);
|
||||
|
||||
public StreamExtractor()
|
||||
{
|
||||
|
@ -79,9 +80,17 @@ namespace N_m3u8DL_RE.Parser
|
|||
/// <returns></returns>
|
||||
public async Task<List<StreamSpec>> ExtractStreamsAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
await semaphore.WaitAsync();
|
||||
Logger.Info(ResString.parsingStream);
|
||||
return await extractor.ExtractStreamsAsync(rawText);
|
||||
}
|
||||
finally
|
||||
{
|
||||
semaphore.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据规格说明填充媒体播放列表信息
|
||||
|
@ -89,8 +98,16 @@ namespace N_m3u8DL_RE.Parser
|
|||
/// <param name="streamSpecs"></param>
|
||||
public async Task FetchPlayListAsync(List<StreamSpec> streamSpecs)
|
||||
{
|
||||
try
|
||||
{
|
||||
await semaphore.WaitAsync();
|
||||
Logger.Info(ResString.parsingStream);
|
||||
await extractor.FetchPlayListAsync(streamSpecs);
|
||||
}
|
||||
finally
|
||||
{
|
||||
semaphore.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue