def update_count(): global completed_task_num completed_task_num += 1 update_window_title(mode='Download', msg='{0}/{1} {2}%'.format( completed_task_num, total_task_num, int((completed_task_num / total_task_num) * 100)))
async def fetch_image_list(chapter_name, url): with (await sema): logger.debug('Starting fetch chapter page %s => %s', chapter_name, url) async with aiohttp.ClientSession() as session: async with session.get(**utils.generate_aiohttp_session_config(url=url)) as resp: text = await resp.text() logger.debug('Http response code %s => %s', chapter_name, resp.status) jspacker_string = re.search(r'(eval\(.+\))', text).group() jspacker_string = utils.decode_packed_codes(jspacker_string) image_list = re.search(r'(\[.+\])', jspacker_string).group() image_list = urllib.parse.unquote(image_list).replace('\\', '') image_list = json.loads(image_list) image_list_ = [] for u in image_list: image_list_.append(base_url + u) all_image_list.setdefault(chapter_name, image_list_) processing_status['completed'] += 1 update_window_title(mode='Fetching', msg="{0}/{1} {2}%".format( processing_status['completed'], processing_status['total'], int( ( processing_status['completed'] / processing_status['total']) * 100 )) )
def launch_downloader(project_name, urls=dict(), output_path=config.get('output_path')): global proj_dir, total_task_num proj_dir = output_path + '/' + project_name events = [] for k in urls.keys(): for u in urls[k]: logger.debug('create download {file_name}@{chapter_name} => {url}'.format( file_name=get_file_name(u), chapter_name=k, url=u )) events.append(download(u, k)) total_task_num = len(events) if not os.path.exists(proj_dir): os.mkdir(proj_dir) update_window_title(mode='Download') loop = asyncio.get_event_loop() loop.run_until_complete(asyncio.wait(events))
def main(): version.show_welcome() logger.info('App launch') try: logger.debug('Load configure file') config.load_file('config.yml') except Exception as err: logger.warning('Failed to load configure file (%s)', str(err)) if len(sys.argv) > 1: index_page_url = sys.argv[1] else: logger.info('Ask user for enter url') index_page_url = get_comic_index_page_url() logger.info('Fetch chapter list') update_window_title(mode='Fetching') title, chapter_page_list = aio_chapter_list.parse_comic_chapter_list( index_page_url) if len(chapter_page_list) == 0: logger.critical('comic url invalid or no chapter avaliable.') exit() update_window_title(mode='Fetching', msg=title) logger.info('Comic title: %s' % title) logger.info('Fetch each chapter page') list_new = {} list_new = aio_chapter_list.fetch_all_image_list(chapter_page_list) output_path = config.get('output_path') try: if sys.argv[2]: output_path = sys.argv[2] except: pass if not os.path.exists(output_path): os.mkdir(output_path) aiodownloader.launch_downloader(title, list_new, output_path) logger.info('All download complete')
def main(): version.show_welcome() logger.info('App launch') try: logger.debug('Load configure file') config.load_file('config.yml') except Exception as err: logger.warning('Failed to load configure file (%s)', str(err)) if len(sys.argv) > 1: index_page_url = sys.argv[1] else: logger.info('Ask user for enter url') index_page_url = get_comic_index_page_url() logger.info('Fetch chapter list') update_window_title(mode='Fetching') title, chapter_page_list, cover = aio_chapter_list.parse_comic_chapter_list(index_page_url) if len(chapter_page_list) == 0: logger.critical('comic url invalid or no chapter avaliable.') exit() update_window_title(mode='Fetching', msg=title) logger.info('Comic title: %s' % title) logger.info('Fetch each chapter page') list_new = {} list_new = aio_chapter_list.fetch_all_image_list(chapter_page_list) list_new['cover'] = [cover] output_path = config.get('output_path') try: if sys.argv[2]: output_path = sys.argv[2] except: pass if not os.path.exists(output_path): os.mkdir(output_path) aiodownloader.launch_downloader(title, list_new, output_path) logger.info('All download complete') if config.get('epub') == True: logger.info('Making epub...') with jpg2epub.Jpg2Epub(title, file_name=output_path + "/" + title + ".epub", creator="动漫之家") as j2e: coverDir = output_path + "/" + title + "/cover.jpg" j2e.add_image_file(coverDir) def eachFile(filepath): pathDir = os.listdir(filepath) for s in pathDir: newDir=os.path.join(filepath,s) if os.path.isfile(newDir): if newDir != coverDir: if os.path.splitext(newDir)[1]==".jpg": j2e.add_image_file(newDir) pass pass else: eachFile(newDir) eachFile(output_path + "/" + title) logger.info('Done.')
def test_update_window_title(): utils.update_window_title(msg='test')