Пример #1
0
    def bad_series_url_test(self):
        dc = DownloadController()
        r = dc.setSeriesUrl(self.batoto_series_url+"asdfgh")

        self.assertFalse(r)
        self.assertTrue( dc.webpage_model is None )
Пример #2
0
    def download_range_test(self):
        dc = DownloadController()
        dc.setSeriesUrl(self.mangatraders_series_url)
        r = dc.downloadChapterRange(0, 1)

        self.assertFalse(False in r)
Пример #3
0
    def select_url_mangatraders_test(self):
        dc = DownloadController()
        r = dc.setSeriesUrl(self.mangatraders_series_url)

        self.assertTrue(r)
        self.assertTrue( isinstance(dc.webpage_model, MangatradersModel) )
Пример #4
0
    def select_url_batoto_test(self):
        dc = DownloadController()
        r = dc.setSeriesUrl(self.batoto_series_url)

        self.assertTrue(r)
        self.assertTrue( isinstance(dc.webpage_model, BatotoModel) )
Пример #5
0
    def select_url_bad_test(self):
        dc = DownloadController()
        r = dc.setSeriesUrl("http://www.google.com")

        self.assertFalse(r)
        self.assertTrue( dc.webpage_model is None )
Пример #6
0
class DownloaderWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.DownloadPath = os.path.expanduser("~") # get home dir
        self.pool = QThreadPool()
        self.pool.setMaxThreadCount(1)

        self.initVariables()

        self.resize(700, 400)
        self.initUI()

        self.line_downpath.setText(self.down_control.getDownloadPath())

    def initVariables(self):
        self.down_control = DownloadController(self.addInfo)
        self.down_control.setDownloadPath(self.DownloadPath)
        self.chapters = None
        self.chapters_filtered = None
        self.ch_from = None
        self.ch_to = None

    def initUI(self):
        cw = QWidget()
        self.setCentralWidget(cw)
        layout_main = QVBoxLayout()
        layout_main.setSpacing(5)

        ## Info
        self.info = QTextEdit()
        self.info.setReadOnly(True)
        self.info.setLineWrapMode(QTextEdit.NoWrap)

        layout_main.addWidget(self.info, 1)

        ## Line edit
        layout_url = QHBoxLayout()
        layout_url.setSpacing(5)

        self.line_url = QLineEdit()

        layout_url.addWidget(QLabel('<b>Series URL:</b>'))
        layout_url.addWidget(self.line_url, 1)
        layout_main.addLayout(layout_url)

        ## Comboboxes
        layout_combo = QHBoxLayout()
        layout_combo.setSpacing(5)

        self.combo_from = QComboBox()
        self.combo_from.setEnabled(False)
        self.combo_to = QComboBox()
        self.combo_to.setEnabled(False)

        layout_combo.addWidget(QLabel('<b>Download chapters: </b>'))
        layout_combo.addWidget(QLabel(' From:'))
        layout_combo.addWidget(self.combo_from, 1)
        layout_combo.addWidget(QLabel('To:'))
        layout_combo.addWidget(self.combo_to, 1)

        layout_main.addLayout(layout_combo)

        ## Download path
        layout_downpath = QHBoxLayout()
        layout_downpath.setSpacing(5)

        self.line_downpath = QLineEdit()
        self.line_downpath.setEnabled(False)
        self.btn_downpath = QPushButton('Change')
        self.btn_downpath.pressed.connect(self.selectDownloadPath)

        layout_downpath.addWidget(QLabel('<b>Download path:</b>'))
        layout_downpath.addWidget(self.line_downpath, 1)
        layout_downpath.addWidget(self.btn_downpath)
        layout_main.addLayout(layout_downpath)

        ## Buttons
        layout_btn = QHBoxLayout()
        layout_btn.setSpacing(5)

        self.btn_getlist = QPushButton('Get List of Chapters')
        self.btn_getlist.pressed.connect(self.getChaptersList)
        self.btn_download = QPushButton('Download chapters')
        self.btn_download.pressed.connect(self.downloadChapters)
        self.btn_download.setEnabled(False)
        self.btn_exit = QPushButton('Exit')
        self.btn_exit.pressed.connect(self.close)

        layout_btn.addStretch()
        layout_btn.addWidget(self.btn_getlist)
        layout_btn.addWidget(self.btn_download)
        layout_btn.addWidget(self.btn_exit)
        layout_btn.addStretch()
        layout_main.addLayout(layout_btn)

        # status bar
        self.statusBar().showMessage('Ready')

        # add layout to main window
        cw.setLayout(layout_main)
        self.setWindowTitle('OMAD - Online MAnga Downloader')
        self.show()

    def closeEvent(self, event):
        """
        Runs when user tryes to close main window.

        sys.exit(0) - to fix wierd bug, where process is not terminated.
        """
        sys.exit(0)

    def addInfo(self, s='Testing printing...', exception=False, downloadProgress=False, trace=[]):
        logger.info(s+', '+str(exception)+', '+str(downloadProgress)+', '+str(trace))

        if type(s)!=type("") and type(s)!=type(b"") and type(s) != type(QtCore.QString('')):
            s = str(s)

        if exception:
            s = "!!! Exception: "+s

        if downloadProgress:
            s = "Downloading progress: "+s
            self.setStatusBarText(s)

        self.info.append(s)

        if exception:
            for t in trace:
                self.info.append(str(t))

        sb = self.info.verticalScrollBar()
        sb.setValue(sb.maximum())

        QtCore.QCoreApplication.processEvents()

    def setStatusBarText(self, s='Testing...'):
        """
        Changes status bar text
        """
        self.statusBar().showMessage(s)
        QtCore.QCoreApplication.processEvents()

    def getChaptersList(self):
        self.addInfo('Getting list of chapters...')

        # reinit clean variables
        self.initVariables()

        # get series url
        url = str(self.line_url.text()).strip()

        if not self.down_control.setSeriesUrl(url):
            return # bad url

        self.chapters = self.down_control.getChaptersList()

        logger.debug('Setting up comboBoxes...')
        for i in range(0, self.combo_from.count()):
            self.combo_from.removeItem(0)
        for i in range(0, self.combo_to.count()):
            self.combo_to.removeItem(0)

        for c in self.chapters:
            self.combo_from.addItem(c[0])
            self.combo_to.addItem(c[0])

        self.combo_from.setCurrentIndex(0)
        self.combo_to.setCurrentIndex(len(self.chapters)-1)

        self.addInfo('Chapter list loaded')

        self.combo_from.setEnabled(True)
        self.combo_to.setEnabled(True)
        self.btn_download.setEnabled(True)

    def downloadChapters(self):
        self.addInfo('Checking chapter range')

        self.ch_from = self.combo_from.currentIndex()
        self.ch_to = self.combo_to.currentIndex()

        if self.ch_from>self.ch_to:
            self.addInfo('Bad range. Cant download backwards!')
            return
        else:
            self.addInfo('Range OK, starting download of '+str((self.ch_to-self.ch_from)+1)+' chapters...')

        self.gui_disable(True)

        worker = DownloadWorker(self.down_control, self.ch_from, self.ch_to)
        worker.signals.update.connect(self.addInfo)
        worker.signals.finished.connect(self.downloadChapters_finished)
        self.pool.start(worker)

    def downloadChapters_finished(self):
        self.gui_disable(False)
        self.setStatusBarText('Ready - Download Finished!!')

        # Finished
        self.addInfo('Download Finished!!')

        # Print failed downloads
        failed_chs = []
        for i, r in enumerate(self.down_control.results):
            if r is False:
                failed_chs.append(self.chapters[i+self.ch_from])

        if len(failed_chs)==0:
            self.addInfo('\nNo failed downloads')
        else:
            self.addInfo('\nChapters with failed downloads:')
            for c in failed_chs:
                self.addInfo(c[0])
        self.addInfo('')

    def selectDownloadPath(self):
        downdir = self._get_dir(directory=self.DownloadPath)
        self.down_control.setDownloadPath(downdir)
        self.DownloadPath = self.down_control.getDownloadPath()
        self.line_downpath.setText(self.DownloadPath)

    def _get_dir(self, directory=''):
        """
        Draw a dialog for directory selection.
        """

        downdir = QFileDialog.getExistingDirectory(
            caption='Select Folder',
            options=QFileDialog.ShowDirsOnly,
            directory=directory
        )

        if len(downdir) > 0:
            downdir = "%s" % (downdir)
        else:
            downdir = directory

        return downdir

    def gui_disable(self, downloading=True):
        self.line_url.setEnabled(not downloading)
        self.combo_from.setEnabled(not downloading)
        self.combo_to.setEnabled(not downloading)
        self.btn_getlist.setEnabled(not downloading)
        self.btn_download.setEnabled(not downloading)
        self.btn_downpath.setEnabled(not downloading)
Пример #7
0
def nogui(args):
    #test if we have all needed args
    if args.url is None:
        print("--url option is needed in nogui mode!")
        sys.exit(2)
    if args.range is None and args.list is False:
        print("--range (or --list) option is needed in nogui mode!")
        sys.exit(2)

    dc = DownloadController()

    print("Downloading gallery info for: %s" % (args.url, ))

    if not dc.setSeriesUrl(args.url):
        print("Wrong url! Exiting...")
        sys.exit(2)
    chapter_list = dc.getChaptersList()

    # -l --list option, print chapters and exit
    if args.list:
        print("Printing list of chapters...")
        for i in range(len(chapter_list)):
            print("%i - %s" % (i, chapter_list[i][0]))
        print("Exiting...")
        sys.exit(0)

    # test -r --range option
    if args.range is None or len(args.range)!=2:
        print("Incorrect range argument, exiting...")
        sys.exit(2)

    if args.range[1]<0:
        args.range[1] = len(chapter_list)
    else:
        args.range[1] = args.range[1]+1

    try:
        c_range = chapter_list[args.range[0]:args.range[1]]
    except Exception as e:
        print("Bad range! %s" % (e,))
        print("Exiting...")
        sys.exit(2)

    if len(c_range)==0:
        print("Nothing to download, exiting...")
        sys.exit(0)

    # downloading
    print("Starting download of %i chapters..." % (len(c_range),))
    print("from: %s" % (c_range[0][0],))
    print("to: %s" % (c_range[-1][0],))

    dc.downloadChapterRange(args.range[0], args.range[1]-1)
    print("Download Finished!!!")

    # Print failed downloads
    print("\nChapters with failed downloads:")
    for i, r in enumerate(dc.results):
        if r is False:
            print(chapter_list[i+args.range[0]][0])

    sys.exit(0)