-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuploadYTvideo.py
More file actions
61 lines (43 loc) · 2.65 KB
/
uploadYTvideo.py
File metadata and controls
61 lines (43 loc) · 2.65 KB
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
import psutil
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
CHANNEL_ID = "UC1sWMZGSOen46Lmp8D8CEAQ"
UPLOAD_URL = f"https://studio.youtube.com/channel/{CHANNEL_ID}/videos/upload?d=ud"
CHROME_DRIVER_PATH = r'C:\Users\Shai grossman\Downloads\chromedriver-win64\chromedriver-win64\chromedriver.exe'
USER_DATA_PATH = r'C:\Users\Shai grossman\AppData\Local\Google\Chrome\User Data'
def uploadVideo(EXPORTED_VIDEO_PATH, FILE_NAME, FILE_EXTENSION):
print(EXPORTED_VIDEO_PATH)
print(FILE_NAME)
print(FILE_EXTENSION)
# close all chrome instances before launching selenium
for proc in psutil.process_iter(['pid', 'name']):
if proc.info['name'] in ['chrome.exe', 'chromedriver.exe']:
proc.kill()
options = Options()
options.add_argument(fr"--user-data-dir={USER_DATA_PATH}")
options.add_argument("--profile-directory=Default")
driver = webdriver.Chrome(service=Service(CHROME_DRIVER_PATH), options=options)
driver.get(UPLOAD_URL)
driver.implicitly_wait(10)
file_input = driver.find_element(By.XPATH, "//input[@type='file']")
# Send the file path to the file input element
file_input.send_keys(EXPORTED_VIDEO_PATH + FILE_NAME + FILE_EXTENSION)
radio_button = driver.find_element(By.XPATH, "//tp-yt-paper-radio-button[@name='VIDEO_MADE_FOR_KIDS_NOT_MFK']")
radio_button.click()
button = driver.find_element(By.XPATH,
"//button[@class='ytcp-button-shape-impl ytcp-button-shape-impl--filled ytcp-button-shape-impl--mono ytcp-button-shape-impl--size-m' and @aria-label='הבא']")
button.click()
button = driver.find_element(By.XPATH,
"//button[@class='ytcp-button-shape-impl ytcp-button-shape-impl--filled ytcp-button-shape-impl--mono ytcp-button-shape-impl--size-m' and @aria-label='הבא']")
button.click()
button = driver.find_element(By.XPATH,
"//button[@class='ytcp-button-shape-impl ytcp-button-shape-impl--filled ytcp-button-shape-impl--mono ytcp-button-shape-impl--size-m' and @aria-label='הבא']")
button.click()
radio_button = driver.find_element(By.XPATH, "//tp-yt-paper-radio-button[@id='private-radio-button']")
radio_button.click()
button = driver.find_element(By.XPATH,
"//button[@class='ytcp-button-shape-impl ytcp-button-shape-impl--filled ytcp-button-shape-impl--mono ytcp-button-shape-impl--size-m' and @aria-label='שמירה']")
button.click()
input("press enter to close the program")