Fix #2: Add support when not providing YouTube Data API v3 key
This commit is contained in:
parent
e19ea59ae4
commit
5288cf9280
13
search_in_youtube_video_comments.py
Normal file → Executable file
13
search_in_youtube_video_comments.py
Normal file → Executable file
@ -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}')
|
||||
|
Reference in New Issue
Block a user