def __handleException(self, exception): t = "An error occurred." m = str(exception) alert = MessageAlert(self, t, m) b = Button("OK", self.__handleErrorOK, Button.SHORTCUT_ENTER) alert.addButton(b) self.beginModalScreen(alert)
def __installSuccessfulMessage(self): title = "Installation successful." msg = "The code has been installed. Please restart the application." a = MessageAlert(self, title, msg) b = Button("OK", self.__abort, Button.SHORTCUT_ENTER) a.addButton(b) self.beginModalScreen(a)
def __updateURLError(self, e): title = "Could not check for newer Youtube DL versions." msg = str(e) a = MessageAlert(self, title, msg) b = Button("Continue", self.__continueApp, Button.SHORTCUT_ENTER) a.addButton(b) b = Button("Abort", self.__abort, "a") a.addButton(b) self.beginModalScreen(a)
def __installError(self, e): title = "Installation failed." msg = "An error occurred while installing the Youtube DL source code: " msg += str(e) a = MessageAlert(self, title, msg) b = Button("Abort", self.__abort, Button.SHORTCUT_ENTER) a.addButton(b) self.beginModalScreen(a)
def __exitApplication(self): title = "Are you sure you want to exit?" msg = "All download processes will be forcefully stopped." a = MessageAlert(self, title, msg) b = Button("Quit", self.__continueExit, Button.SHORTCUT_ENTER) a.addButton(b) b = Button("Cancel", self.__endAlert, 'c') a.addButton(b) self.beginModalScreen(a)
def __versionExtractionError(self, e): title = "Could not check for newer Youtube DL versions." msg = "Could not extract the version of the installed or new " msg += "source code." a = MessageAlert(self, title, msg) b = Button("Continue", self.__endAlert, Button.SHORTCUT_ENTER) a.addButton(b) b = Button("Abort", self.__abort, "a") a.addButton(b) self.beginModalScreen(a)
def __permissionInstallError(self): title = "Installation failed." msg = "Could not install the Youtube DL code because the file " msg += "system could not be accessed. You can try again as root " msg += "or change the installation directory in the configuration " msg += "file." a = MessageAlert(self, title, msg) b = Button("Abort", self.__abort, Button.SHORTCUT_ENTER) a.addButton(b) self.beginModalScreen(a)
def __handleException(self, exception): t = "An error occurred." m = str(exception) alert = MessageAlert(self, t, m) b = Button("OK", self.__handleErrorOK, Button.SHORTCUT_ENTER) alert.addButton(b) if not self.isFirstResponder(): self.__pendingAlert = alert return self.beginModalScreen(alert)
def __youtubeDLNotInstalled(self): title = "Youtube DL source code is not installed." msg = "This application requires source code from " msg += "https://github.com/rg3/youtube-dl. You can install the code " msg += "manually or install it automatically." a = MessageAlert(self, title, msg) b = Button("Automatically", self.__automaticInstall, Button.SHORTCUT_ENTER) a.addButton(b) b = Button("Manually", self.__manualInstall, "m") a.addButton(b) self.beginModalScreen(a)
def __manualInstall(self): title = "Manual installation guide." msg = "Extract the https://github.com/rg3/youtube-dl folder " msg += "somewhere on your file system and point the 'sourcepath' " msg += "option in the configuration file to the folder CONTAINING " msg += "the youtube-dl folder. " msg += "Your configuration file is located at " msg += self.preferences._file a = MessageAlert(self, title, msg) b = Button("OK", self.__abort, Button.SHORTCUT_ENTER) a.addButton(b) self.beginModalScreen(a)
def __handleError(self, title, msg): self.errorAlert = MessageAlert(self.parent, title, msg) b = Button("OK", self.__handleErrorOK, Button.SHORTCUT_ENTER) self.errorAlert.addButton(b) self.parent.beginModalScreen(self.errorAlert)
def __showRemovalConfirmation(self, index, alertParent): with self.__lock: if index >= len(self.queue): return dc = self.queue[index] self.__removalConfiguration = dc title = "Are you sure you want to delete the selected " title+= "download configuration?" msg = "This operation cannot be undone." a = MessageAlert(alertParent, title, msg) b = Button("OK", self.__continueRemoval, Button.SHORTCUT_ENTER) a.addButton(b) b = Button("Cancel", self.__endRemovalConfirmation, 'c') a.addButton(b) self.__removalAlert = a alertParent.beginModalScreen(a)
def handleOK(self): fn = self.__getFinalFilename() if fn == None: t = "Invalid filename." msg = "Please choose a valid filename. The file must " msg+= "be in the current directory and cannot contain " msg+= "any illegal characters." alert = MessageAlert(self, t, msg) b = Button("OK", self.__handleErrorOK, Button.SHORTCUT_ENTER) alert.addButton(b) self.beginModalScreen(alert) return mo = self.mediaObject mf = self.formatBox.selectedFormat() dc = DownloadConfiguration(mo, mf, fn) try: self.doneHandler(dc) except Exception as e: self.__handleException(e)
def __updateYoutubeDL(self): title = "An update of the Youtube DL source code is available." msg = "You can install the application's backend automatically or " msg += "manually, or you can continue to use the current version." a = MessageAlert(self, title, msg) b = Button("Automatically", self.__automaticInstall, Button.SHORTCUT_ENTER) a.addButton(b) b = Button("Manually", self.__manualInstall, "m") a.addButton(b) b = Button("Continue", self.__continueApp, "c") a.addButton(b) self.beginModalScreen(a)
class VideoURLDialog(Alert): CONTENT_HEIGHT = 6 def initialize(self): super(VideoURLDialog, self).initialize() self.textField = TextField(self, (3, 2)) self.addChild(self.textField) self.__progressMessage = None self.addButton(Button("OK", self.handleOK, Button.SHORTCUT_ENTER)) self.addButton(Button("Cancel", self.handleCancel, 'c')) # Drawing def layout(self): super(VideoURLDialog, self).layout() self.textField.size = (1, self.size[1] - 4) def display(self): super(VideoURLDialog, self).display() y, x = self.abs(1, 1) self.addstr(y, x, "Video URL or YouTube hash:") self.__drawProgressMessage() def __drawProgressMessage(self): y, x = self.abs(5, 1) w = (self.size[1] - 4) self.addstr(y, x, ' '*w) if self.__progressMessage != None: y, x = self.abs(5, 1) self.addstr(y, x, self.__progressMessage[:w]) self.refresh() # Events def handleOK(self): self.__handleURL(self.textField.getValue()) def handleCancel(self): self.parent.endModalScreen(self) def __handleURL(self, url): invalidURL = False try: mo = MediaObject(url) mo.delegate = self info = mo.getMediaInformation() if info == None: raise UnsupportedURLError(url) except UnsupportedURLError: invalidURL = True finally: self.__progressMessage = None self.update() if invalidURL == True: t = "Could not extract information." m = "Invalid URL or video hash." self.__handleError(t, m) return # Choose details self.chooseDetailsDialog = ChooseDetailsDialog(self, mo, info) self.chooseDetailsDialog.doneHandler = self.__handleChooseDetailsDone self.beginModalScreen(self.chooseDetailsDialog) def __handleChooseDetailsDone(self, dc): self.parent.addDownloadConfiguration(dc) self.endModalScreen(self.chooseDetailsDialog) self.chooseDetailsDialog = None self.parent.endModalScreen(self) def __handleError(self, title, msg): self.errorAlert = MessageAlert(self.parent, title, msg) b = Button("OK", self.__handleErrorOK, Button.SHORTCUT_ENTER) self.errorAlert.addButton(b) self.parent.beginModalScreen(self.errorAlert) def __handleErrorOK(self): self.parent.endModalScreen(self.errorAlert) # Media Object delegate def mediaObjectMessage(self, msg): self.__progressMessage = msg self.__drawProgressMessage() def mediaObjectError(self, msg): self.__progressMessage = msg self.__drawProgressMessage()