Exemplo n.º 1
0
Arquivo: enbea.py Projeto: rdno/ENBea
    def __init__(self):
        QMainWindow.__init__(self)

        self.ui = Ui_main()
	myWidget = QWidget()
        self.ui.setupUi(myWidget)
	self.setCentralWidget(myWidget)
        self.setWindowTitle("ENBea")
        self._setupEpisodeList()
        self.parser = EpisodeParser()
        self.api_parser = IMDbApiParser()
        self.ui.showProperties.hide()
        self.ui.progressBar.hide()
        self.ui.infoLabel.setText(i18n("Add files"))
        self.ui.nameMask.setText(i18n("%season%episode - %name"))
        self.selectedRows = []
        self.connect_signals()
Exemplo n.º 2
0
Arquivo: enbea.py Projeto: rdno/ENBea
class enbea(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.ui = Ui_main()
	myWidget = QWidget()
        self.ui.setupUi(myWidget)
	self.setCentralWidget(myWidget)
        self.setWindowTitle("ENBea")
        self._setupEpisodeList()
        self.parser = EpisodeParser()
        self.api_parser = IMDbApiParser()
        self.ui.showProperties.hide()
        self.ui.progressBar.hide()
        self.ui.infoLabel.setText(i18n("Add files"))
        self.ui.nameMask.setText(i18n("%season%episode - %name"))
        self.selectedRows = []
        self.connect_signals()
    def connect_signals(self):
        #ui stuff (buttons)
        self.connect(self.ui.addFileBtn,
                     SIGNAL('clicked()'), self.openFileDialog)
        self.connect(self.ui.addFolderBtn,
                     SIGNAL('clicked()'), self.openFolderDialog)
        self.connect(self.ui.renameBtn,
                     SIGNAL('clicked()'), self.renameAll)
        #ui stuff (lineEdits)
        self.connect(self.ui.nameMask,
                     SIGNAL('textEdited(QString)'), self.updateNewNames)
        self.connect(self.ui.showName,
                     SIGNAL('editingFinished()'), self.showInfoChanged)
        self.connect(self.ui.seasonNo,
                     SIGNAL('editingFinished()'), self.showInfoChanged)
        self.connect(self.ui.episodeNo,
                     SIGNAL('editingFinished()'), self.showInfoChanged)
        #Show state signals
        self.connect(self.api_parser, SIGNAL('ShowListUpdated()'),
                     self.showFound)
        self.connect(self.api_parser, SIGNAL('ShowNotFound()'),
                     self.showNotFound)
        #EList download signals
        self.connect(self.api_parser.downloader,
                     SIGNAL('AddedToQueue(QString)'),
                     self.addedToQueue)
        self.connect(self.api_parser.downloader,
                     SIGNAL('downloadStarted(int, QString)'),
                     self.startDownloadProgress)
        self.connect(self.api_parser.downloader,
                     SIGNAL('downloadProgress(int)'),
                     self.updateDownloadProgress)
    def renameAll(self):
        mod = self.model
        for row in range(mod.rowCount()):
            newname = unicode(mod.data(mod.index(row, 1)).toString())
            if newname:
                oldname = unicode(mod.data(mod.index(row, 0)).toString())
                done = rename_file(self.episodeInfos[row]['dir'],
                                oldname, newname)
                if done:
                    self.ui.infoLabel.setText(i18n("Renamed {0} to {1}") \
                                                 % (oldname, newname))
                else:
                    self.ui.infoLabel.setText(i18n("Couldn't renamed %s.") \
                                                  % oldname)
    def addedToQueue(self, show):
        self.ui.infoLabel.setText(i18n("%s list added to download queue.") \
                                      % show)
    def updateDownloadProgress(self, bytes):
        self.ui.progressBar.setValue(bytes)
    def startDownloadProgress(self, total, show):
        self.ui.infoLabel.setText(i18n("Downloading %s episode list") % show)
        self.ui.progressBar.setMinimum(0)
        self.ui.progressBar.setMaximum(total)
        self.ui.progressBar.show()
    def _setupEpisodeList(self):
        self.episodeFiles = []
        self.episodeInfos = []
        self.shows = set()
        self.model = EpisodeTableModel(self.episodeFiles)
        self.ui.episodeList.setModel(self.model)
        self.ui.episodeList.setColumnWidth(0, 200)
        self.ui.episodeList.setColumnWidth(1, 200)
        self.ui.episodeList.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.connect(self.ui.episodeList.selectionModel(),
                SIGNAL('selectionChanged(QItemSelection,QItemSelection)'),
                self.episodeSelected);
        set_drag_and_drop_events(self.ui.episodeList, self.drop)
    def drop(self, event):
        for link in get_links(event.mimeData()):
            if path.isdir(link):
                for video in get_videos(link):
                    self.addFile(video)
            elif is_a_video_file(link):
                self.addFile(link)

    def showInfoChanged(self):
        show = unicode(self.ui.showName.text())
        season = int(self.ui.seasonNo.text())
        episode = int(self.ui.episodeNo.text())
        for row in self.selectedRows:
            self.episodeInfos[row]['show'] = show
            self.api_parser.addShow(show)
            if self.ui.seasonNo.isEnabled():
                self.episodeInfos[row]['season'] = season
                self.episodeInfos[row]['episode'] = episode
        self.updateNewNames()
    def episodeSelected(self):
        indexes = self.ui.episodeList.selectionModel().selectedIndexes()
        if len(indexes) == 2: #one row contains two columns
            row = indexes[0].row()
            self.selectedRows = [row]
            self.ui.showProperties.show()
            self.ui.showName.setDisabled(False)
            self.ui.seasonNo.setDisabled(False)
            self.ui.episodeNo.setDisabled(False)
            self.ui.showName.setPlaceholderText("")
            self.ui.showName.setText(self.episodeInfos[row]['show'])
            self.ui.seasonNo.setText(unicode(self.episodeInfos[row]['season']))
            self.ui.episodeNo.setText(unicode(self.episodeInfos[row]['episode']))
        elif len(indexes) > 2:
            for index in indexes:
                self.selectedRows.append(index.row())
            self.selectRows = set(self.selectedRows)
            firstRow = indexes[0].row()
            self.ui.showProperties.show()
            self.ui.showName.setPlaceholderText(i18n("Multiple Edit is on"))
            self.ui.showName.setText("")
            self.ui.showName.setDisabled(False)
            self.ui.seasonNo.setDisabled(True)
            self.ui.episodeNo.setDisabled(True)
        else:
            self.ui.showProperties.hide()
            self.ui.showName.setText("")
            self.ui.seasonNo.setText("")
            self.ui.episodeNo.setText("")
            self.ui.showName.setPlaceholderText("")
    def addFile(self, fullname):
        info = self.parser.parse(unicode(fullname))
        self.model.add(info['filename'], '')
        self.episodeInfos.append(info)
        if info['show']:
            self.shows.add(info['show'])
            self.api_parser.addShow(info['show'])
    def openFileDialog(self):
        fullnames = QFileDialog.getOpenFileNames(self, i18n("Open file"),
                    '~', filter=get_video_file_filter()
                                + ";;"+i18n("All Files")+" (*)")
        for fullname in fullnames:
            self.addFile(fullname)
    def openFolderDialog(self):
        dirname = QFileDialog.getExistingDirectory(self, i18n("Select folder"),
                                                   '~')
        for video in get_videos(unicode(dirname)):
            self.addFile(video)
    def newname(self, info):
        if info['show'] == '' or info['season'] == 0 or \
                info['episode'] == 0:
            return ""
        episodeName = self.api_parser.getEpisodeName(info)
        if episodeName == '':
            return ""
        name = self.ui.nameMask.text()
        name = name.replace(i18n("%season"),  unicode(info['season']))
        name = name.replace(i18n("%Season"),  unicode(info['season']).zfill(2))
        name = name.replace(i18n("%episode"),  unicode(info['episode']).zfill(2))
        name = name.replace(i18n("%show"),  info['show'])
        name = name.replace(i18n("%name"), episodeName)
        return name + "." + info['extension']
    def showNotFound(self):
        self.ui.progressBar.hide()
        self.ui.infoLabel.setText(i18n("Show list couldn't be parsed"))
    def showFound(self):
        self.ui.progressBar.hide()
        self.ui.infoLabel.setText(i18n("Download Successful!"))
        self.updateNewNames()
    def updateNewNames(self):
        mod = self.model
        for row in range(mod.rowCount()):
            index = mod.index(row, 1)
            mod.setData(index, self.newname(self.episodeInfos[row]))