def setShow(self, showTitle): """Sets a new show to search for, the old show will be removed """ if showTitle: self.show = Show(showTitle) self.show.proper_title = utils.prepare_title(showTitle.lower()) self.show.title = showTitle else: raise ValueError("Empty show title passed to set show")
def __init__(self, showTitle="", cache=None): """ Proper title is used for the database/url while the display title is used for error messages/display purposes""" self.show = Show(showTitle) self.cache = cache
class ShowFinder(object): """The main parser will poll the internet as well as a database looking for the show by using the parseData() function""" def __init__(self, showTitle="", cache=None): """ Proper title is used for the database/url while the display title is used for error messages/display purposes""" self.show = Show(showTitle) self.cache = cache def setShow(self, showTitle): """Sets a new show to search for, the old show will be removed """ if showTitle: self.show = Show(showTitle) self.show.proper_title = utils.prepare_title(showTitle.lower()) self.show.title = showTitle else: raise ValueError("Empty show title passed to set show") def getShow(self): """ The main driver function of this class, it will poll the database first, if the show doesn't exist it will then try the internet. """ if not self.show.title: return None if self.cache: self.show.add_episodes(self._parseCacheData()) # The show was found in the database if self.show.episodes: logging.info("Show found in database") return self.show # The show was not in the database so now we try the website logging.info("Show not found in database, polling web") self.show.add_episodes(self._parseHTMLData()) if not self.show.episodes: logging.error("Show was not found, check spelling and try again") return self.show # If we successfully find the show from the internet then # we should add it to our database for later use if self.cache: logging.info("Adding show to the database") self.cache.add_show(self.show.proper_title, self.show.episodes, self.show.specials) return self.show def _parseCacheData(self): """The query should return a positive show id otherwise it's not in the database""" return self.cache.get_episodes(self.show.proper_title) def _parseHTMLData(self): """ Passes the sites contents through the regex to seperate episode information such as name, episode number, and title. After getting the data from the regex we will occupy the episode list """ return poll_sources.locate_show(self.show.title)
def __init__(self, parent=None): super(Form, self).__init__(parent) self.epLine = QtGui.QLineEdit() self.findShowBtn = QtGui.QPushButton("&Find Show") self.episode_list = QtGui.QListWidget() self.fmtLine = QtGui.QLineEdit() self.filterBox = QtGui.QGroupBox() self.seasonBox = QtGui.QComboBox(self) self.typeBox = QtGui.QComboBox(self) self.seasonBox.addItem("All Seasons") self.typeBox.addItem("All Types") self.typeBox.addItem("Episodes Only") self.typeBox.addItem("Specials Only") self.findDirBtn = QtGui.QPushButton("&Find Dir") self.dirList = QtGui.QListWidget() self.renameBtn = QtGui.QPushButton("&Rename") # Connect our signals self.epLine.returnPressed.connect(self.findShow) self.findDirBtn.clicked.connect(self.displayDirDialog) self.findShowBtn.clicked.connect(self.findShow) self.renameBtn.clicked.connect(self.displayRenameDialog) self.fmtLine.editingFinished.connect(self.updateFormat) self.seasonBox.activated[str].connect(self.filterSeasons) self.typeBox.activated[str].connect(self.filterType) # Prepare the display update signals self.updater = UpdateDisplaySignal() self.updater.update_directory.connect(self.updateDirectoryListing) self.updater.update_episodes.connect(self.updateEpisodeListing) # Stack the combo boxes into a horizontal line layout = QtGui.QHBoxLayout() layout.addWidget(self.seasonBox) layout.addWidget(self.typeBox) layout.addStretch(0) self.filterBox.setFlat(True) self.filterBox.setLayout(layout) #Set the left layout leftWidget = QtGui.QWidget() stackedWidget = QtGui.QWidget() topLayout = QtGui.QVBoxLayout() vertLayout = QtGui.QFormLayout() vertLayout.addRow("&Search for show", self.epLine) vertLayout.addRow("&Episode Format", self.fmtLine) vertLayout.addRow("&Filter by", self.filterBox) stackedWidget.setLayout(vertLayout) topLayout.addWidget(stackedWidget) topLayout.addWidget(self.episode_list) topLayout.addWidget(self.findShowBtn) leftWidget.setLayout(topLayout) #Set the right layout label = QtGui.QLabel("Current Directory") self.currentDirLabel = QtGui.QLabel("<No Directory Selected>") label.setBuddy(self.currentDirLabel) rightWidget = QtGui.QWidget() rightLayout = QtGui.QVBoxLayout() rightLayout.addWidget(label) rightLayout.addWidget(self.currentDirLabel) rightLayout.addWidget(self.findDirBtn) rightLayout.addWidget(self.dirList) rightLayout.addWidget(self.renameBtn) rightWidget.setLayout(rightLayout) #Connect the left widget and right widget displayBox = QtGui.QHBoxLayout() displayBox.addWidget(leftWidget) displayBox.addWidget(rightWidget) self.setLayout(displayBox) self.show = Show("") self.renameDir = "" self.episodes = [] self.formatter = EpisodeFormatter(self.show) self.show.formatter = self.formatter self.fmtLine.setText(self.show.formatter.format_string)
class Form(QtGui.QWidget): def __init__(self, parent=None): super(Form, self).__init__(parent) self.epLine = QtGui.QLineEdit() self.findShowBtn = QtGui.QPushButton("&Find Show") self.episode_list = QtGui.QListWidget() self.fmtLine = QtGui.QLineEdit() self.filterBox = QtGui.QGroupBox() self.seasonBox = QtGui.QComboBox(self) self.typeBox = QtGui.QComboBox(self) self.seasonBox.addItem("All Seasons") self.typeBox.addItem("All Types") self.typeBox.addItem("Episodes Only") self.typeBox.addItem("Specials Only") self.findDirBtn = QtGui.QPushButton("&Find Dir") self.dirList = QtGui.QListWidget() self.renameBtn = QtGui.QPushButton("&Rename") # Connect our signals self.epLine.returnPressed.connect(self.findShow) self.findDirBtn.clicked.connect(self.displayDirDialog) self.findShowBtn.clicked.connect(self.findShow) self.renameBtn.clicked.connect(self.displayRenameDialog) self.fmtLine.editingFinished.connect(self.updateFormat) self.seasonBox.activated[str].connect(self.filterSeasons) self.typeBox.activated[str].connect(self.filterType) # Prepare the display update signals self.updater = UpdateDisplaySignal() self.updater.update_directory.connect(self.updateDirectoryListing) self.updater.update_episodes.connect(self.updateEpisodeListing) # Stack the combo boxes into a horizontal line layout = QtGui.QHBoxLayout() layout.addWidget(self.seasonBox) layout.addWidget(self.typeBox) layout.addStretch(0) self.filterBox.setFlat(True) self.filterBox.setLayout(layout) #Set the left layout leftWidget = QtGui.QWidget() stackedWidget = QtGui.QWidget() topLayout = QtGui.QVBoxLayout() vertLayout = QtGui.QFormLayout() vertLayout.addRow("&Search for show", self.epLine) vertLayout.addRow("&Episode Format", self.fmtLine) vertLayout.addRow("&Filter by", self.filterBox) stackedWidget.setLayout(vertLayout) topLayout.addWidget(stackedWidget) topLayout.addWidget(self.episode_list) topLayout.addWidget(self.findShowBtn) leftWidget.setLayout(topLayout) #Set the right layout label = QtGui.QLabel("Current Directory") self.currentDirLabel = QtGui.QLabel("<No Directory Selected>") label.setBuddy(self.currentDirLabel) rightWidget = QtGui.QWidget() rightLayout = QtGui.QVBoxLayout() rightLayout.addWidget(label) rightLayout.addWidget(self.currentDirLabel) rightLayout.addWidget(self.findDirBtn) rightLayout.addWidget(self.dirList) rightLayout.addWidget(self.renameBtn) rightWidget.setLayout(rightLayout) #Connect the left widget and right widget displayBox = QtGui.QHBoxLayout() displayBox.addWidget(leftWidget) displayBox.addWidget(rightWidget) self.setLayout(displayBox) self.show = Show("") self.renameDir = "" self.episodes = [] self.formatter = EpisodeFormatter(self.show) self.show.formatter = self.formatter self.fmtLine.setText(self.show.formatter.format_string) def updateDirectoryListing(self): if not self.epLine.text().strip(): self.epLine.setText(os.path.split(self.renameDir)[1]) self.currentDirLabel.setText(os.path.abspath(self.renameDir)) self.dirList.clear() for ep in utils.clean_filenames(self.renameDir): self.dirList.addItem(ep.name) def updateEpisodeListing(self): if not self.episodes: InfoMessage(self, "Find Show", "Unable to find show, check spelling and try again") return self.episode_list.clear() for ep in self.episodes: self.episode_list.addItem(self.show.formatter.display(ep)) def filterType(self, text): if 'all' in text.lower(): self.episodes = self.show.episodes + self.show.specials elif 'episodes' in text.lower(): self.episodes = self.show.episodes else: self.episodes = self.show.specials self.updater.update_episodes.emit() def filterSeasons(self, text): if 'all' in text.lower(): self.episodes = self.show.episodes + self.show.specials self.updater.update_episodes.emit() else: season = int(text) self.episodes = self.show.get_season(season) self.updater.update_episodes.emit() def updateFormat(self): if self.fmtLine.text() != '': self.formatter.format_string = self.fmtLine.text() if self.show.title != "": self.updater.update_episodes.emit() def findShow(self): showTitle = utils.remove_punctuation(self.epLine.text().strip()) if not showTitle: InfoMessage(self, "Find Show", "No show specified") return Settings.title = showTitle show_locater.setShow(showTitle) self.show = show_locater.getShow() self.formatter.show = self.show self.show.formatter = self.formatter self.episodes = self.show.episodes + self.show.specials self.seasonBox.clear() self.seasonBox.addItem("All Seasons") if self.episodes: for s in xrange(self.show.num_seasons): self.seasonBox.addItem(str(s + 1)) self.updater.update_episodes.emit() def displayDirDialog(self): newDir = QtGui.QFileDialog.getExistingDirectory(self, 'Choose Directory', r'G:\TV\Misc') if newDir: self.renameDir = newDir self.dirList.clear() self.updater.update_directory.emit() def displayRenameDialog(self): if not self.renameDir: InfoMessage(self, "Rename Files", "No Directory Selected") return if not self.episode_list.count(): InfoMessage(self, "Rename Files", "No Show Information Retrieved") return files = utils.prepare_filenames(self.renameDir, self.show) dialog = RenameDialog(files, self) dialog.finished.connect(self.updateDirectoryListing) dialog.exec_() self.updater.update_directory.emit() def displayUndoRenameDialog(self): items = [] for d in Settings.backup_list: items.append(Settings.backup_list[d]['name']) text, ok = QtGui.QInputDialog.getItem(self, "Select show", "", items, editable=False) if not ok or not text: return items = [] for d in Settings.backup_list: renamed_entry = Settings.backup_list[d] if text == renamed_entry['name']: self.renameDir = d items = renamed_entry['file_list'] break dialog = RenameDialog(items, self) dialog.finished.connect(self.updateDirectoryListing) dialog.exec_() self.updater.update_directory.emit()
class Form(QtGui.QWidget): def __init__(self, parent=None): super(Form, self).__init__(parent) self.epLine = QtGui.QLineEdit() self.findShowBtn = QtGui.QPushButton("&Find Show") self.episode_list = QtGui.QListWidget() self.fmtLine = QtGui.QLineEdit() self.filterBox = QtGui.QGroupBox() self.seasonBox = QtGui.QComboBox(self) self.typeBox = QtGui.QComboBox(self) self.seasonBox.addItem("All Seasons") self.typeBox.addItem("All Types") self.typeBox.addItem("Episodes Only") self.typeBox.addItem("Specials Only") self.findDirBtn = QtGui.QPushButton("&Find Dir") self.dirList = QtGui.QListWidget() self.renameBtn = QtGui.QPushButton("&Rename") # Connect our signals self.epLine.returnPressed.connect(self.findShow) self.findDirBtn.clicked.connect(self.displayDirDialog) self.findShowBtn.clicked.connect(self.findShow) self.renameBtn.clicked.connect(self.displayRenameDialog) self.fmtLine.editingFinished.connect(self.updateFormat) self.seasonBox.activated[str].connect(self.filterSeasons) self.typeBox.activated[str].connect(self.filterType) # Prepare the display update signals self.updater = UpdateDisplaySignal() self.updater.update_directory.connect(self.updateDirectoryListing) self.updater.update_episodes.connect(self.updateEpisodeListing) # Stack the combo boxes into a horizontal line layout = QtGui.QHBoxLayout() layout.addWidget(self.seasonBox) layout.addWidget(self.typeBox) layout.addStretch(0) self.filterBox.setFlat(True) self.filterBox.setLayout(layout) #Set the left layout leftWidget = QtGui.QWidget() stackedWidget = QtGui.QWidget() topLayout = QtGui.QVBoxLayout() vertLayout = QtGui.QFormLayout() vertLayout.addRow("&Search for show", self.epLine) vertLayout.addRow("&Episode Format", self.fmtLine) vertLayout.addRow("&Filter by", self.filterBox) stackedWidget.setLayout(vertLayout) topLayout.addWidget(stackedWidget) topLayout.addWidget(self.episode_list) topLayout.addWidget(self.findShowBtn) leftWidget.setLayout(topLayout) #Set the right layout label = QtGui.QLabel("Current Directory") self.currentDirLabel = QtGui.QLabel("<No Directory Selected>") label.setBuddy(self.currentDirLabel) rightWidget = QtGui.QWidget() rightLayout = QtGui.QVBoxLayout() rightLayout.addWidget(label) rightLayout.addWidget(self.currentDirLabel) rightLayout.addWidget(self.findDirBtn) rightLayout.addWidget(self.dirList) rightLayout.addWidget(self.renameBtn) rightWidget.setLayout(rightLayout) #Connect the left widget and right widget displayBox = QtGui.QHBoxLayout() displayBox.addWidget(leftWidget) displayBox.addWidget(rightWidget) self.setLayout(displayBox) self.show = Show("") self.renameDir = "" self.episodes = [] self.formatter = EpisodeFormatter(self.show) self.show.formatter = self.formatter self.fmtLine.setText(self.show.formatter.format_string) def updateDirectoryListing(self): if not self.epLine.text().strip(): self.epLine.setText(os.path.split(self.renameDir)[1]) self.currentDirLabel.setText(os.path.abspath(self.renameDir)) self.dirList.clear() for ep in utils.clean_filenames(self.renameDir): self.dirList.addItem(ep.name) def updateEpisodeListing(self): if not self.episodes: InfoMessage(self, "Find Show", "Unable to find show, check spelling and try again") return self.episode_list.clear() for ep in self.episodes: self.episode_list.addItem(self.show.formatter.display(ep)) def filterType(self, text): if 'all' in text.lower(): self.episodes = self.show.episodes + self.show.specials elif 'episodes' in text.lower(): self.episodes = self.show.episodes else: self.episodes = self.show.specials self.updater.update_episodes.emit() def filterSeasons(self, text): if 'all' in text.lower(): self.episodes = self.show.episodes + self.show.specials self.updater.update_episodes.emit() else: season = int(text) self.episodes = self.show.get_season(season) self.updater.update_episodes.emit() def updateFormat(self): if self.fmtLine.text() != '': self.formatter.format_string = self.fmtLine.text() if self.show.title != "": self.updater.update_episodes.emit() def findShow(self): showTitle = utils.remove_punctuation(self.epLine.text().strip()) if not showTitle: InfoMessage(self, "Find Show", "No show specified") return Settings.title = showTitle show_locater.setShow(showTitle) self.show = show_locater.getShow() self.formatter.show = self.show self.show.formatter = self.formatter self.episodes = self.show.episodes + self.show.specials self.seasonBox.clear() self.seasonBox.addItem("All Seasons") if self.episodes: for s in xrange(self.show.num_seasons): self.seasonBox.addItem(str(s + 1)) self.updater.update_episodes.emit() def displayDirDialog(self): newDir = QtGui.QFileDialog.getExistingDirectory( self, 'Choose Directory', r'G:\TV\Misc') if newDir: self.renameDir = newDir self.dirList.clear() self.updater.update_directory.emit() def displayRenameDialog(self): if not self.renameDir: InfoMessage(self, "Rename Files", "No Directory Selected") return if not self.episode_list.count(): InfoMessage(self, "Rename Files", "No Show Information Retrieved") return files = utils.prepare_filenames(self.renameDir, self.show) dialog = RenameDialog(files, self) dialog.finished.connect(self.updateDirectoryListing) dialog.exec_() self.updater.update_directory.emit() def displayUndoRenameDialog(self): items = [] for d in Settings.backup_list: items.append(Settings.backup_list[d]['name']) text, ok = QtGui.QInputDialog.getItem(self, "Select show", "", items, editable=False) if not ok or not text: return items = [] for d in Settings.backup_list: renamed_entry = Settings.backup_list[d] if text == renamed_entry['name']: self.renameDir = d items = renamed_entry['file_list'] break dialog = RenameDialog(items, self) dialog.finished.connect(self.updateDirectoryListing) dialog.exec_() self.updater.update_directory.emit()