Skip to content

Commit

Permalink
Implement #1007
Browse files Browse the repository at this point in the history
  • Loading branch information
Nandaka committed Sep 6, 2021
1 parent 031cb49 commit 3f92558
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
14 changes: 14 additions & 0 deletions PixivBatchHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
from copy import deepcopy

import PixivArtistHandler
import PixivBrowserFactory
import PixivConfig
import PixivHelper
import PixivImageHandler
import PixivSketchHandler
import PixivTagsHandler
import PixivUtil2

Expand Down Expand Up @@ -60,6 +62,9 @@ def handle_members(caller, job, job_name, job_option):
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,
Expand All @@ -71,6 +76,15 @@ def handle_members(caller, job, job_name, job_option):
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 handle_images(caller: PixivUtil2, job, job_name, job_option):
Expand Down
13 changes: 12 additions & 1 deletion PixivListHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

import PixivArtistHandler
import PixivHelper
import PixivSketchHandler
import PixivTagsHandler
from PixivListItem import PixivListItem
from PixivTags import PixivTags


def process_list(caller, config, list_file_name=None, tags=None):
def process_list(caller, config, list_file_name=None, tags=None, include_sketch=False):
db = caller.__dbManager__
br = caller.__br__

Expand Down Expand Up @@ -61,6 +62,16 @@ def process_list(caller, config, list_file_name=None, tags=None):
print('Something wrong, retrying after 2 second (', retry_count, ')')
time.sleep(2)

# Issue 1007
if include_sketch:
# fetching artist token...
(artist_model, _) = br.getMemberPage(item.memberId)
prefix = f"[{current_member} ({artist_model.artistToken}) of {len(result)}] "
PixivSketchHandler.process_sketch_artists(caller,
config,
artist_model.artistToken,
title_prefix=prefix)

br.clear_history()
print('done.')
except Exception as ex:
Expand Down
7 changes: 5 additions & 2 deletions PixivSketchHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ def process_sketch_post(caller, config, post_id):
PixivHelper.print_and_log('error', f'Exception: {sys.exc_info()}')


def process_sketch_artists(caller, config, artist_id, start_page=0, end_page=0):
def process_sketch_artists(caller, config, artist_id, start_page=0, end_page=0, title_prefix=None):
config.loadConfig(path=caller.configfile)
br = PixivBrowserFactory.getBrowser()
title_prefix = f"Pixiv Sketch - Processing Artist Id: {artist_id}"
if title_prefix is None:
title_prefix = f"Pixiv Sketch - Processing Artist Id: {artist_id}"
else:
title_prefix = f"{title_prefix} Pixiv Sketch - Processing Artist Id: {artist_id}"
caller.set_console_title(title_prefix)
msg = Fore.YELLOW + Style.NORMAL + f'Processing Artist Id: {artist_id}' + Style.RESET_ALL
PixivHelper.print_and_log(None, msg)
Expand Down
13 changes: 10 additions & 3 deletions PixivUtil2.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ def menu_download_by_member_id(opisvalid, args, options):
__config__,
artist_model.artistToken,
page,
end_page)
end_page,
title_prefix=prefix)

current_member = current_member + 1
except PixivException as ex:
Expand Down Expand Up @@ -456,23 +457,29 @@ def menu_download_from_list(opisvalid, args, options):
__log__.info('Batch mode from list (4).')
global op
global __config__
include_sketch = False

list_file_name = __config__.downloadListDirectory + os.sep + 'list.txt'
tags = None
if opisvalid:
include_sketch = options.include_sketch
list_file_name = get_list_file_from_options(options, list_file_name)
# get one tag from input parameter
if len(args) > 0:
tags = args[0]
else:
test_tags = input('Tag : ').rstrip("\r")
include_sketch_ask = input('Include Pixiv Sketch [y/n]? ').rstrip("\r") or 'n'
if include_sketch_ask.lower() == 'y':
include_sketch = True
if len(test_tags) > 0:
tags = test_tags

PixivListHandler.process_list(sys.modules[__name__],
__config__,
list_file_name,
tags)
list_file_name=list_file_name,
tags=tags,
include_sketch=include_sketch)


def menu_download_from_online_user_bookmark(opisvalid, args, options):
Expand Down

0 comments on commit 3f92558

Please sign in to comment.