优化多线程环境下的解析
This commit is contained in:
parent
aea058dfbe
commit
17e3a0c4ab
|
@ -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,9 +80,17 @@ namespace N_m3u8DL_RE.Parser
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<List<StreamSpec>> ExtractStreamsAsync()
|
public async Task<List<StreamSpec>> ExtractStreamsAsync()
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await semaphore.WaitAsync();
|
||||||
Logger.Info(ResString.parsingStream);
|
Logger.Info(ResString.parsingStream);
|
||||||
return await extractor.ExtractStreamsAsync(rawText);
|
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)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await semaphore.WaitAsync();
|
||||||
Logger.Info(ResString.parsingStream);
|
Logger.Info(ResString.parsingStream);
|
||||||
await extractor.FetchPlayListAsync(streamSpecs);
|
await extractor.FetchPlayListAsync(streamSpecs);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
semaphore.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue