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 check_filename(self, update, context): """ This method represents the 2° step of the download conversation. It asks the user to insert a valid filename for the video (the filename have to be from 5 to 254 characters of length). This step can be skipped if the config file the "automaticFilename" flag is set True or if the "noDownloadWizard" flag is set at True. """ # Create unique notifier for this user (every update -> different notifier) notifier = Notifier(update, self.BOT) # Get last message sent by the user filename = update.message.text if 4 < len(filename) < 255: # Check with regex if it's a valid filename update.message.reply_text("Shitty name but is okay..") # Save filename self.DOWNLOAD_REQUEST.filename = filename # Pass to another step update.message.reply_text(self.DOWNLOAD_CONFIRMATION) return self.START_DOWNLOAD else: notifier.notify_error( "This name is not valid! The name have a minimum 4 characters and a maximum of 254 characters" ) # Ask again return self.SET_FILE_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 check_download_url(self, update, context): """ This method represents the 1° step of the download conversation. It asks the user to insert the video URL. It will check if the URL is formatted well (validator-like) and if the site is reachable (HTTP GET Request with Reponse Code 200) """ # Create unique notifier for this user (every update -> different notifier) notifier = Notifier(update, self.BOT) # Get last message sent by the user url = update.message.text # Check url if UrlChecker.full_check(url): # Save url self.DOWNLOAD_REQUEST.url = url if self.CONFIG["noDownloadWizard"]: print("[NoWizard] Skip to downloading") # Download file self._download_file(self.DOWNLOAD_REQUEST, update) # End conversation return ConversationHandler.END else: notifier.notify_success("The url is well-formatted and the website is reachable.") # Check if automaticFilename is enabled or not in the config if not self.CONFIG["automaticFilename"]: # Ask for the filename notifier.notify_custom("2️⃣", "Send me a filename") return self.SET_FILE_NAME else: # Go to the download confirmation update.message.reply_text(self.DOWNLOAD_CONFIRMATION) return self.START_DOWNLOAD else: # Ask again notifier.notify_error("The url is not valid or the website is not reachable.") return self.SET_DOWNLOAD_URL