-
Notifications
You must be signed in to change notification settings - Fork 0
/
Uploader.py
132 lines (102 loc) · 4.67 KB
/
Uploader.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import time
import logging
import platform, os
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
from pathlib import Path
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from Constant import Constant
class YouTubeUploader:
def __init__(self):
is_mac = False
if not any(os_name in platform.platform() for os_name in ["Windows", "Linux"]):
is_mac = True
profile_path=str(Path.cwd()) + "/profile"
options = Options()
options.add_argument("-profile")
options.add_argument(profile_path)
options.headless = Constant.HEADLESS
self.browser = webdriver.Firefox(options=options,service=Service(GeckoDriverManager().install()))
self.browser.get(Constant.YOUTUBE_URL)
def sleep(self,t):
for i in range(0, t):
time.sleep(1)
print(f"{str(i)} out of {str(t)}", end="\r")
def UPLOADER(self,title: str, description: str, video_path: str):
browser=self.browser
browser.get(Constant.YOUTUBE_URL)
self.sleep(Constant.USER_WAITING_TIME)
browser.get(Constant.YOUTUBE_UPLOAD_URL)
self.sleep(Constant.USER_WAITING_TIME)
absolute_video_path = video_path
browser.find_element(By.XPATH, Constant.INPUT_FILE_VIDEO).send_keys(
absolute_video_path)
#check for Upload Progress
CheckComplete=False
while CheckComplete==False:
checks_summary=browser.find_element(By.XPATH, "/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/ytcp-animatable[2]/div/div[1]/ytcp-video-upload-progress").get_attribute("checks-summary-status-v2")
print(checks_summary)
self.ScreenShot()
if checks_summary=="UPLOAD_CHECKS_DATA_SUMMARY_STATUS_NOT_STARTED":
print(browser.find_element(By.XPATH, "/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/ytcp-animatable[2]/div/div[1]/ytcp-video-upload-progress").text)
elif checks_summary=="UPLOAD_CHECKS_DATA_SUMMARY_STATUS_STARTED":
print(browser.find_element(By.XPATH, "/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/ytcp-animatable[2]/div/div[1]/ytcp-video-upload-progress").text)
elif checks_summary=="UPLOAD_CHECKS_DATA_SUMMARY_STATUS_COMPLETED":
CheckComplete=True
print("checking complete")
else:
print("another status May be error"+ browser.find_element(By.XPATH, "/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/ytcp-animatable[2]/div/div[1]/ytcp-video-upload-progress").text)
break
# CheckComplete=False if checks_summary=="UPLOAD_CHECKS_DATA_SUMMARY_STATUS_NOT_STARTED" else True
time.sleep(3)
#proceed further
self.sleep(30)
title_field, description_field = browser.find_elements(By.ID, Constant.TEXTBOX_ID)
title_field.clear()
title_field.send_keys(title)
self.sleep(5)
description_field.click()
description_field.send_keys(description)
self.sleep(5)
kids_section = browser.find_element(By.NAME, Constant.NOT_MADE_FOR_KIDS_LABEL)
kids_section.location_once_scrolled_into_view
xpath="/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/ytcp-animatable[1]/ytcp-ve/ytcp-video-metadata-editor/div/ytcp-video-metadata-editor-basics/div[5]/ytkc-made-for-kids-select/div[4]/tp-yt-paper-radio-group/tp-yt-paper-radio-button[2]/div[1]/div[1]"
browser.find_element(By.XPATH, xpath).click()
self.sleep(5)
cl=browser.find_element(By.ID, Constant.NEXT_BUTTON)
cl.location_once_scrolled_into_view
cl.click()
self.sleep(5)
browser.find_element(By.ID, Constant.NEXT_BUTTON).click()
self.sleep(5)
browser.find_element(By.ID, Constant.NEXT_BUTTON).click()
self.sleep(10)
cl=browser.find_element(By.XPATH,"/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/ytcp-animatable[1]/ytcp-uploads-review/div[2]/div[1]/ytcp-video-visibility-select/div[2]/tp-yt-paper-radio-group/tp-yt-paper-radio-button[3]/div[1]/div[1]")
cl.click()
self.sleep(10)
done_button = browser.find_element(By.ID, Constant.DONE_BUTTON)
done_button.click()
self.sleep(20)
#get video Url
# el="//*[@id='share-url']"
# url=browser.find_element(By.XPATH, el).text
# print(url)
#close window
# url=browser.find_element(By.ID, "close-icon-button")
# url.click()
#quit browser
browser.quit()
if __name__ == "__main__":
objName = Name()
objName.main()
# title="Unexpected"
# description="r/Unexpected"
# video_path="~/waste/video.mp4"
# url="https://www.reddit.com/r/Unexpected/comments/zt5zdx/one_of_the_best_scene_in_television_history/"
# os.system(f"rm -rf ~/waste/video.mp4 && yt-dlp -o ~/waste/video.mp4 {url}")
# UPLOADER(title, description, video_path)