Skip to content

Commit

Permalink
增加预防HLS隐藏式切流的逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
CHKZL committed Dec 2, 2024
1 parent 60d15bb commit 878ac4c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions Core/LiveChat/LiveChatListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ private void _parse(string jsonBody)
}
catch (Exception) { return; }
string cmd = (string)obj["cmd"];
//Log.Info("test",$"收到cmd:{cmd}");
switch (cmd)
{

Expand Down
24 changes: 21 additions & 3 deletions Core/RuntimeObject/Download/HLS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,31 @@ await Task.Run(() =>
{
downloadSizeForThisCycle += WriteToFile(fs, $"{hostClass.host}{hostClass.base_url}{hostClass.eXTM3U.Map_URI}?{hostClass.extra}");
}
foreach (var item in hostClass.eXTM3U.eXTINFs)
if (currentLocation != 0)
{
if (long.TryParse(item.FileName, out long index) && index > currentLocation)
//用于处理流悄悄切了,但是没有发现的情况
bool FileNameTimeout = hostClass.eXTM3U.eXTINFs.All(extinf =>
{
if (long.TryParse(extinf.FileName, out long value))
{
return value != currentLocation;
}
return false;
});
if (FileNameTimeout)
{
//如果本次HLS获取到的内容前后都包含上一秒的切片,视为换了全新的切片队列
hlsState = DlwnloadTaskState.AnchorReStream;
return;
}
}
foreach (var item in hostClass.eXTM3U.eXTINFs)
{
if (long.TryParse(item.FileName, out long index) && (index == currentLocation + 1 || currentLocation == 0))
{
downloadSizeForThisCycle += WriteToFile(fs, $"{hostClass.host}{hostClass.base_url}{item.FileName}.{item.ExtensionName}?{hostClass.extra}");
currentLocation = index;
}
}
}
hostClass.eXTM3U.eXTINFs = new();
values.Add((downloadSizeForThisCycle, DateTime.Now));
Expand Down

0 comments on commit 878ac4c

Please sign in to comment.