Exemple #1
0
    def show_progress_bar(self):
        percent = 0
        is_exits = False
        self.result = None
        progressDialog = QProgressDialog(self.files_list_dialog)
        progressDialog.setAutoReset(True)
        progressDialog.setWindowModality(Qt.WindowModal)
        progressDialog.setMinimumDuration(5)
        progressDialog.setWindowTitle('Downloading')
        progressDialog.setLabelText('Current speed: ')
        progressDialog.setCancelButtonText('Cancel')
        progressDialog.setRange(0, 100)

        while percent < 100 and not is_exits:
            percent = status.get_percent()
            is_exits = status.get_exist()
            if is_exits:
                self.result = 'Files already exists (..•˘_˘•..)'
                progressDialog.close()
                break
            progressDialog.setValue(percent)
            progressDialog.setLabelText('Current speed: ' + str(status.get_speed()))
            QThread.msleep(100)
            if progressDialog.wasCanceled():
                status.set_stop_thread(True)
                self.download_thread.wait()
                mlog.debug('stop the download thread')
                mlog.debug('download_thread.isRunning ' + str(self.download_thread.isRunning()))
                progressDialog.close()
                self.result = 'Paused Σ(っ °Д °;)っ'
                break
    def show_progress_bar(self):
        percent = 0
        is_exits = False
        self.result = None
        progressDialog = QProgressDialog(self.files_list_dialog)
        progressDialog.setAutoReset(True)
        progressDialog.setWindowModality(Qt.WindowModal)
        progressDialog.setMinimumDuration(5)
        progressDialog.setWindowTitle('Downloading')
        progressDialog.setWindowIcon(QIcon(':/res/favicon.ico'))
        progressDialog.setLabelText('Current speed: ')
        progressDialog.setCancelButtonText('Cancel')
        progressDialog.setRange(0, 100)

        while percent < 100 and not is_exits:
            percent = status.get_percent()
            is_exits = status.get_exist()
            if is_exits:
                self.result = 'Files already exists (..•˘_˘•..)'
                progressDialog.close()
                break
            progressDialog.setValue(percent)
            progressDialog.setLabelText('Current speed: ' + str(status.get_speed()))
            QThread.msleep(100)
            if progressDialog.wasCanceled():
                status.set_stop_thread(True)
                self.download_thread.wait()
                mlog.debug('stop the download thread')
                mlog.debug('download_thread.isRunning ' + str(self.download_thread.isRunning()))
                progressDialog.close()
                self.result = 'Paused Σ(っ °Д °;)っ'
                break
    def get_info(self):
        mconfig.set_default()
        self.button_download.setEnabled(False)
        self.urls = (str(self.text_edit_urls.toPlainText())).split(';')
        mlog.debug(self.urls[0])

        self.m_thread = GetVideoInfoThread(self.urls, **mconfig.kwargs)
        self.m_thread.finish_signal.connect(self.finish_get_info)
        self.m_thread.start()
 def finish_get_info(self, ls, can_download):
     mlog.debug('finish_get_info: ' + str(can_download))
     self.button_download.setEnabled(True)
     if can_download:
         self.files_list_dialog = FilesListDialog()
         self.files_list_dialog.update_files_list(ls)
         mconfig.set_urls(self.urls)
     else:
         self.show_msg(QMessageBox.Critical, 'Failed ', 'Can not get the files list (╯°Д°)╯︵ ┻━┻')
Exemple #5
0
    def get_info(self):
        mconfig.set_default()
        self.button_download.setEnabled(False)
        self.urls = (str(self.text_edit_urls.toPlainText())).split(';')
        mlog.debug(self.urls[0])

        self.m_thread = GetVideoInfoThread(self.urls, **mconfig.kwargs)
        self.m_thread.finish_signal.connect(self.finish_get_info)
        self.m_thread.start()
 def set_file_path(self):
     fname = QFileDialog.getExistingDirectory(self.main_window, caption='Select Path', directory='',
                                              options=QFileDialog.ShowDirsOnly)
     if fname:
         mconfig.set_file_path(fname)
         mlog.debug('changed file path to ' + mconfig.get_file_path())
         self.show_msg(QMessageBox.Information, 'Tip', 'Changed file path to:\n' + str(fname))
     else:
         mconfig.set_file_path(mconfig.base_dir)
         self.show_msg(QMessageBox.Information, 'Tip', 'Default file path:\n' + str(mconfig.base_dir))
Exemple #7
0
 def finish_get_info(self, ls, can_download):
     mlog.debug('finish_get_info: ' + str(can_download))
     self.button_download.setEnabled(True)
     if can_download:
         self.files_list_dialog = FilesListDialog()
         self.files_list_dialog.update_files_list(ls)
         mconfig.set_urls(self.urls)
     else:
         # self.show_msg(QMessageBox.Critical, 'Failed ', 'Can not get the files list (╯°Д°)╯︵ ┻━┻')
         self.show_msg(QMessageBox.Critical, 'Failed ', ls)
Exemple #8
0
def m_get_video(urls, **kwargs):
    m_urls = ct.url2http(urls)
    for url in m_urls:
        mlog.debug('start import module')
        m, url = url_to_module(url)
        mlog.debug('import module compelete')
        if m and url:
            m.download(url, **kwargs)
        else:
            raise Exception('bad url')
Exemple #9
0
def m_get_video(urls, **kwargs):
    m_urls = ct.url2http(urls)
    for url in m_urls:
        mlog.debug('start import module')
        m, url = url_to_module(url)
        mlog.debug('import module compelete')
        if m and url:
            m.download(url, **kwargs)
        else:
            raise Exception('bad url')
Exemple #10
0
    def start_download_files(self):
        status.set_default()
        self.push_button_confirm.setEnabled(False)
        option = self.combo_box_options.currentText()
        mconfig.set_file_itag(option)
        mlog.debug('option is ' + option)

        self.download_thread = DownloadThread(mconfig.get_urls(),
                                              **mconfig.kwargs)
        self.download_thread.finish_signal.connect(self.finish_download)
        self.download_thread.start()
        self.show_progress_bar()
Exemple #11
0
    def start_download_files(self):
        status.set_default()
        self.push_button_confirm.setEnabled(False)
        option = self.combo_box_options.currentText()
        mconfig.set_file_itag(option)
        mlog.debug('option is ' + option)

        self.download_thread = DownloadThread(mconfig.get_urls(), **mconfig.kwargs)
        self.download_thread.finish_signal.connect(self.finish_download)
        self.download_thread.start()

        self.show_progress_bar()
Exemple #12
0
 def set_file_path(self):
     fname = QFileDialog.getExistingDirectory(self.main_window, caption='Select Path', directory='',
                                              options=QFileDialog.ShowDirsOnly)
     if fname:
         self.config.setValue(mconfig.file_path, fname)
         self.file_path_label.setText(fname)
         set_file_path(fname)
         mlog.debug('changed file path to ' + mconfig.get_file_path())
     else:
         set_file_path(mconfig.base_dir)
         self.file_path_label.setText(mconfig.base_dir)
         self.config.setValue(mconfig.file_path, mconfig.base_dir)
Exemple #13
0
 def set_file_path(self):
     fname = QFileDialog.getExistingDirectory(
         self.main_window,
         caption='Select Path',
         directory='',
         options=QFileDialog.ShowDirsOnly)
     if fname:
         mconfig.set_file_path(fname)
         mlog.debug('changed file path to ' + mconfig.get_file_path())
         self.show_msg(QMessageBox.Information, 'Tip',
                       'Changed file path to:\n' + str(fname))
     else:
         mconfig.set_file_path(mconfig.base_dir)
         self.show_msg(QMessageBox.Information, 'Tip',
                       'Default file path:\n' + str(mconfig.base_dir))
Exemple #14
0
 def run(self):
     """
     Download the video
     :return: nothing
     """
     is_succeed = False
     try:
         self.kwargs['info_only'] = False
         mlog.debug(mconfig.get_file_itag)
         m_get_video(self.urls, **self.kwargs)
         is_succeed = True
     except Exception as e:
         mlog.exception(e)
         is_succeed = False
     finally:
         self.finish_signal.emit(is_succeed)
Exemple #15
0
 def run(self):
     """
     Download the video
     :return: nothing
     """
     is_succeed = False
     try:
         self.kwargs['info_only'] = False
         mlog.debug(mconfig.get_file_itag)
         download_main(any_download, any_download_playlist, self.urls, **self.kwargs)
         is_succeed = True
     except Exception as e:
         mlog.exception(e)
         is_succeed = False
     finally:
         self.finish_signal.emit(is_succeed)
Exemple #16
0
    def check_for_updates(self):
        try:
            with request.urlopen('https://raw.githubusercontent.com/ingbyr/GUI-YouGet/master/version.json') as f:
                raw_inf = str(f.read())[2:-1]
                mlog.debug(str(f.read())[2:-1])
                remote_inf = json.loads(raw_inf)
                mlog.debug('remote version is ' + remote_inf['version'])
        except Exception as e:
            mlog.exception(e)
            self.show_msg(QMessageBox.Critical, 'Failed', 'Check for updates failed')
            return

        if mconfig.version >= remote_inf['version']:
            self.show_msg(QMessageBox.Information, 'Check for updates', 'No available updates')
        else:
            self.show_msg(QMessageBox.Information, 'Check for updates', 'There is a new version')
            self.do_updates()
Exemple #17
0
    def check_for_updates(self):
        try:
            with request.urlopen('https://raw.githubusercontent.com/ingbyr/GUI-YouGet/master/version.json') as f:
                raw_inf = str(f.read())[2:-1]
                mlog.debug(str(f.read())[2:-1])
                remote_inf = json.loads(raw_inf)
                mlog.debug('remote version is ' + remote_inf['version'])
        except Exception as e:
            mlog.exception(e)
            self.show_msg(QMessageBox.Critical, 'Failed', 'Check for updates failed')
            return

        if mconfig.version >= remote_inf['version']:
            self.show_msg(QMessageBox.Information, 'Check for updates', 'No available updates')
        else:
            self.show_msg(QMessageBox.Information, 'Check for updates', 'There is a new version')
            self.do_updates()
Exemple #18
0
def get_content(url, headers={}, decoded=True):
    """Gets the content of a URL via sending a HTTP GET request.

    Args:
        url: A URL.
        headers: Request headers used by the client.
        decoded: Whether decode the response body using UTF-8 or the charset specified in Content-Type.

    Returns:
        The content as a string.
    """

    mlog.debug('get_content: %s' % url)

    req = request.Request(url, headers=headers)
    if cookies:
        cookies.add_cookie_header(req)
        req.headers.update(req.unredirected_hdrs)

    for i in range(10):
        try:
            response = request.urlopen(req)
            break
        except socket.timeout:
            mlog.debug('request attempt %s timeout' % str(i + 1))

    data = response.read()

    # Handle HTTP compression for gzip and deflate (zlib)
    content_encoding = response.getheader('Content-Encoding')
    if content_encoding == 'gzip':
        data = ungzip(data)
    elif content_encoding == 'deflate':
        data = undeflate(data)

    # Decode the response body
    if decoded:
        charset = match1(response.getheader('Content-Type'),
                         r'charset=([\w-]+)')
        if charset is not None:
            data = data.decode(charset)
        else:
            data = data.decode('utf-8')

    return data
 def run(self):
     """
     Download the video
     :return: nothing
     """
     r_obj.flush()
     is_succeed = False
     try:
         self.kwargs['info_only'] = False
         mlog.debug(mconfig.get_file_itag)
         m_get_video(self.urls, **self.kwargs)
         is_succeed = True
     except Exception:
         for item in sys.exc_info():
             mlog.error(str(item))
             is_succeed = False
     finally:
         self.finish_signal.emit(is_succeed)
Exemple #20
0
def get_content(url, headers={}, decoded=True):
    """Gets the content of a URL via sending a HTTP GET request.

    Args:
        url: A URL.
        headers: Request headers used by the client.
        decoded: Whether decode the response body using UTF-8 or the charset specified in Content-Type.

    Returns:
        The content as a string.
    """

    mlog.debug('get_content: %s' % url)

    req = request.Request(url, headers=headers)
    if cookies:
        cookies.add_cookie_header(req)
        req.headers.update(req.unredirected_hdrs)

    for i in range(10):
        try:
            response = request.urlopen(req)
            break
        except socket.timeout:
            mlog.debug('request attempt %s timeout' % str(i + 1))

    data = response.read()

    # Handle HTTP compression for gzip and deflate (zlib)
    content_encoding = response.getheader('Content-Encoding')
    if content_encoding == 'gzip':
        data = ungzip(data)
    elif content_encoding == 'deflate':
        data = undeflate(data)

    # Decode the response body
    if decoded:
        charset = match1(response.getheader('Content-Type'), r'charset=([\w-]+)')
        if charset is not None:
            data = data.decode(charset)
        else:
            data = data.decode('utf-8')

    return data
Exemple #21
0
    def __init__(self, urls, parent=None, **kwargs):
        super(DownloadThread, self).__init__(parent)
        self.urls = urls
        self.kwargs = kwargs
        self.config = QSettings('config.ini', QSettings.IniFormat)

        if s2b(self.config.value('enable_proxy', 'false')):
            if s2b(self.config.value('is_http_proxy', 'false')):
                m_set_http_proxy(self.config.value('ip', '127.0.0.1'), self.config.value('port', '1080'))
                mlog.debug("enable http proxy")
            if s2b(self.config.value('is_socks_proxy', 'false')):
                m_set_socks_proxy(self.config.value('ip', '127.0.0.1'), self.config.value('port', '1080'))
                mlog.debug("enable socks proxy")
        else:
            mlog.debug('disable the proxy')
            disable_proxy()
 def show_about(self):
     mlog.debug('show about widget')
     self.about_widget = AboutWdiget()
     self.about_widget.about_widget.move(self.qr.topLeft())
     self.about_widget.about_widget.show()
Exemple #23
0
 def show_about(self):
     mlog.debug('show about widget')
     self.about_widget = AboutWdiget()
     self.about_widget.about_widget.move(self.qr.topLeft())
     self.about_widget.about_widget.show()