-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload_video.py
105 lines (74 loc) · 2.94 KB
/
upload_video.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import json
import os
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
def save_cookies(cookies_file: str = "cookies") -> list[dict]:
"""
Get cookies from current website and saves cookies to .json file
"""
# Get cookies from current website
cookies = driver.get_cookies()
# Save cookies to .json file
with open(f"cookies/{cookies_file}.json", 'w') as file:
json.dump(cookies, file, indent=4)
return cookies
def load_cookies(cookies_file: str = "cookies") -> list[dict]:
"""
Get cookies from .json file and load them on current website
"""
# Get cookies from .json file
with open(f"cookies/{cookies_file}.json", 'r') as file:
cookies = json.load(file)
# Load cookies on current website
for cookie in cookies:
driver.add_cookie(cookie)
return cookies
def upload_instagram() -> str:
"""
Upload video to Instagram and returns the URL of the video
"""
pass
def upload_tiktok() -> str:
"""
Upload video to Tiktok and returns the URL of the video
"""
pass
def upload_youtube(input_file: str = "generate_video_output", title: str = "test", article: str = "The quick brown fox jumps over the lazy dog. Lorem Ipsum is simply dummy text of the printing and typesetting industry.", link: str = "https://en.wikipedia.org/wiki/Wikipedia:Today%27s_featured_article/", schedule_date: str | None = None, schedule_time: str | None = None) -> str:
"""
Upload video to YouTube and returns the URL of the video
"""
# Link
driver.get("https://studio.youtube.com")
if "youtube_cookies.json" in os.listdir():
load_cookies("youtube_cookies")
else:
input("Press any key to continue after logging in: ")
save_cookies("youtube_cookies")
# Select upload
driver.find_element(By.ID, "upload-icon").click()
driver.find_element(By.CSS_SELECTOR, "input[type='file']").send_keys(f"media/{input_file}.mp4")
time.sleep(1)
# Input Details page
video_url = driver.find_element(By.CLASS_NAME, "style-scope ytcp-video-info").text
driver.find_elements(By.ID, "textbox")[0].send_keys(title)
driver.find_elements(By.ID, "textbox")[1].send_keys(f"{article}/n/nLink:{link}")
driver.find_element(By.ID, "next-button").click()
time.sleep(1)
# Input Video Elements page
driver.find_element(By.ID, "next-button").click()
time.sleep(1)
# Input Checks page
driver.find_element(By.ID, "next-button").click()
time.sleep(1)
# Input Visibility page
driver.find_element(By.ID, "second-container-expand-button").click()
driver.find_element(By.ID, "input-3").send_keys(schedule_date)
driver.find_element(By.ID, "input-2").send_keys(schedule_time)
driver.find_element(By.ID, "done-button").click()
time.sleep(1)
# Return URL
return video_url
if __name__ == "__main__":
upload_youtube()