def __init__(self, user): self.bot = Bot().getBot() self.url = "https://www.tiktok.com/upload?lang=en" self.cookies = Cookies() self.userRequest = {"dir": "", "cap": "", "vidTxt": ""} self.video = None self.IO = IO("hashtags.txt") self.videoFormats = ["mov", "flv", "avi"] self.userPreference = user
def directUpload(self, filename, private=False, test=False): if self.bot is None: self.bot = Browser().getBot() self.webbot = Bot(self.bot) self.bot.get(self.url) utils.randomTimeQuery() self.cookies = Cookies(self.bot) self.bot.refresh() try: file_input_element = self.webbot.getVideoUploadInput() except Exception as e: print(f"Error: {e}") print( "Major error, cannot find the file upload button, please update getVideoUploadInput() in Bot.py" ) file_input_element = None exit() abs_path = os.path.join(os.getcwd(), filename) try: file_input_element.send_keys(abs_path) except StaleElementReferenceException as e: try: self.bot.implicitly_wait(5) file_input_element = self.webbot.getVideoUploadInput() file_input_element.send_keys(abs_path) except Exception as e: print( "Major error, cannot find the file upload button, please update getVideoUploadInput() in Bot.py" ) exit() # We need to wait until it is uploaded and then clear input. self.addCaptions() utils.randomTimeQuery() if private: self.webbot.selectPrivateRadio() # private video selection utils.randomTimeQuery() else: """ self.webbot.selectPublicRadio() # public video selection utils.randomTimeQuery() """ pass if not test: self.webbot.uploadButtonClick() # upload button input("Press any button to exit")
def uploadVideo(self, video_dir, videoText, startTime=0, endTime=0, private=True, test=False, scheduled=False, schdate="", schtime=""): video_dir = self.downloadIfYoutubeURL(video_dir) if not video_dir: return if self.bot is None: self.bot = Browser().getBot() self.webbot = Bot(self.bot) self.userRequest["dir"] = video_dir self.checkFileExtensionValid() self.userRequest["cap"] = self.IO.getHashTagsFromFile() # Initiate bot if isn't already. self.bot.get(self.url) self.userRequest["vidTxt"] = videoText # Cookies loaded here. self.cookies = Cookies(self.bot) self.bot.refresh() # User now has logged on and can upload videos time.sleep(3) self.inputVideo(startTime, endTime) self.addCaptions() utils.randomTimeQuery() if private: self.webbot.selectPrivateRadio() # private video selection else: self.webbot.selectPublicRadio() # public video selection utils.randomTimeQuery() if not test: self.webbot.uploadButtonClick() # upload button input("Press any button to exit")
def __init__(self): self.cookies = Cookies()