Skip to content

Commit

Permalink
update style to flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
Nandaka committed Jul 23, 2022
1 parent 1b83d0e commit f12e43f
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .pep8
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[pep8]
ignore = W601,E501,E402,E128,E127,E266,E221,E115
ignore = W601,E501,E402,E128,E127,E266,E221,E115,W503
2 changes: 2 additions & 0 deletions PixivBookmarkHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def export_image_bookmark(caller,
PixivHelper.print_and_log('error', 'Error at export_image_bookmark(): {0}'.format(sys.exc_info()))
raise


def export_image_table(caller, filename, pixiv, fanbox, sketch):
export_list = list()
table = list()
Expand All @@ -330,6 +331,7 @@ def export_image_table(caller, filename, pixiv, fanbox, sketch):
PixivHelper.print_and_log('error', 'Error at export_image_table(): {0}'.format(sys.exc_info()))
raise


def get_bookmarks(caller, config, hide, start_page=1, end_page=0, member_id=None):
br: PixivBrowser = caller.__br__

Expand Down
8 changes: 4 additions & 4 deletions PixivDBManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys
from datetime import datetime

import colorama
# import colorama
from colorama import Back, Fore, Style

import PixivHelper
Expand Down Expand Up @@ -256,15 +256,15 @@ def exportImageTable(self, name):
FROM {table}
ORDER BY member_id''')
for row in c:
im_list.append(row[0])
im_list.append(row[0])
c.close()
print('done.')
return im_list
except BaseException:
print('Error at exportImageTable():', str(sys.exc_info()))
print('failed')
raise

def exportList(self, filename, include_artist_token=True):
print('Exporting list...', end=' ')
try:
Expand Down Expand Up @@ -1346,7 +1346,7 @@ def selectNovelPostByPostId(self, post_id):

def menu(self):
PADDING = 60
print('Pixiv DB Manager Console')
print(Fore.YELLOW + Back.BLACK + Style.BRIGHT + 'Pixiv DB Manager Console' + Style.RESET_ALL)
print(Style.BRIGHT + '── Pixiv '.ljust(PADDING, "─") + Style.RESET_ALL)
print('1. Show all member')
print('2. Show all images')
Expand Down
2 changes: 1 addition & 1 deletion PixivImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def WriteJSON(self, filename, JSONfilter):

def WriteXMP(self, filename):
import pyexiv2
import tempfile
# import tempfile

# need to use temp file due to bad unicode support for pyexiv2 in windows
d = PixivHelper.create_temp_dir(prefix="xmp")
Expand Down
57 changes: 29 additions & 28 deletions PixivImageHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ def process_manga_series(caller,
PixivHelper.print_and_log('error', f'Exception: {sys.exc_info()}')
raise


def process_ugoira_local(caller, config):
directory = config.rootDirectory
counter = 0
Expand All @@ -452,36 +453,36 @@ def process_ugoira_local(caller, config):

try:
print('')
for extension in ["ugoira", "zip"]: # always ugoira then zip
for extension in ["ugoira", "zip"]: # always ugoira then zip
for zip in pathlib.Path(directory).rglob(f'*.{extension}'):
zip_name = os.path.splitext(os.path.basename(zip))[0]
zip_dir = os.path.dirname(zip)
image_id = zip_name.partition("_")[0]
if image_id not in list_done:
counter += 1
PixivHelper.print_and_log(None, f"# Ugoira {counter}")
PixivHelper.print_and_log("info", f"Deleting old animated files ...", newline = False)
PixivHelper.print_and_log("info", "Deleting old animated files ...", newline=False)
d = PixivHelper.create_temp_dir(prefix="reencoding")

# List and move all files related to the image_id
for file in os.listdir(zip_dir):
if os.path.isfile(os.path.join(zip_dir,file)) and zip_name in file:
if os.path.isfile(os.path.join(zip_dir, file)) and zip_name in file:
file_basename = os.path.basename(file)
file_ext = os.path.splitext(file_basename)[1]
if ((("gif" in file_ext) and (config.createGif)) or
(("png" in file_ext) and (config.createApng)) or
(("webm" in file_ext) and (config.createWebm)) or
(("webp" in file_ext) and (config.createWebp)) or
(("ugoira"in file_ext) and (config.createUgoira)) or
("zip" in file_ext)):
abs_file_path = os.path.abspath(os.path.join(zip_dir,file))
if((("gif" in file_ext) and (config.createGif))
or (("png" in file_ext) and (config.createApng))
or (("webm" in file_ext) and (config.createWebm))
or (("webp" in file_ext) and (config.createWebp))
or (("ugoira" in file_ext) and (config.createUgoira))
or ("zip" in file_ext)):
abs_file_path = os.path.abspath(os.path.join(zip_dir, file))
PixivHelper.print_and_log("debug", f"Moving {abs_file_path} to {d}")
if ("zip" in file_ext) or ("ugoira" in file_ext):
shutil.copy2(abs_file_path, os.path.join(d, file_basename))
else:
shutil.move(abs_file_path, os.path.join(d, file_basename))
PixivHelper.print_and_log(None, f" done.")
PixivHelper.print_and_log(None, " done.")

# Process artwork locally
if "ugoira" in extension and not config.overwrite:
try:
Expand All @@ -504,7 +505,7 @@ def process_ugoira_local(caller, config):
PixivHelper.print_and_log('warn', f'Failed to process Image ID {image_id} locally: will retry with online infos')
PixivHelper.print_and_log('debug', f'Removing corrupted ugoira {zip}')
os.remove(zip)

# Process artwork with online infos
if "zip" in extension or res == PixivConstant.PIXIVUTIL_NOT_OK or ("ugoira" in extension and config.overwrite):
res = process_image(caller,
Expand All @@ -514,46 +515,46 @@ def process_ugoira_local(caller, config):
useblacklist=False,
reencoding=True)
if res == PixivConstant.PIXIVUTIL_NOT_OK:
PixivHelper.print_and_log("warn", f"Cannot process Image Id: {image_id}, restoring old animated files...", newline = False)
PixivHelper.print_and_log("warn", f"Cannot process Image Id: {image_id}, restoring old animated files...", newline=False)
for file_name in os.listdir(d):
PixivHelper.print_and_log("debug", f"Moving back {os.path.join(d, file_name)} to {os.path.join(zip_dir, file_name)}")
shutil.move(os.path.join(d, file_name), os.path.join(zip_dir, file_name)) # overwrite corrupted file generated
PixivHelper.print_and_log(None, f" done.")
shutil.move(os.path.join(d, file_name), os.path.join(zip_dir, file_name)) # overwrite corrupted file generated
PixivHelper.print_and_log(None, " done.")
print('')

# Checking result
list_file_zipdir = os.listdir(zip_dir)
for file_name in os.listdir(d):
file_ext = os.path.splitext(file_name)[1]
if file_name not in list_file_zipdir and config.backupOldFile:
if ((config.createUgoira and not config.deleteUgoira and "ugoira" in file_ext) or
(not config.deleteZipFile and "zip" in file_ext) or
(config.createGif and "gif" in file_ext) or
(config.createApng and "png" in file_ext) or
(config.createWebm and "webm" in file_ext) or
(config.createWebp and "webp" in file_ext)):
if((config.createUgoira and not config.deleteUgoira and "ugoira" in file_ext)
or (not config.deleteZipFile and "zip" in file_ext)
or (config.createGif and "gif" in file_ext)
or (config.createApng and "png" in file_ext)
or (config.createWebm and "webm" in file_ext)
or (config.createWebp and "webp" in file_ext)):
split_name = file_name.rsplit(".", 1)
new_name = file_name + "." + str(int(time.time()))
if len(split_name) == 2:
new_name = split_name[0] + "." + str(int(time.time())) + "." + split_name[1]
PixivHelper.print_and_log('warn', f"Could not found the animated file re-encoded ==> {file_name}, backing up to: {new_name}")
PixivHelper.print_and_log('warn', f"The new encoded file may have another name or the artist may have change its name")
PixivHelper.print_and_log('warn', "The new encoded file may have another name or the artist may have change its name.")
PixivHelper.print_and_log("debug", f"Rename and move {os.path.join(d, file_name)} to {os.path.join(zip_dir, new_name)}")
shutil.move(os.path.join(d, file_name), os.path.join(zip_dir, new_name))
print('')

# Delete temp path
if os.path.exists(d) and d != "":
PixivHelper.print_and_log("debug", f"Deleting path {d}")
shutil.rmtree(d)
list_done.append(image_id)
if counter == 0:
PixivHelper.print_and_log('info', "No zip file or ugoira found to re-encode animated files.")

except Exception as ex:
if isinstance(ex, KeyboardInterrupt):
raise
PixivHelper.print_and_log('error', 'Error at process_ugoira_local(): %s' %str(sys.exc_info()))
PixivHelper.print_and_log('error', 'Error at process_ugoira_local(): %s' % str(sys.exc_info()))
PixivHelper.print_and_log('error', 'failed')
raise
finally:
Expand Down
1 change: 1 addition & 0 deletions PixivUtil2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,7 @@ def main_loop(ewd, op_is_valid, selection, np_is_valid_local, args, options):
elif selection == 'u':
menu_ugoira_reencode(op_is_valid, args, options)
elif selection == 'd':
PixivHelper.clearScreen()
__dbManager__.main()
elif selection == 'r':
menu_reload_config()
Expand Down

0 comments on commit f12e43f

Please sign in to comment.