def handle_members(caller, job, job_name, job_option): member_ids = list() if "member_ids" in job: print("Multi Member IDs") member_ids = job["member_ids"] elif "member_id" in job: member_id = job["member_id"] member_ids.append(member_id) else: print(f"No member_id or member_ids found in {job_name}!") return start_page = 1 if "start_page" in job: start_page = int(job["start_page"]) end_page = 0 if "end_page" in job: end_page = int(job["end_page"]) from_bookmark = False if "from_bookmark" in job: from_bookmark = bool(job["from_bookmark"]) tags = None if "tags" in job and len(job["tags"]) > 0: tags = job["tags"] for member_id in member_ids: PixivArtistHandler.process_member(caller, member_id=member_id, user_dir=job_option.rootDirectory, page=start_page, end_page=end_page, bookmark=from_bookmark, tags=tags, title_prefix=job_name, job_option=job_option)
def process_bookmark(caller, config, hide='n', start_page=1, end_page=0, bookmark_count=-1): br: PixivBrowser = caller.__br__ try: total_list = list() print(f"My Member Id = {br._myId}") if hide != 'o': print("Importing Bookmarks...") total_list.extend( get_bookmarks(caller, config, False, start_page, end_page, br._myId)) if hide != 'n': print("Importing Private Bookmarks...") total_list.extend( get_bookmarks(caller, config, True, start_page, end_page, br._myId)) print(f"Result: {str(len(total_list))} items.") i = 0 current_member = 1 for item in total_list: print("%d/%d\t%f %%" % (i, len(total_list), 100.0 * i / float(len(total_list)))) i += 1 prefix = "[{0} of {1}]".format(current_member, len(total_list)) PixivArtistHandler.process_member(caller, config, item.memberId, user_dir=item.path, title_prefix=prefix, bookmark_count=bookmark_count) current_member = current_member + 1 if len(total_list) > 0: print("%d/%d\t%f %%" % (i, len(total_list), 100.0 * i / float(len(total_list)))) else: print("Cannot find any followed member.") except KeyboardInterrupt: raise except BaseException: PixivHelper.print_and_log( 'error', 'Error at process_bookmark(): {0}'.format(sys.exc_info())) raise
def handle_members(caller, job, job_name, job_option): member_ids = list() if "member_ids" in job: print("Multi Member IDs") member_ids = job["member_ids"] elif "member_id" in job: member_id = job["member_id"] member_ids.append(member_id) else: print(f"No member_id or member_ids found in {job_name}!") return start_page = 1 if "start_page" in job: start_page = int(job["start_page"]) end_page = 0 if "end_page" in job: end_page = int(job["end_page"]) from_bookmark = False if "from_bookmark" in job: from_bookmark = bool(job["from_bookmark"]) tags = None if "tags" in job and len(job["tags"]) > 0: tags = job["tags"] include_sketch = False if "include_sketch" in job and len(job["include_sketch"]) > 0: include_sketch = bool(job["include_sketch"]) for member_id in member_ids: PixivArtistHandler.process_member(caller, job_option.config, member_id=member_id, user_dir=job_option.config.rootDirectory, page=start_page, end_page=end_page, bookmark=from_bookmark, tags=tags, title_prefix=f"{job_name} ") if include_sketch: # fetching artist token... (artist_model, _) = PixivBrowserFactory.getBrowser().getMemberPage(member_id) PixivSketchHandler.process_sketch_artists(caller, job_option.config, artist_model.artistToken, start_page=start_page, end_page=end_page, title_prefix=f"{job_name} ")
def process_pixiv_by_fanbox_id(caller, config, artist_id, start_page=1, end_page=0, tags=None, title_prefix=""): # Implement #1005 config.loadConfig(path=caller.configfile) br = PixivBrowserFactory.getBrowser() caller.set_console_title(title_prefix) artist = br.fanboxGetArtistById(artist_id) PixivArtistHandler.process_member(caller, config, artist.artistId, user_dir='', page=start_page, end_page=end_page, bookmark=False, tags=tags, title_prefix=title_prefix)
def process_list(caller, config, list_file_name=None, tags=None, include_sketch=False): db = caller.__dbManager__ br = caller.__br__ result = None try: # Getting the list if config.processFromDb: PixivHelper.print_and_log('info', 'Processing from database.') if config.dayLastUpdated == 0: result = db.selectAllMember() else: print(f'Select only last {config.dayLastUpdated} days.') result = db.selectMembersByLastDownloadDate( config.dayLastUpdated) else: PixivHelper.print_and_log( 'info', f'Processing from list file: {list_file_name}') result = PixivListItem.parseList(list_file_name, config.rootDirectory) ignore_file_list = "ignore_list.txt" if os.path.exists(ignore_file_list): PixivHelper.print_and_log( 'info', f'Processing ignore list for member: {ignore_file_list}') ignore_list = PixivListItem.parseList(ignore_file_list, config.rootDirectory) for ignore in ignore_list: for item in result: if item.memberId == ignore.memberId: result.remove(item) break PixivHelper.print_and_log('info', f"Found {len(result)} items.") current_member = 1 for item in result: retry_count = 0 while True: try: prefix = f"[{current_member} of {len(result)}] " PixivArtistHandler.process_member(caller, config, item.memberId, user_dir=item.path, tags=tags, title_prefix=prefix) break except KeyboardInterrupt: raise except BaseException as ex: if retry_count > config.retry: PixivHelper.print_and_log( 'error', f'Giving up member_id: {item.memberId} ==> {ex}') break retry_count = retry_count + 1 print( f'Something wrong, retrying after 2 second ({retry_count}) ==> {ex}' ) PixivHelper.print_delay(2) retry_count = 0 while include_sketch: try: # Issue 1007 # fetching artist token... (artist_model, _) = br.getMemberPage(item.memberId) prefix = f"[{current_member} ({item.memberId} - {artist_model.artistToken}) of {len(result)}] " PixivSketchHandler.process_sketch_artists( caller, config, artist_model.artistToken, title_prefix=prefix) break except KeyboardInterrupt: raise except BaseException as ex: if retry_count > config.retry: PixivHelper.print_and_log( 'error', f'Giving up member_id: {item.memberId} when processing PixivSketch ==> {ex}' ) break retry_count = retry_count + 1 print( f'Something wrong, retrying after 2 second ({retry_count}) ==> {ex}' ) PixivHelper.print_delay(2) current_member = current_member + 1 br.clear_history() print(f'done for member id = {item.memberId}.') print('') except Exception as ex: if isinstance(ex, KeyboardInterrupt): raise caller.ERROR_CODE = getattr(ex, 'errorCode', -1) PixivHelper.print_and_log( 'error', f'Error at process_list(): {sys.exc_info()}') print('Failed') raise
def process_list(caller, config, list_file_name=None, tags=None): db = caller.__dbManager__ br = caller.__br__ result = None try: # Getting the list if config.processFromDb: PixivHelper.print_and_log('info', 'Processing from database.') if config.dayLastUpdated == 0: result = db.selectAllMember() else: print('Select only last', config.dayLastUpdated, 'days.') result = db.selectMembersByLastDownloadDate( config.dayLastUpdated) else: PixivHelper.print_and_log( 'info', 'Processing from list file: {0}'.format(list_file_name)) result = PixivListItem.parseList(list_file_name, config.rootDirectory) if os.path.exists("ignore_list.txt"): PixivHelper.print_and_log( 'info', 'Processing ignore list for member: {0}'.format( "ignore_list.txt")) ignore_list = PixivListItem.parseList("ignore_list.txt", config.rootDirectory) for ignore in ignore_list: for item in result: if item.memberId == ignore.memberId: result.remove(item) break PixivHelper.print_and_log('info', f"Found {len(result)} items.") current_member = 1 for item in result: retry_count = 0 while True: try: prefix = "[{0} of {1}] ".format(current_member, len(result)) PixivArtistHandler.process_member(caller, config, item.memberId, user_dir=item.path, tags=tags, title_prefix=prefix) current_member = current_member + 1 break except KeyboardInterrupt: raise except BaseException: if retry_count > config.retry: PixivHelper.print_and_log( 'error', 'Giving up member_id: ' + str(item.memberId)) break retry_count = retry_count + 1 print('Something wrong, retrying after 2 second (', retry_count, ')') time.sleep(2) br.clear_history() print('done.') except Exception as ex: if isinstance(ex, KeyboardInterrupt): raise caller.ERROR_CODE = getattr(ex, 'errorCode', -1) PixivHelper.print_and_log( 'error', 'Error at process_list(): {0}'.format(sys.exc_info())) print('Failed') raise