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}')