Add the ability to display whole thread containing match #3

Open
opened 2023-05-15 23:12:39 +02:00 by Benjamin_Loison · 1 comment

In order to avoid to open too many matches with Firefox, as it hasn't worked fine with my potentially current low-end computer and connection.

Maybe just showing whether or not a comment has answers or a parent comment may be a first step. Below is the add-on for 2888f5973d.

diff --git a/search_in_youtube_video_comments.py b/search_in_youtube_video_comments.py
index 1d8a8ca..6e11862 100755
--- a/search_in_youtube_video_comments.py
+++ b/search_in_youtube_video_comments.py
@@ -18,9 +18,16 @@ OPEN_IN_FIREFOX = input('Open comment in firefox (yes or no): ') == 'yes'
 nextPageToken = ''
 commentRegexCompiled = re.compile(COMMENT_REGEX)
 
-def treatComment(comment):
+all, avoided = 0, 0
+
+def treatComment(comment, hasMore):
+    global all, avoided
     textOriginal = comment['snippet']['textOriginal']
     if commentRegexCompiled.search(textOriginal):
+        all += 1
+        if not hasMore:
+            avoided += 1
+            return
         id = comment['id']
         url = f'https://www.youtube.com/watch?v={VIDEO_ID}&lc={id}'
         print(f'{url} {textOriginal}')
@@ -38,16 +45,17 @@ while True:
             while True:
                 commentsData = getContentFromURL(f'comments?part=snippet&parentId={parentId}&maxResults=100&pageToken={commentsNextPageToken}')
                 for item in commentsData['items']:
-                    treatComment(item)
+                    treatComment(item, True)
                 if not 'nextPageToken' in commentsData:
                     break
                 commentsNextPageToken = commentsData['nextPageToken']
         else:
-            treatComment(snippet['topLevelComment'])
+            treatComment(snippet['topLevelComment'], totalReplyCount > 0)
             if totalReplyCount > 0:
                 for comment in item['replies']['comments']:
-                    treatComment(comment)
+                    treatComment(comment, True)
     if not 'nextPageToken' in data:
         break
     nextPageToken = data['nextPageToken']
 
+print(all, avoided)
\ No newline at end of file
In order to avoid to open too many matches with Firefox, as it hasn't worked fine with my potentially current *low-end* computer and connection. Maybe just showing whether or not a comment has answers or a parent comment may be a first step. Below is the add-on for 2888f5973d85e879c6b1fe045b31c3ad385b87e4. ```diff diff --git a/search_in_youtube_video_comments.py b/search_in_youtube_video_comments.py index 1d8a8ca..6e11862 100755 --- a/search_in_youtube_video_comments.py +++ b/search_in_youtube_video_comments.py @@ -18,9 +18,16 @@ OPEN_IN_FIREFOX = input('Open comment in firefox (yes or no): ') == 'yes' nextPageToken = '' commentRegexCompiled = re.compile(COMMENT_REGEX) -def treatComment(comment): +all, avoided = 0, 0 + +def treatComment(comment, hasMore): + global all, avoided textOriginal = comment['snippet']['textOriginal'] if commentRegexCompiled.search(textOriginal): + all += 1 + if not hasMore: + avoided += 1 + return id = comment['id'] url = f'https://www.youtube.com/watch?v={VIDEO_ID}&lc={id}' print(f'{url} {textOriginal}') @@ -38,16 +45,17 @@ while True: while True: commentsData = getContentFromURL(f'comments?part=snippet&parentId={parentId}&maxResults=100&pageToken={commentsNextPageToken}') for item in commentsData['items']: - treatComment(item) + treatComment(item, True) if not 'nextPageToken' in commentsData: break commentsNextPageToken = commentsData['nextPageToken'] else: - treatComment(snippet['topLevelComment']) + treatComment(snippet['topLevelComment'], totalReplyCount > 0) if totalReplyCount > 0: for comment in item['replies']['comments']: - treatComment(comment) + treatComment(comment, True) if not 'nextPageToken' in data: break nextPageToken = data['nextPageToken'] +print(all, avoided) \ No newline at end of file ```
Author
Owner

Could maybe avoid to open answers and associated parent, as loading many tabs is quite heavy compared to just doing some clicks to expand the answers (which we know contain matches). However in the worst case of having two matches in hundreds of answers, it's not a good solution, especially when noticing that all answers don't load at once, and so we can't evaluate the regex directly within the web-browser for treating the loaded answers.

Could maybe avoid to open answers and associated parent, as loading many tabs is quite heavy compared to just doing some clicks to expand the answers (which we know contain matches). However in the worst case of having two matches in hundreds of answers, it's not a good solution, especially when noticing that all answers don't load at once, and so we can't evaluate the regex directly within the web-browser for treating the loaded answers.
This repo is archived. You cannot comment on issues.
No Label
No Milestone
No project
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Benjamin_Loison/Search_in_YouTube_video_comments#3
No description provided.