From e19ea59ae48299b2ad2a6b16570e953b872bfd3f Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Thu, 27 Apr 2023 00:04:24 +0200 Subject: [PATCH] Make `VIDEO_ID`, `API_KEY` and `COMMENT_REGEX` use `stdin` and not hard-coded values --- search_in_youtube_video_comments.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/search_in_youtube_video_comments.py b/search_in_youtube_video_comments.py index fb8336b..7a771ca 100644 --- a/search_in_youtube_video_comments.py +++ b/search_in_youtube_video_comments.py @@ -8,26 +8,24 @@ def getContentFromURL(url): data = json.loads(content) return data -VIDEO_ID = '5PdEmeopJVQ' -API_KEY = 'AIzaSy...' -PATTERN_REGEX = '76115293' +VIDEO_ID = input('Video id: ') +API_KEY = input('YouTube Data API v3 (empty if use no-key service): ') +COMMENT_REGEX = input('Comment regex') nextPageToken = '' -pattern = re.compile(PATTERN_REGEX) +commentRegexCompiled = re.compile(COMMENT_REGEX) def treatComment(comment): id = comment['id'] textOriginal = comment['snippet']['textOriginal'] - if pattern.match(textOriginal): + if commentRegexCompiled.match(textOriginal): url = f'https://www.youtube.com/watch?v={VIDEO_ID}&lc={id}' #os.system(f"firefox -new-tab '{url}'") print(f'{url} {textOriginal}') while True: data = getContentFromURL(f'commentThreads?part=snippet,replies&videoId={VIDEO_ID}&maxResults=100&pageToken={nextPageToken}') - #print(data) for item in data['items']: - #print(item) snippet = item['snippet'] totalReplyCount = snippet['totalReplyCount'] if totalReplyCount > 5: