Skip to content

Commit

Permalink
Fix (#897)
Browse files Browse the repository at this point in the history
* Update PixivDownloadHandler.py

Changed the return value of `download_image` from given filename/filepath to actual filename/filepath

* Update PixivUtil2.py

Inside `menu_fanbox_download_from_list` and `menu_fanbox_download_by_id`, added logic to deal with `KeyboardInterrupt` during processing artists.

* Update PixivFanboxHandler.py

1. Optimized the logic for FANBOX artists who are suspended on pixiv: if it's member record exists in db, then use that, otherwise FANBOX filename formats would be checked. If they don't contain `%artist%` or `%artistToken%`, procedure would continue, otherwise user would be required to input for either or both of the placeholders.
2. Optimized some tiny UI messages.
  • Loading branch information
bluerthanever authored Jan 20, 2021
1 parent ece620a commit ff1ef48
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
4 changes: 2 additions & 2 deletions PixivDownloadHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ def download_image(caller,
# write to downloaded lists
if caller.start_iv or config.createDownloadLists:
dfile = codecs.open(caller.dfilename, 'a+', encoding='utf-8')
dfile.write(filename + "\n")
dfile.write(filename_save + "\n")
dfile.close()

return (PixivConstant.PIXIVUTIL_OK, filename)
return (PixivConstant.PIXIVUTIL_OK, filename_save)

except urllib.error.HTTPError as httpError:
PixivHelper.print_and_log('error', f'[download_image()] HTTP Error: {httpError} at {url}')
Expand Down
28 changes: 18 additions & 10 deletions PixivFanboxHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,32 @@ def process_fanbox_artist_by_id(caller, config, artist_id, end_page, title_prefi
try:
artist = br.fanboxGetArtistById(artist_id)
except PixivException as pex:
PixivHelper.print_and_log("error", "Error getting FANBOX artist by id: {0} ==> {1}".format(artist_id, pex.message))
PixivHelper.print_and_log("error", f"Error getting FANBOX artist by id: {artist_id} ==> {pex.message}")
if pex.errorCode != PixivException.USER_ID_SUSPENDED:
return
result = caller.__dbManager__.selectMemberByMemberId(artist.artistId)
if not result:
return
artist = br.fanboxGetArtistById(artist_id, for_suspended=True)
artist.artistName = result[1]
artist.artistToken = result[7]
PixivHelper.print_and_log("info", f"Using saved artist name and token from db: {artist.artistName}, {artist.artistToken}")

result = caller.__dbManager__.selectMemberByMemberId(artist.artistId)
if result:
artist.artistName = result[1]
artist.artistToken = result[7]
PixivHelper.print_and_log("info", f"Using saved artist name and token from db: {artist.artistName}, {artist.artistToken}")
else:
formats = f"{config.filenameFormatFanboxCover}{config.filenameFormatFanboxContent}{config.filenameFormatFanboxInfo}"
name_flag = "%artist%" in formats
token_flag = "%member_token%" in formats
if name_flag or token_flag:
PixivHelper.print_and_log("warn", f"Artist name or token found in FANBOX filename formats, but not in db.")
if name_flag:
artist.artistName = input(f"Please input %artist% for {artist_id}: ").strip()
if token_flag:
artist.artistToken = input(f"Please input %member_token% for {artist_id}: ").strip()

current_page = 1
next_url = None
image_count = 1
while True:
PixivHelper.print_and_log("info", "Processing {0}, page {1}".format(artist, current_page))
caller.set_console_title(f"{title_prefix} FANBOX Artist {artist}, page {current_page}")
caller.set_console_title(f"{title_prefix} {artist}, page {current_page}")
try:
posts = br.fanboxGetPostsFromArtist(artist, next_url)
except PixivException as pex:
Expand Down Expand Up @@ -64,7 +72,7 @@ def process_fanbox_artist_by_id(caller, config, artist_id, end_page, title_prefi
PixivHelper.print_and_log("info", "No more post for {0}".format(artist))
break
current_page += 1
if end_page > 0 and current_page > end_page:
if 0 < end_page < current_page:
PixivHelper.print_and_log("info", "Reaching page limit for {0}, limit {1}".format(artist, end_page))
break
next_url = artist.nextUrl
Expand Down
27 changes: 22 additions & 5 deletions PixivUtil2.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,13 @@ def menu_fanbox_download_from_list(op_is_valid, via, args, options):
artist_id,
end_page,
title_prefix=f"{index} of {len(ids)}")
except KeyboardInterrupt:
choice = input("Keyboard Interrupt detected, continue to next artist (Y/N)").rstrip("\r")
if choice.upper() == 'N':
PixivHelper.print_and_log("info", f"Artist id: {artist_id}, processing aborted")
break
else:
continue
except PixivException as pex:
PixivHelper.print_and_log("error", f"Error processing FANBOX Artist in {via_type} list: {artist_id} ==> {pex.message}")

Expand Down Expand Up @@ -800,11 +807,21 @@ def menu_fanbox_download_by_id(op_is_valid, args, options):
PixivHelper.print_and_log('info', f"Member IDs: {member_ids}")

for index, member_id in enumerate(member_ids, start=1):
PixivFanboxHandler.process_fanbox_artist_by_id(sys.modules[__name__],
__config__,
member_id,
end_page,
title_prefix=f"{index} of {len(member_ids)}")
try:
PixivFanboxHandler.process_fanbox_artist_by_id(sys.modules[__name__],
__config__,
member_id,
end_page,
title_prefix=f"{index} of {len(member_ids)}")
except KeyboardInterrupt:
choice = input("Keyboard Interrupt detected, continue to next artist (Y/N)").rstrip("\r")
if choice.upper() == 'N':
PixivHelper.print_and_log("info", f"Artist id: {member_id}, processing aborted")
break
else:
continue
except PixivException as pex:
PixivHelper.print_and_log("error", f"Error processing FANBOX Artist: {member_id} ==> {pex.message}")


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

0 comments on commit ff1ef48

Please sign in to comment.