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 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