@@ -103,25 +103,33 @@ def checkStreamDelay(lines):
103103
104104
105105def checkServiceRecommendations (lines ):
106- maxBitrate = None
107- for i , line in enumerate (lines ):
108- if "User is ignoring service bitrate limits." in line :
109- for j in range (i + 1 , len (lines )):
110- if "video bitrate:" in lines [j ]:
111- maxBitrateMatch = re .search (r'video bitrate:\s+(\d+)' , lines [j ])
112- if maxBitrateMatch :
113- maxBitrate = int (maxBitrateMatch .group (1 ))
114- break
115- break
116-
117- if maxBitrate is not None :
118- for i , line in enumerate (lines ):
119- if "bitrate:" in line and "video bitrate:" not in line :
120- currentBitrateMatch = re .search (r'bitrate:\s+(\d+)' , line )
121- if currentBitrateMatch :
122- currentBitrate = int (currentBitrateMatch .group (1 ))
106+ ignoringStreams = searchWithIndex ("User is ignoring service bitrate limits." , lines )
107+
108+ for _ , index in ignoringStreams [::- 1 ]: # Check last streams first
109+
110+ try :
111+ maxBitrateRE = re .search (r'video bitrate:\s+(\d+)' , lines [index + 2 ])
112+ maxBitrate = int (maxBitrateRE .group (1 )) if maxBitrateRE else float ("nan" )
113+ # Guards against failed regex, nan to fail the comparison if so
114+
115+ attemptStart = searchWithIndex ("channel_layout" , lines [index :])
116+ # This is the audio encoder line, always included after the video encoder
117+ isMultitrack = searchWithIndex ("Go live URL:" , lines [index : index + attemptStart [0 ][1 ]]) if attemptStart else True
118+ # True to skip this attempt if not attemptStart
119+
120+ if not isMultitrack :
121+ # With enhanced broadcasting, the max recommended are irrelevant
122+
123+ bitrateLines = searchExclude ("bitrate:" , lines [index : index + attemptStart [0 ][1 ]], ["video bitrate" , "audio bitrate" , "aggregate" ])
124+ if bitrateLines and "channels" not in bitrateLines [0 ]:
125+
126+ currentBitrateRE = re .search (r'bitrate:\s+(\d+)' , bitrateLines [0 ])
127+ currentBitrate = int (currentBitrateRE .group (1 )) if currentBitrateRE else float ("nan" )
128+ # Guards against failed regex, nan to fail the comparison if so
129+
123130 if currentBitrate > maxBitrate :
124131 return [LEVEL_WARNING , "Max Video Bitrate Limit Exceeded" ,
125132 f"Current bitrate { currentBitrate } kbps exceeds max video bitrate limit { maxBitrate } kbps. "
126133 "This may result in the streaming service not displaying the video from your stream or rejecting it entirely." ]
127- return None
134+ except ValueError :
135+ pass
0 commit comments