Make VIDEO_ID
, API_KEY
and COMMENT_REGEX
use stdin
and not hard-coded values
This commit is contained in:
parent
902d2084f1
commit
e19ea59ae4
@ -8,26 +8,24 @@ def getContentFromURL(url):
|
|||||||
data = json.loads(content)
|
data = json.loads(content)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
VIDEO_ID = '5PdEmeopJVQ'
|
VIDEO_ID = input('Video id: ')
|
||||||
API_KEY = 'AIzaSy...'
|
API_KEY = input('YouTube Data API v3 (empty if use no-key service): ')
|
||||||
PATTERN_REGEX = '76115293'
|
COMMENT_REGEX = input('Comment regex')
|
||||||
|
|
||||||
nextPageToken = ''
|
nextPageToken = ''
|
||||||
pattern = re.compile(PATTERN_REGEX)
|
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 pattern.match(textOriginal):
|
if commentRegexCompiled.match(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}')
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
data = getContentFromURL(f'commentThreads?part=snippet,replies&videoId={VIDEO_ID}&maxResults=100&pageToken={nextPageToken}')
|
data = getContentFromURL(f'commentThreads?part=snippet,replies&videoId={VIDEO_ID}&maxResults=100&pageToken={nextPageToken}')
|
||||||
#print(data)
|
|
||||||
for item in data['items']:
|
for item in data['items']:
|
||||||
#print(item)
|
|
||||||
snippet = item['snippet']
|
snippet = item['snippet']
|
||||||
totalReplyCount = snippet['totalReplyCount']
|
totalReplyCount = snippet['totalReplyCount']
|
||||||
if totalReplyCount > 5:
|
if totalReplyCount > 5:
|
||||||
|
Reference in New Issue
Block a user