-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_visibility.py
73 lines (67 loc) · 2.73 KB
/
check_visibility.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
with open('differences.json', 'r') as file:
video_list = json.load(file)
private_video = ["Private video"]
deleted_video = ["This video has been removed by the uploader", "This video isn't available anymore"]
unlisted_video = ["Unlisted"]
tosd_video = ["This video has been removed for violating YouTube's Terms of Service"]
copyrighted_video = ["This video contains content from", "Video unavailable"]
browser = webdriver.Firefox()
total_results = []
try:
for video in video_list:
videoId = video.get('videoId', '')
title = video.get('title', '')
publishedAt = video.get('publishedAt', '')
url = f"https://www.youtube.com/watch?v={videoId}"
browser.get(url)
wait = WebDriverWait(browser, 1)
print(f"checking visibility of video ID {videoId}")
status = "public"
for phrase in private_video:
try:
element = wait.until(EC.text_to_be_present_in_element((By.TAG_NAME, "body"), phrase))
status = "privated"
break
except TimeoutException:
pass
for phrase in deleted_video:
try:
element = wait.until(EC.text_to_be_present_in_element((By.TAG_NAME, "body"), phrase))
status = "deleted"
break
except TimeoutException:
pass
for phrase in unlisted_video:
try:
element = wait.until(EC.text_to_be_present_in_element((By.TAG_NAME, "body"), phrase))
status = "unlisted"
break
except TimeoutException:
pass
for phrase in tosd_video:
try:
element = wait.until(EC.text_to_be_present_in_element((By.TAG_NAME, "body"), phrase))
status = "tosd"
break
except TimeoutException:
pass
for phrase in copyrighted_video:
try:
element = wait.until(EC.text_to_be_present_in_element((By.TAG_NAME, "body"), phrase))
status = "copyrighted"
break
except TimeoutException:
pass
result = {"videoId": videoId, "title": title, "status": status, "publishedAt": publishedAt}
total_results.append(result)
finally:
browser.quit()
with open('video_visibility.json', 'w') as result_file:
json.dump(total_results, result_file, indent=2)
print("visibility written to video_visibility.json")