def thumbnail_set_categories(self, update, context): """ This method represents the 3° step of the thumbnail conversation. It asks the user to insert a list of categories separated by the character selected in the config file (thumbnailArgumentDivider setting). """ notifier = Notifier(update, self.BOT) # Get last message sent by the user msg = update.message.text.strip() # Get categories and set them into the Thumbnail object categories = msg.split(self.CONFIG["thumbnailArgumentDivider"]) self.THUMBNAILS[self.get_user_id(update)].set_categories(categories) notifier.notify_success('I detected {} categories!'.format(len(categories))) print("[Thumbnail] User {} selected {} categories: {}".format( self.get_user_id(update), len(categories), categories )) # Proceed to the next step notifier.notify_information( 'Now tell me the url of the video!'.format( self.CONFIG["thumbnailArgumentDivider"] ) ) return self.SET_URL
def thumbnail_set_video_name(self, update, context): """ This method represents the 1° step of the thumbnail conversation. It asks the user to insert a valid name for the video (the filename have to be from 5 to 254 characters of length). """ notifier = Notifier(update, self.BOT) # Get last message sent by the user msg = update.message.text.strip() print("[Thumbnail] User {} select a message: {}".format( self.get_user_id(update), msg )) if 4 < len(msg) < 255: self.THUMBNAILS[self.get_user_id(update)].set_title(msg) notifier.notify_success("'{}' is a valid video name".format(msg)) notifier.notify_information( "Please, list all the models present in the video (names separated with '{}' ).\ (Example: Sasha Grey;Mia Khalifa;...".format(self.CONFIG["thumbnailArgumentDivider"]) ) return self.SET_MODEL else: # Invalid name detected notifier.notify_error("Invalid name, please try again") return self.SET_VIDEO_NAME
def download(self, update, context): """ This method handles the '/download' command. It start a conversation (3 steps) with the user to determine the URL of the video resource to download and the filename (if set in the config file) """ print("[Bot] Received download command from", self.get_user_id(update)) # Create unique notifier for this user (every update -> different notifier) notifier = Notifier(update, self.BOT) if not self.get_user_id(update) in self.DOWNLOAD_PROCESSES: if self.CONFIG["noDownloadWizard"]: # For fast downloading change automatic filename to true self.CONFIG["automaticFilename"] = True notifier.notify_information("If you wanna abort the download process just type: '/cancel'") else: # Start the download wizard notifier.notify_information("Oh hello! I'm here to guide you inside the downloading wizard!.\ PS: you can exit this wizard any time you want, you have just to type '/cancel'") # Go to the first step notifier.notify_custom("1️", "Send me a video url") return self.SET_DOWNLOAD_URL else: notifier.notify_error("You are downloading already a resource." "Multiple download are currently disabled. Ask the developer for extra information.")
def thumbnail_set_url(self, update, context): """ This method represents the 4° and last step of the thumbnail conversation. It asks the user to insert a valid (well-formatted) and reachable via HTTP GET request URL. The URL will be validated by the UrlChecker class. """ notifier = Notifier(update, self.BOT) checker = UrlChecker() # Get last message sent by the user url = update.message.text.strip() if checker.check_format(url): # Url valid (well-formatted & reachable) notifier.notify_success("The URL is well-formatted.") if checker.check_exists(url): notifier.notify_success("The link is also reachable via HTTP GET requests") else: notifier.notify_warning("The link is not reachable or its response is not valid") self.THUMBNAILS[self.get_user_id(update)].set_video_url(url) print("[Thumbnail] User {} selected a url for the caption: {}".format( self.get_user_id(update), url )) # Send image with caption notifier.notify_information("Generating image with caption...") self._build_thumbnail_message( notifier, self.THUMBNAILS[self.get_user_id(update)], online=self.CONFIG["onlineThumbnail"] ) notifier.notify_success( "Message generated successfully. " "If you don't like it you can type '/thumbnail' again." ) # End conversation return ConversationHandler.END else: # Error detected by checker, retry again with another URL notifier.notify_error( "The url is not well-formatted or is not reachable via HTTP GET requests... Check the URL and try again" ) # Restart to 'set URL' step return self.SET_URL
def thumbnail(self, update, context): """ This method handles the '/thumbnail' command. It start a conversation (4 steps) with the user to determine the name of the video, the models of the video, the video's categories and the video URL. """ notifier = Notifier(update, self.BOT) print("[Thumbnail] Check if user with id {} has downloaded any videos..".format(self.get_user_id(update))) thumbnail = self.THUMBNAILS.get(self.get_user_id(update)) if (thumbnail is None) or (self.get_user_id(update) not in self.THUMBNAILS): print("You have first to upload the video to OpenLoad to access this function..") notifier.notify_warning("You have to download and upload a video on OpenLoad to use this function properly.") return ConversationHandler.END else: notifier.notify_success( "We detected that you have already uploaded a video on OpenLoad so you can start build your caption" ) notifier.notify_warning( "This is a wizard that helps you to generate a nice caption for your thumbnail. " "You can type '/cancel' in any moment to abort the process!" ) if self.CONFIG["onlineThumbnail"]: print("[Thumbnail] User {} has a valid thumbnail URL saved: {}".format( self.get_user_id(update), thumbnail.URL) ) else: print("[Thumbnail] User {} has a valid thumbnail data saved in '{}'".format( self.get_user_id(update), len(thumbnail.IMAGE_LOCAL_PATH)) ) notifier.notify_information("Select a video name. PS: It can't be only spaces!") return self.SET_VIDEO_NAME