def shell_select_books(inputs):
    if len(inputs) >= 2:
        Vars.current_book = None
        if Vars.current_bookshelf is not None:
            Vars.current_book = Vars.current_bookshelf.get_book(inputs[1])
            if Vars.current_book is not None:
                response = HbookerAPI.Book.get_info_by_id(Vars.current_book.book_id)
                if response.get('code') == '100000':
                    Vars.current_book = Book(None, response['data']['book_info'])
                else:
                    print(msg.m('failed_get_book_info_index'), inputs[1])
                    return
        if Vars.current_book is None:
            response = HbookerAPI.Book.get_info_by_id(inputs[1])
            if response.get('code') == '100000':
                # print(response['data']['book_info'])
                Vars.current_book = Book(None, response['data']['book_info'])
            else:
                print(msg.m('failed_get_book_info_id'), inputs[1])
                return

        print('《' + Vars.current_book.book_name + '》')
        Vars.current_book.get_division_list()
        Vars.current_book.get_chapter_catalog()
        if len(inputs) < 3:
            Vars.current_book.show_division_list()
            Vars.current_book.show_latest_chapter()
    else:
        if Vars.current_book is not None:
            Vars.current_book.show_chapter_list_order_division()
        elif Vars.current_bookshelf is None:
            print(msg.m('not_picked_shelf'))
        else:
            Vars.current_bookshelf.get_book_list()
            Vars.current_bookshelf.show_book_list()
Exemple #2
0
 def get_division_list(self):
     print(msg.m('get_div'), end='')
     response = HbookerAPI.Book.get_division_list(self.book_id)
     if response.get('code') == '100000':
         self.division_list = response['data']['division_list']
     else:
         print(msg.m('failed_get_div') + str(response))
def shell_login(inputs):
    if len(inputs) == 1 and Vars.cfg.data.get('user_account') is not None and \
            Vars.cfg.data.get('user_password') is not None:
        pass
    elif len(inputs) >= 3:
        Vars.cfg.data['user_account'] = inputs[1]
        Vars.cfg.data['user_password'] = inputs[2]
    else:
        print(msg.m('input_correct_var'))
        return False
    response = HbookerAPI.SignUp.login(Vars.cfg.data['user_account'],
                                       Vars.cfg.data['user_password'])
    if response.get('code') == '100000':
        Vars.cfg.data['reader_name'] = response['data']['reader_info'][
            'reader_name']
        Vars.cfg.data['user_code'] = response['data']['user_code']
        Vars.cfg.data['common_params'] = {
            'login_token': response['data']['login_token'],
            'account': response['data']['reader_info']['account']
        }
        Vars.cfg.save()
        HbookerAPI.set_common_params(Vars.cfg.data['common_params'])
        print(msg.m('login_success_user') + Vars.cfg.data['reader_name'])
        return True
    else:
        # print("response logon: " + str(response))
        print(response.get('tip'))
        return False
def shell_download_book(inputs):
    if len(inputs) > 1:
        shell_select_books(inputs)
    if Vars.current_book is None:
        print(msg.m('not_picked_book'))
        return
    print(msg.m('start_book_dl'))
    Vars.current_book.download_book_multi_thread()
Exemple #5
0
 def show_book_list(self):
     for book in self.BookList:
         print('《', book.book_name, msg.m('show_list_author'),
               book.author_name, msg.m('show_list_book_index'), book.index,
               msg.m('show_list_book_id'), book.book_id)
         print(msg.m('show_list_uptime'), book.last_chapter_info['uptime'],
               msg.m('show_list_last_chap'),
               book.last_chapter_info['chapter_title'], '\n')
     print()
Exemple #6
0
 def show_division_list(self):
     print('\r', end='')
     for division in self.division_list:
         print(
             msg.m('show_div_index') +
             division['division_index'].rjust(3, " ") +
             msg.m('show_div_total') +
             str(len(self.division_chapter_list[
                 division['division_name']])).rjust(4, " ") +
             msg.m('show_div_name') + division['division_name'])
def agreed_read_readme():
    if Vars.cfg.data.get('agreed_to_readme') != 'yes':
        print(msg.m('read_readme'))
        print(msg.m('agree_terms'))

        confirm = get('>').strip()
        if confirm == 'yes':
            Vars.cfg.data['agreed_to_readme'] = 'yes'
            Vars.cfg.save()
        else:
            sys.exit()
def shell_bookshelf(inputs):
    if len(inputs) >= 2:
        if not BookShelfList:
            refresh_bookshelf_list()
        Vars.current_bookshelf = get_bookshelf_by_index(inputs[1])
        if Vars.current_bookshelf is None:
            print(msg.m('input_correct_var'))
        else:
            print(msg.m('picked_shelf_s') + Vars.current_bookshelf.shelf_name + msg.m('picked_shelf_e'))
            Vars.current_bookshelf.get_book_list()
            Vars.current_bookshelf.show_book_list()
    else:
        refresh_bookshelf_list()
def check_in_today_do(check_in_records):
    # UTC+8
    server_time = datetime.datetime.now(
        tz=datetime.timezone.utc) + datetime.timedelta(hours=8)
    print(
        str(server_time.date()) + " " + str(server_time.hour) + ":" +
        str(server_time.minute))
    today = str(server_time.date())
    for record in check_in_records['data']['sign_record_list']:
        if record['date'] == today:
            if record['is_signed'] == '0':
                check_in = HbookerAPI.CheckIn.do_check_in()
                if check_in.get('code') == '100000':
                    print(
                        msg.m('check_in_success_got') +
                        str(check_in['data']['bonus']['exp']) +
                        msg.m('check_in_xp') +
                        str(check_in['data']['bonus']['hlb']) +
                        msg.m('check_in_token') +
                        str(check_in['data']['bonus']['recommend']) +
                        msg.m('check_in_recommend'))
                    return True
                elif check_in.get('code') == '340001':
                    print(msg.m('check_in_no_redo'))
                    return True
                else:
                    print(msg.m('check_in_failed') + str(check_in) + '\n')
                    return False
            else:
                print(msg.m('check_in_already'))
                return True
    # 日期異常,未找本日對應簽到記錄,不進行簽到嘗試
    print(msg.m('check_in_error_day_not_found') + str(check_in_records))
    return False
Exemple #10
0
 def get_chapter_catalog(self):
     print(msg.m('get_chap'))
     self.chapter_list.clear()
     for chapter_list in self.division_list:
         self.chapter_list.extend(chapter_list['chapter_list'])
         self.division_chapter_list[chapter_list['division_name']] = chapter_list['chapter_list']
     print("\r", end="")
def shell_download_shelf(inputs):
    if len(inputs) >= 2:
        shell_bookshelf(inputs)
    if Vars.current_bookshelf is not None:
        for book in Vars.current_bookshelf.BookList:
            shell_download_book(['', book.book_id])
    else:
        print(msg.m('not_picked_shelf'))
def check_in_today():
    if Vars.cfg.data.get('user_account') is None or Vars.cfg.data.get('user_account') == "" \
            or Vars.cfg.data.get('user_password') is None or Vars.cfg.data.get('user_password') == "":
        print(msg.m('not_login_pl_login'))
        return False
    check_in_records = HbookerAPI.CheckIn.get_check_in_records()
    if check_in_records.get('code') == '100000':
        if check_in_today_do(check_in_records):
            return True
        else:
            return False
    elif check_in_records.get('code') == '200001':
        # {'code': '200001', 'tip': '缺少登录必需参数'}
        print(msg.m('not_login_pl_login'))
        return False
    elif check_in_records.get('code') == '200100':
        # {'code': '200100', 'tip': '登录状态过期,请重新登录'}
        print(msg.m('check_in_token_failed'))
        if shell_login(['']):
            print(msg.m('check_in_re_login_retry_check_in'))
            check_in_records = HbookerAPI.CheckIn.get_check_in_records()
            if check_in_records.get('code') == '100000':
                if check_in_today_do(check_in_records):
                    return True
                else:
                    return False
            else:
                print(msg.m('check_in_error_1') + str(check_in_records) + '\n')
                return False
        else:
            print(msg.m('check_in_re_login_failed'))
            return False
    else:
        print(msg.m('check_in_error_2') + str(check_in_records) + '\n')
        return False
def shell_switch_message_charter_set():
    if Vars.cfg.data['interface_traditional_chinese']:
        Vars.cfg.data['interface_traditional_chinese'] = False
        pass
    else:
        Vars.cfg.data['interface_traditional_chinese'] = True
    Vars.cfg.save()
    msg.set_message_lang(Vars.cfg.data['interface_traditional_chinese'])
    print(msg.m('lang'))
Exemple #14
0
 def show_chapter_list_order_division(self):
     for division in self.division_list:
         chapter_order = 1
         print(msg.m('show_chap_list_index'), division['division_index'], ',:', division['division_name'])
         for chapter_info in self.division_chapter_list[division['division_name']]:
             print(' ' + chapter_info['chapter_index'] + ', ' + division['division_index'] + "-" +
                   str(chapter_order) + "-" + str(chapter_info['chapter_id']) + ' ' + division['division_name'] +
                   ':' + chapter_info['chapter_title'])
             chapter_order += 1
 def add_image(self, filename: str, url: str):
     image_path = self.tempdir + '/OEBPS/Images/' + filename
     if os.path.exists(image_path):
         if os.path.getsize(image_path) != 0:
             return
     for retry in range(image_get_retry):
         try:
             urllib.request.urlretrieve(url, image_path, download_progress_reporthook)
             return
         except OSError as e:
             if retry != image_get_retry - 1:
                 print(msg.m('image_dl_rt') + str(retry + 1) + ' / ' + str(image_get_retry) + ', ' + str(e) + '\n' +
                       url)
                 time.sleep(0.5 * retry)
             else:
                 print(msg.m('image_dl_f') + str(e) + '\n' + url)
                 with open(image_path, 'wb'):
                     pass
 def set_cover(self, url: str):
     image_path = self.tempdir + '/OEBPS/Images/' + url[url.rfind('/') + 1:]
     if os.path.exists(image_path):
         if os.path.getsize(image_path) != 0:
             return
     for retry in range(image_get_retry):
         try:
             urllib.request.urlretrieve(url, image_path, download_progress_reporthook)
             copyfile(image_path, self.tempdir + '/OEBPS/Images/cover.jpg')
             return
         except OSError as e:
             if retry != image_get_retry - 1:
                 print(msg.m('cover_dl_rt') + str(retry + 1) + ' / ' + str(image_get_retry) + ', ' + str(e) + '\n' +
                       url)
                 time.sleep(0.5 * retry)
             else:
                 print(msg.m('cover_dl_f') + str(e) + '\n' + url)
                 with open(image_path, 'wb'):
                     pass
def get_app_update_version_info():
    response = (HbookerAPI.CheckAppVersion.get_version())
    if response.get('code') == '100000':
        android_version = response.get('data').get('android_version')
        print(msg.m('app_update_info') + str(response))
        print(msg.m('current_version_var') + HbookerAPI.common_params['app_version'])
        print(msg.m('get_app_version_var') + android_version)

        print(msg.m('confirm_change_version_var'))
        confirm = get('>').strip()
        if confirm == 'yes':
            print('confirm_msg')
            HbookerAPI.common_params['app_version'] = android_version
            Vars.cfg.data['current_app_version'] = android_version
            Vars.cfg.save()
        else:
            print('cancel_msg')
        print(msg.m('current_version_var') + HbookerAPI.common_params['app_version'])
    else:
        print("error response: " + str(response))
Exemple #18
0
 def get_chapter_catalog_get_thread(self, division):
     response = HbookerAPI.Book.get_chapter_update(division['division_id'])
     if response.get('code') == '100000':
         self.get_chapter_catalog_mt_dl_lock.acquire()
         self.chapter_list.extend(response['data']['chapter_list'])
         self.division_chapter_list[
             division['division_name']] = response['data']['chapter_list']
         self.get_chapter_catalog_mt_dl_lock.release()
     else:
         print(
             msg.m('failed_get_chap') + division['division_name'] + ": " +
             str(response))
def refresh_bookshelf_list():
    response = HbookerAPI.BookShelf.get_shelf_list()
    if response.get('code') == '100000':
        BookShelfList.clear()
        for shelf in response['data']['shelf_list']:
            BookShelfList.append(BookShelf(shelf))
    else:
        print(msg.m('error_response') + str(response))
    for shelf in BookShelfList:
        shelf.show_info()
    if len(BookShelfList) == 1:
        shell_bookshelf(['', '1'])
Exemple #20
0
    def download_book_get_chapter(self, chapter_index, chapter_id,
                                  division_index, chapter_order):
        division_name = None
        for division in self.division_list:
            if division['division_index'] == division_index:
                division_name = division['division_name']
        chapter_title = None
        if division_name is not None:
            chapter_title = self.division_chapter_list[division_name][
                chapter_order - 1]['chapter_title']
        f_name = division_index.rjust(4, "0") + '-' + str(chapter_order).rjust(
            6, "0") + '-' + chapter_id
        if os.path.exists(self.epub.tempdir + '/OEBPS/Text/' + f_name +
                          '.xhtml'):
            if os.path.getsize(self.epub.tempdir + '/OEBPS/Text/' + f_name +
                               '.xhtml') == 0:
                # 章節檔案大小為0 重新下載
                print('\r' + chapter_index.rjust(5, "0") + ', ' +
                      division_index.rjust(4, "0") + "-" +
                      str(chapter_order).rjust(6, "0") + "-" +
                      str(chapter_id) + msg.m('dl_0_chap_re_dl') +
                      division_name + ':' + chapter_title + "\n" +
                      str(self.downloaded_count) + ' / ' +
                      str(self.process_finished_count) + " / " +
                      str(len(self.chapter_list)),
                      end=' ')
            else:
                # 章節已經下載過 跳過
                self.add_process_finished_count()
                print('\r' + str(self.downloaded_count) + ' / ' +
                      str(self.process_finished_count) + " / " +
                      str(len(self.chapter_list)),
                      end=' ')
                self.get_chapter_catalog_mt_dl_lock.release()
                return True

        q_item = self.concurrent_download_queue.get()
        response = HbookerAPI.Chapter.get_chapter_command(chapter_id)
        if response.get('code') == '100000':
            chapter_command = response['data']['command']
            response2 = HbookerAPI.Chapter.get_cpt_ifm(chapter_id,
                                                       chapter_command)
            self.concurrent_download_queue.put(q_item)
            if response2.get('code') == '100000' and response2['data'][
                    'chapter_info'].get('chapter_title') is not None:
                if response2['data']['chapter_info']['auth_access'] == '1':
                    content = HbookerAPI.CryptoUtil.decrypt(
                        response2['data']['chapter_info']['txt_content'],
                        chapter_command).decode('utf-8')
                    if content[-1] == '\n':
                        content = content[:-1]
                    content = content.replace('\n', '</p>\r\n<p>')
                    # 下載成功
                    author_say = response2['data']['chapter_info'][
                        'author_say'].replace('\r', '')
                    author_say = author_say.replace('\n', '</p>\r\n<p>')
                    self.epub.add_chapter(
                        chapter_id, division_name,
                        response2['data']['chapter_info']['chapter_title'],
                        '<p>' + content + '</p>\r\n<p>' + author_say + '</p>',
                        division_index, chapter_order)
                    self.add_process_finished_count()
                    self.downloaded_count += 1
                    print('\r' + str(self.downloaded_count) + ' / ' +
                          str(self.process_finished_count) + " / " +
                          str(len(self.chapter_list)),
                          end=' ')
                    self.get_chapter_catalog_mt_dl_lock.release()
                    return True
                else:
                    # 異常狀況,態異常,已訂閱但無法下載。
                    self.add_process_finished_count()
                    print('\r' + chapter_index.rjust(5, "0") + ', ' +
                          division_index.rjust(4, "0") + '-' +
                          str(chapter_order).rjust(6, "0") + '-' + chapter_id +
                          msg.m('dl_error_paid_stat_conflict') +
                          division_name + ':' + chapter_title + "\n" +
                          str(self.downloaded_count) + ' / ' +
                          str(self.process_finished_count) + " / " +
                          str(len(self.chapter_list)),
                          end=' ')
                    self.get_chapter_catalog_mt_dl_lock.release()
                    return False
            else:
                # 章節下載異常,請再次嘗試下載
                with codecs.open(
                        self.epub.tempdir + '/OEBPS/Text/' + f_name + '.xhtml',
                        'w', 'utf-8') as _file:
                    pass
                self.add_process_finished_count()
                print('\r' + chapter_index.rjust(5, "0") + ', ' +
                      division_index.rjust(4, "0") + '-' +
                      str(chapter_order).rjust(6, "0") + '-' + chapter_id +
                      msg.m('dl_error_chap_get_failed_1') + division_name +
                      ':' + chapter_title + "\n" + str(self.downloaded_count) +
                      ' / ' + str(self.process_finished_count) + " / " +
                      str(len(self.chapter_list)),
                      end=' ')
                self.get_chapter_catalog_mt_dl_lock.release()
                return True
        else:
            self.concurrent_download_queue.put(q_item)
            self.add_process_finished_count()
            print('\r' + chapter_index.rjust(5, "0") + ', ' +
                  division_index.rjust(4, "0") + '-' +
                  str(chapter_order).rjust(6, "0") + '-' + chapter_id +
                  msg.m('dl_error_chap_get_failed_2') + division_name + ':' +
                  chapter_title + "\n" + str(self.downloaded_count) + ' / ' +
                  str(self.process_finished_count) + " / " +
                  str(len(self.chapter_list)),
                  end=' ')
            self.get_chapter_catalog_mt_dl_lock.release()
            return False
Exemple #21
0
    def download_book_multi_thread(self):
        self.file_path = Vars.cfg.data['output_dir'] + self.fix_illegal_book_name() + '/' + \
                         self.fix_illegal_book_name() + '.epub '
        self.epub = EpubFile(self.file_path,
                             Vars.cfg.data['cache_dir'] +
                             self.fix_illegal_book_name(),
                             self.book_id,
                             self.book_name,
                             self.author_name,
                             use_old_epub=False)
        self.epub.set_cover(self.cover)
        threads = []
        # for every chapter in order of division
        for division in self.division_list:
            chapter_order = 1
            # print('分卷編號:', division['division_index'], ', 分卷名:', division['division_name'])
            for chapter_info in self.division_chapter_list[
                    division['division_name']]:
                # print("ch_info_index: ", chapter_info['chapter_index'], " ch_info_id", chapter_info['chapter_id'])
                if chapter_info['is_valid'] == '0':
                    # 處理屏蔽章節
                    self.process_finished_count += 1
                    f_name = division['division_index'].rjust(4, "0") + '-' + str(chapter_order).rjust(6, "0") + '-' + \
                        chapter_info['chapter_id']
                    if os.path.exists(self.epub.tempdir + '/OEBPS/Text/' +
                                      f_name + '.xhtml'):
                        if os.path.getsize(self.epub.tempdir + '/OEBPS/Text/' +
                                           f_name + '.xhtml') == 0:
                            # self.add_download_finished_count()
                            print('\r' +
                                  chapter_info['chapter_index'].rjust(5, "0") +
                                  ', ' +
                                  division['division_index'].rjust(4, "0") +
                                  "-" + str(chapter_order).rjust(6, "0") +
                                  "-" + str(chapter_info['chapter_id']) +
                                  msg.m('dl_chap_block_e') +
                                  division['division_name'] + ':' +
                                  chapter_info['chapter_title'] + "\n" +
                                  str(self.downloaded_count) + ' / ' +
                                  str(self.process_finished_count) + " / " +
                                  str(len(self.chapter_list)),
                                  end=' ')
                        else:
                            print('\r' +
                                  chapter_info['chapter_index'].rjust(5, "0") +
                                  ', ' +
                                  division['division_index'].rjust(4, "0") +
                                  "-" + str(chapter_order).rjust(6, "0") +
                                  "-" + str(chapter_info['chapter_id']) +
                                  msg.m('dl_chap_block_c') +
                                  division['division_name'] + ':' +
                                  chapter_info['chapter_title'] + "\n" +
                                  str(self.downloaded_count) + ' / ' +
                                  str(self.process_finished_count) + " / " +
                                  str(len(self.chapter_list)),
                                  end=' ')
                    else:
                        # 如無檔案 建立空檔
                        with codecs.open(
                                self.epub.tempdir + '/OEBPS/Text/' + f_name +
                                '.xhtml', 'w', 'utf-8') as _file:
                            pass
                        print('\r' +
                              chapter_info['chapter_index'].rjust(5, "0") +
                              ', ' + division['division_index'].rjust(4, "0") +
                              "-" + str(chapter_order).rjust(6, "0") + "-" +
                              str(chapter_info['chapter_id']) +
                              msg.m('dl_chap_block_e') +
                              division['division_name'] + ':' +
                              chapter_info['chapter_title'] + "\n" +
                              str(self.downloaded_count) + ' / ' +
                              str(self.process_finished_count) + " / " +
                              str(len(self.chapter_list)),
                              end=' ')

                elif chapter_info['auth_access'] == '0':
                    # 跳過未購買章節
                    self.process_finished_count += 1
                    print('\r' + chapter_info['chapter_index'].rjust(5, "0") +
                          ', ' + division['division_index'].rjust(4, "0") +
                          '-' + str(chapter_order).rjust(6, "0") + '-' +
                          chapter_info['chapter_id'] +
                          msg.m('dl_chap_not_paid') +
                          division['division_name'] + ':' +
                          chapter_info['chapter_title'] + "\n" +
                          str(self.downloaded_count) + ' / ' +
                          str(self.process_finished_count) + " / " +
                          str(len(self.chapter_list)),
                          end=' ')
                else:
                    download_thread = threading.Thread(
                        target=self.download_book_get_chapter,
                        args=(
                            chapter_info['chapter_index'],
                            chapter_info['chapter_id'],
                            division['division_index'],
                            chapter_order,
                        ))
                    threads.append(download_thread)
                    download_thread.start()
                chapter_order += 1
        for thread in threads:
            thread.join()
        print(msg.m('dl_fin'), end='')

        if self.downloaded_count == 0:
            if os.path.exists(self.epub.tempdir + '/OEBPS/Text'):
                text_mod_time = os.path.getmtime(self.epub.tempdir +
                                                 '/OEBPS/Text')
            else:
                text_mod_time = 0
            if os.path.exists(Vars.cfg.data['output_dir'] +
                              self.fix_illegal_book_name() + '/' +
                              self.fix_illegal_book_name() + '.epub'):
                epub_mod_time = os.path.getmtime(Vars.cfg.data['output_dir'] +
                                                 self.fix_illegal_book_name() +
                                                 '/' +
                                                 self.fix_illegal_book_name() +
                                                 '.epub')
            else:
                epub_mod_time = 0
            if text_mod_time >= epub_mod_time:
                print(msg.m('expo_s'), end='')
                if not os.path.isdir(Vars.cfg.data['output_dir'] +
                                     self.fix_illegal_book_name()):
                    os.makedirs(Vars.cfg.data['output_dir'] +
                                self.fix_illegal_book_name())
                self.epub.make_cover_text(self.book_info['book_name'],
                                          self.book_info['author_name'],
                                          self.book_info['description'],
                                          self.book_info['uptime'])
                self.epub.download_book_write_chapter(
                    self.division_chapter_list)
                # self.config.data['book_info'] = self.book_info
                # self.config.data['division_chapter_list'] = self.division_chapter_list
                # self.config.save()
                print(msg.m('expo_e'))
            else:
                print(msg.m('expo_no'))
        else:
            print(msg.m('expo_s'), end='')
            if not os.path.isdir(Vars.cfg.data['output_dir']):
                os.makedirs(Vars.cfg.data['output_dir'])
            if not os.path.isdir(Vars.cfg.data['output_dir'] +
                                 self.fix_illegal_book_name()):
                os.makedirs(Vars.cfg.data['output_dir'] +
                            self.fix_illegal_book_name())
            self.epub.make_cover_text(self.book_info['book_name'],
                                      self.book_info['author_name'],
                                      self.book_info['description'],
                                      self.book_info['uptime'])
            self.epub.download_book_write_chapter(self.division_chapter_list)
            # self.config.data['book_info'] = self.book_info
            # self.config.data['division_chapter_list'] = self.division_chapter_list
            # self.config.save()
            print(msg.m('expo_e'))
        self.process_finished_count = 0
        self.downloaded_count = 0
Exemple #22
0
 def show_info(self):
     print(msg.m('shelf_index'), self.shelf_index, msg.m('shelf_name'),
           self.shelf_name)
def shell():
    if Vars.cfg.data.get('user_code') is not None:
        HbookerAPI.set_common_params(Vars.cfg.data['common_params'])
        if len(sys.argv) > 1:
            if str(sys.argv[1]).startswith('t'):
                if check_in_today():
                    sys.exit()
                else:
                    loop = True
                    inputs = []
            else:
                check_in_today()
                loop = False
                inputs = sys.argv[1:]
        else:
            check_in_today()
            loop = True
            print(msg.m('help_msg'))
            refresh_bookshelf_list()
            inputs = re.split('\\s+', get('>').strip())
    else:
        loop = True
        save = False
        if Vars.cfg.data.get('user_account') is None or Vars.cfg.data.get('user_account') is not str:
            Vars.cfg.data['user_account'] = ""
            save = True
        if Vars.cfg.data.get('user_password') is None or Vars.cfg.data.get('user_password') is not str:
            Vars.cfg.data['user_password'] = ""
            save = True
        if save:
            Vars.cfg.save()
        print(msg.m('help_msg'))
        print(msg.m('not_login_pl_login'))
        if len(sys.argv) > 1:
            inputs = sys.argv[1:]
        else:
            inputs = re.split('\\s+', get('>').strip())
    while True:
        if inputs[0].startswith('q'):
            sys.exit()
        elif inputs[0].startswith('l'):
            shell_login(inputs)
            check_in_today()
        elif inputs[0].startswith('s'):
            shell_bookshelf(inputs)
        elif inputs[0].startswith('b'):
            shell_select_books(inputs)
        elif inputs[0].startswith('ds') or inputs[0].startswith('downloads'):
            shell_download_shelf(inputs)
        elif inputs[0].startswith('d'):
            shell_download_book(inputs)
        elif inputs[0].startswith('u'):
            shell_download_list(inputs)
        elif inputs[0].startswith('t'):
            check_in_today()
        elif inputs[0].startswith('m'):
            shell_switch_message_charter_set()
        elif inputs[0].startswith('version'):
            get_app_update_version_info()
        else:
            print(msg.m('help_msg'))
        if loop is False:
            break
        inputs = re.split('\\s+', get('>').strip())
Exemple #24
0
 def show_latest_chapter(self):
     print(msg.m('show_last_chap_s_index'),
           self.chapter_list[-1]['chapter_index'],
           msg.m('show_last_chap_uptime'), self.last_chapter_info['uptime'],
           msg.m('show_last_chap_name'),
           self.chapter_list[-1]['chapter_title'])
Exemple #25
0
    def download_book_get_chapter(self, chapter_index, chapter_id, division_index, chapter_order):
        division_name = None
        for division in self.division_list:
            if division['division_index'] == division_index:
                division_name = division['division_name']
        chapter_title = None
        if division_name is not None:
            chapter_title = self.division_chapter_list[division_name][chapter_order - 1]['chapter_title']
        f_name = division_index.rjust(4, "0") + '-' + str(chapter_order).rjust(6, "0") + '-' + chapter_id
        if os.path.exists(self.epub.tempdir + '/OEBPS/Text/' + f_name + '.xhtml'):
            if os.path.getsize(self.epub.tempdir + '/OEBPS/Text/' + f_name + '.xhtml') == 0:
                # 章節檔案大小為0 重新下載
                if chapter_title == "该章节未审核通过":
                    print('\r' + chapter_index.rjust(5, "0") + ', ' + division_index.rjust(4, "0") + '-' +
                          str(chapter_order).rjust(6, "0") + '-' + chapter_id + " 分辨屏蔽章節下載: 標題 #1 " +
                          division_name + ':' + chapter_title + "\n" +
                          str(self.downloaded_count) + ' / ' + str(self.process_finished_count) + " / " + str(
                        len(self.chapter_list)), end=' ')
                    return False
                print('\r' + chapter_index.rjust(5, "0") + ', ' + division_index.rjust(4, "0") + "-" +
                      str(chapter_order).rjust(6, "0") + "-" + str(chapter_id) +
                      msg.m('dl_0_chap_re_dl') + division_name + ':' + chapter_title +
                      "\n" + str(self.downloaded_count) + ' / ' + str(self.process_finished_count) + " / " + str(
                    len(self.chapter_list)), end=' ')
            else:
                # 章節已經下載過 跳過
                self.add_process_finished_count()
                if chapter_title == "该章节未审核通过":
                    print('\r' + chapter_index.rjust(5, "0") + ', ' + division_index.rjust(4, "0") + "-" +
                          str(chapter_order).rjust(6, "0") + "-" + chapter_id +
                          msg.m('dl_chap_block_c') + division_name + ':' + chapter_title + " : 分辨屏蔽章節下載: 標題 #2 " +
                          str(self.downloaded_count) + ' / ' + str(self.process_finished_count) + " / " +
                          str(len(self.chapter_list)), end=' ')
                else:
                    print('\r' + str(self.downloaded_count) + ' / ' + str(self.process_finished_count) + " / " + str(
                        len(self.chapter_list)), end=' ')
                self.get_chapter_catalog_mt_dl_lock.release()
                return True

        q_item = self.concurrent_download_queue.get()
        response = HbookerAPI.Chapter.get_chapter_command(chapter_id)
        if response.get('code') == '100000':
            chapter_command = response['data']['command']
            response2 = HbookerAPI.Chapter.get_cpt_ifm(chapter_id, chapter_command)
            self.concurrent_download_queue.put(q_item)
            if response2.get('code') == '100000' and response2['data']['chapter_info'].get('chapter_title') is not None:
                if response2['data']['chapter_info']['auth_access'] == '1':
                    content = HbookerAPI.CryptoUtil.decrypt(response2['data']['chapter_info']['txt_content'],
                                                            chapter_command).decode('utf-8')
                    if content[-1] == '\n':
                        content = content[:-1]
                    content = content.replace('\n', '</p>\r\n<p>')

                    if content == "本章节内容未审核通过                                            " \
                                  "                                                       ":
                        # 分辨屏蔽章節下載 (2021/07/13)
                        print('\r' + chapter_index.rjust(5, "0") + ', ' + division_index.rjust(4, "0") + '-' +
                              str(chapter_order).rjust(6, "0") + '-' + chapter_id + " 分辨屏蔽章節下載: 內容 #3 " +
                              division_name + ':' + chapter_title + "\n" +
                              str(self.downloaded_count) + ' / ' + str(self.process_finished_count) + " / " + str(
                            len(self.chapter_list)), end=' ')
                        with codecs.open(self.epub.tempdir + '/OEBPS/Text/' + f_name + '.xhtml', 'w', 'utf-8') as _file:
                            pass
                        return False
                    if response2['data']['chapter_info']['chapter_title'] == "该章节未审核通过#Ejxt" or \
                            chapter_title == "该章节未审核通过":
                        # 分辨屏蔽章節下載 (2021/07/13)
                        print('\r' + chapter_index.rjust(5, "0") + ', ' + division_index.rjust(4, "0") + '-' +
                              str(chapter_order).rjust(6, "0") + '-' + chapter_id + " 分辨屏蔽章節下載: 標題 #4 " +
                              division_name + ':' + chapter_title + "\n" +
                              str(self.downloaded_count) + ' / ' + str(self.process_finished_count) + " / " + str(
                            len(self.chapter_list)), end=' ')
                        with codecs.open(self.epub.tempdir + '/OEBPS/Text/' + f_name + '.xhtml', 'w', 'utf-8') as _file:
                            pass
                        return False

                    # 下載成功
                    author_say = response2['data']['chapter_info']['author_say'].replace('\r', '')
                    author_say = author_say.replace('\n', '</p>\r\n<p>')
                    # version above 2.9.225 chapter_title from
                    # self.division_chapter_list[division_name][chapter_order - 1]['chapter_title']
                    # and
                    # response2['data']['chapter_info']['chapter_title']
                    # are different
                    # response2['data']['chapter_info']['chapter_title'] has string #[a-zA-Z0-9]{4} ending
                    # print(chapter_title, response2['data']['chapter_info']['chapter_title'])
                    if chapter_title is None or chapter_title == '':
                        print("debug: self.division_chapter_list[division_name][chapter_order - 1]['chapter_title'] "
                              "is None or blank")
                        chapter_title = response2['data']['chapter_info']['chapter_title']
                        # change fail safe, old method
                    self.epub.add_chapter(chapter_id, division_name,
                                          chapter_title, '<p>' + content +
                                          '</p>\r\n<p>' + author_say + '</p>', division_index, chapter_order)
                    self.add_process_finished_count()
                    self.downloaded_count += 1
                    print('\r' + str(self.downloaded_count) + ' / ' + str(self.process_finished_count) + " / " + str(
                        len(self.chapter_list)), end=' ')
                    self.get_chapter_catalog_mt_dl_lock.release()
                    return True
                else:
                    # 異常狀況,態異常,已訂閱但無法下載。
                    self.add_process_finished_count()
                    print('\r' + chapter_index.rjust(5, "0") + ', ' + division_index.rjust(4, "0") + '-' +
                          str(chapter_order).rjust(6, "0") + '-' + chapter_id + msg.m('dl_error_paid_stat_conflict') +
                          division_name + ':' + chapter_title + "\n" +
                          str(self.downloaded_count) + ' / ' + str(self.process_finished_count) + " / " + str(
                        len(self.chapter_list)), end=' ')
                    self.get_chapter_catalog_mt_dl_lock.release()
                    return False
            else:
                # 章節下載異常,請再次嘗試下載
                with codecs.open(self.epub.tempdir + '/OEBPS/Text/' + f_name + '.xhtml', 'w', 'utf-8') as _file:
                    pass
                self.add_process_finished_count()
                print('\r' + chapter_index.rjust(5, "0") + ', ' + division_index.rjust(4, "0") + '-' +
                      str(chapter_order).rjust(6, "0") + '-' + chapter_id +
                      msg.m('dl_error_chap_get_failed_1') + division_name + ':' + chapter_title + "\n" +
                      str(self.downloaded_count) + ' / ' + str(self.process_finished_count) + " / " + str(
                    len(self.chapter_list)), end=' ')
                self.get_chapter_catalog_mt_dl_lock.release()
                return True
        else:
            self.concurrent_download_queue.put(q_item)
            self.add_process_finished_count()
            print('\r' + chapter_index.rjust(5, "0") + ', ' + division_index.rjust(4, "0") + '-' +
                  str(chapter_order).rjust(6, "0") + '-' + chapter_id + msg.m('dl_error_chap_get_failed_2') +
                  division_name + ':' + chapter_title + "\n" +
                  str(self.downloaded_count) + ' / ' + str(self.process_finished_count) + " / " + str(
                len(self.chapter_list)), end=' ')
            self.get_chapter_catalog_mt_dl_lock.release()
            return False