@@ -28,8 +28,8 @@ def __init__(self, *args, **kwargs):
2828 self .chatSenderIsVerified = ''
2929 self .chat = ''
3030 self .voting = False
31- self .chatBanner = ''
3231 self .chatContainerSearchObject = None
32+ self .chatBannerSearchObject = None
3333 self .chatSearchObject = None
3434
3535 def getVideoPlayer (self ):
@@ -64,35 +64,37 @@ def getChatContainer(self):
6464 self .chatContainer = None
6565 self .chatObject = None
6666 self .voting = None
67- self .chatBanner = ''
6867 if self .chatContainerSearchObject :
6968 self .chatContainerSearchObject .cancel ()
7069
7170 self .chatContainerSearchObject = search (obj , lambda obj : ('yt-live-chat-item-list-renderer' in obj .IA2Attributes .get ('class' ) and obj .IA2Attributes .get ('id' ) == 'items' ) or obj .IA2Attributes .get ('id' ) == 'chat' , self .onFoundChatContainer , continueOnFound = True )
7271
72+ if self .chatBannerSearchObject :
73+ self .chatBannerSearchObject .cancel ()
74+
7375 if self .chatSearchObject :
7476 self .chatSearchObject .cancel ()
7577
7678
7779 def onFoundChatContainer (self , obj ):
78- if obj .IA2Attributes .get ('id' ) == 'chat' :
80+ id = obj .IA2Attributes .get ('id' )
81+ if id == 'chat' :
7982 self .chatRoom = obj
80- else :
83+ elif id == 'items' :
8184 self .chatContainer = obj
8285 self .chatContainerSearchObject .cancel ()
86+ self .readChatBanner ()
8387
8488
8589 def getSubtitle (self ):
8690 '''
8791 取得字幕
8892 '''
89-
9093 self .promptInfoCard ()
9194
9295 self .get_subtitle_object ()
9396
9497 self .readVoting ()
95- self .readChatBanner ()
9698 self .readChat ()
9799
98100 def get_subtitle_object (self ):
@@ -300,29 +302,26 @@ def readChatBanner(self):
300302 if not self .chatContainer :
301303 return
302304
303- banner = self .chatContainer .parent .previous
304- text = ''
305- while banner :
306- obj = banner .firstChild
307- while obj :
308- if obj .name :
309- text += obj .name
310- break
311-
312- obj = obj .firstChild
305+ obj = self .chatContainer .parent .previous
306+ banner = None
307+ while obj :
308+ banner = find (obj , 'firstChild' , 'id' , 'banner-container' )
309+ if banner :
310+ break
313311
314- banner = banner .previous
312+ obj = obj .previous
315313
316- if text and not self . chatBanner :
317- ui . message ( text )
314+ if not banner :
315+ return
318316
319- self .chatBanner = text
317+ self .chatBannerSearchObject = search ( banner , lambda obj : bool ( obj . name ) and obj . role != role ( 'LINK' ), lambda banner : ui . message ( banner . name if banner . role != role ( 'BUTTON' ) else '聊天室橫幅' ), continueOnFound = True )
320318
321319 def readVoting (self ):
322320 if not self .chatRoom :
323321 return
324322
325- votingObj = self .chatRoom .firstChild .next .next
323+ votingObj = self .chatRoom .lastChild
324+ votingObj = find (votingObj , 'firstChild' , 'class' , 'style-scope yt-live-chat-poll-renderer' )
326325 if bool (votingObj ) != self .voting :
327326 self .voting = bool (votingObj )
328327 if self .voting :
0 commit comments