From 5288cf9280494af5a44540dc00804ce47eeb21d7 Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Thu, 27 Apr 2023 00:16:01 +0200 Subject: [PATCH] Fix #2: Add support when not providing YouTube Data API v3 key --- search_in_youtube_video_comments.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) mode change 100644 => 100755 search_in_youtube_video_comments.py diff --git a/search_in_youtube_video_comments.py b/search_in_youtube_video_comments.py old mode 100644 new mode 100755 index 7a771ca..8f12253 --- a/search_in_youtube_video_comments.py +++ b/search_in_youtube_video_comments.py @@ -1,16 +1,19 @@ +#!/usr/bin/python3 + import requests, json, os, re def getContentFromURL(url): - #url = f'https://yt.lemnoslife.com/noKey/{url}' - url = f'https://www.googleapis.com/youtube/v3/{url}&key={API_KEY}' - #print(url) + if API_KEY != '': + url = f'https://www.googleapis.com/youtube/v3/{url}&key={API_KEY}' + else: + url = f'https://yt.lemnoslife.com/noKey/{url}' content = requests.get(url).text data = json.loads(content) return data VIDEO_ID = input('Video id: ') API_KEY = input('YouTube Data API v3 (empty if use no-key service): ') -COMMENT_REGEX = input('Comment regex') +COMMENT_REGEX = input('Comment regex: ') nextPageToken = '' commentRegexCompiled = re.compile(COMMENT_REGEX) @@ -18,7 +21,7 @@ commentRegexCompiled = re.compile(COMMENT_REGEX) def treatComment(comment): id = comment['id'] textOriginal = comment['snippet']['textOriginal'] - if commentRegexCompiled.match(textOriginal): + if commentRegexCompiled.search(textOriginal): url = f'https://www.youtube.com/watch?v={VIDEO_ID}&lc={id}' #os.system(f"firefox -new-tab '{url}'") print(f'{url} {textOriginal}')