Fix #2: Add support when not providing YouTube Data API v3 key

This commit is contained in:
Benjamin Loison 2023-04-27 00:16:01 +02:00
parent e19ea59ae4
commit 5288cf9280
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

13
search_in_youtube_video_comments.py Normal file → Executable file
View File

@ -1,16 +1,19 @@
#!/usr/bin/python3
import requests, json, os, re import requests, json, os, re
def getContentFromURL(url): def getContentFromURL(url):
#url = f'https://yt.lemnoslife.com/noKey/{url}' if API_KEY != '':
url = f'https://www.googleapis.com/youtube/v3/{url}&key={API_KEY}' url = f'https://www.googleapis.com/youtube/v3/{url}&key={API_KEY}'
#print(url) else:
url = f'https://yt.lemnoslife.com/noKey/{url}'
content = requests.get(url).text content = requests.get(url).text
data = json.loads(content) data = json.loads(content)
return data return data
VIDEO_ID = input('Video id: ') VIDEO_ID = input('Video id: ')
API_KEY = input('YouTube Data API v3 (empty if use no-key service): ') API_KEY = input('YouTube Data API v3 (empty if use no-key service): ')
COMMENT_REGEX = input('Comment regex') COMMENT_REGEX = input('Comment regex: ')
nextPageToken = '' nextPageToken = ''
commentRegexCompiled = re.compile(COMMENT_REGEX) commentRegexCompiled = re.compile(COMMENT_REGEX)
@ -18,7 +21,7 @@ commentRegexCompiled = re.compile(COMMENT_REGEX)
def treatComment(comment): def treatComment(comment):
id = comment['id'] id = comment['id']
textOriginal = comment['snippet']['textOriginal'] textOriginal = comment['snippet']['textOriginal']
if commentRegexCompiled.match(textOriginal): if commentRegexCompiled.search(textOriginal):
url = f'https://www.youtube.com/watch?v={VIDEO_ID}&lc={id}' url = f'https://www.youtube.com/watch?v={VIDEO_ID}&lc={id}'
#os.system(f"firefox -new-tab '{url}'") #os.system(f"firefox -new-tab '{url}'")
print(f'{url} {textOriginal}') print(f'{url} {textOriginal}')