Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cnwxi committed Aug 28, 2024
1 parent 0b1fef2 commit 55f0102
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 25 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
release:
description: 'Create a new release'
required: true
default: 'true'
default: true
type: boolean
version:
description: 'Release version'
Expand Down Expand Up @@ -52,9 +52,7 @@ jobs:
- name: Build the executables
run: |
pyinstaller --onefile --name decrypt_epub 重构epub并反文件名混淆.py
pyinstaller --onefile --name encrypt_epub 重构epub并加入文件名混淆.py
pyinstaller --onefile --name rebuild_epub 重构epub为规范格式_v2.8.3.py
pyinstaller --onefile --name epub_tool epub_tool.py
- name: Rename artifacts with OS prefix (Linux and macOS)
if: matrix.os != 'windows-latest'
Expand Down
60 changes: 60 additions & 0 deletions epub_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from utils.encrypt_epub import run as encrypt_run
from utils.decrypt_epub import run as decrypt_run
from utils.reformat_epub import run as reformat_run
import sys
import os
import argparse


def prepare_args():
parser = argparse.ArgumentParser(description='Epub Tool')
parser.add_argument('-i', help='input file/folder')
parser.add_argument('-e', action='store_true', help='encrypt epub file')
parser.add_argument('-d', action='store_true', help='decrypt epub file')
parser.add_argument('-r', action='store_true', help='reformat epub file')
return parser.parse_args()

def check_args(args):
if not args.i:
print('Please specify the input file/folder')
sys.exit(1)
if not os.path.exists(args.i):
print('Input file/folder does not exist')
sys.exit(1)
# 判断输入文件是否为文件夹
if os.path.isdir(args.i):
file_list = sorted(os.listdir(args.i))
args.i = [os.path.join(args.i, file) for file in file_list if file.endswith('.epub')]
else:
args.i = [args.i]
for i in args.i:
if not os.path.exists(i):
print('Input file does not exist')
sys.exit(1)
return args


def main():
prepare_args()
args = prepare_args()
args = check_args(args)
if args.e:
func=encrypt_run
elif args.d:
func=decrypt_run
elif args.r:
func=reformat_run
else:
print('Please specify the operation')
sys.exit(1)
tmp_run_result = []
for file in args.i:
if func(file) == 0:
tmp_run_result.append(f'{file} Success')
else:
tmp_run_result.append(f'{file} Fail')
for result in tmp_run_result:
print(result)

if __name__ == '__main__':
main()
12 changes: 3 additions & 9 deletions pyinstallerForMac.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# for mac
pyinstaller -F 重构epub并反文件名混淆.py -n decrypt_epub;
echo "------decrypt_epub finished------";
pyinstaller -F 重构epub并加入文件名混淆.py -n encrypt_epub;
echo "------encrypt_epub finished------";
pyinstaller -F 重构epub为规范格式_v2.8.3.py -n rebuild_epub;
echo "------rebuild_epub finished------";
pyinstaller -F epub_tool.py -n epub_tool;
echo "------finished------";
rm -rf ./build;
rm ./decrypt_epub.spec;
rm ./encrypt_epub.spec;
rm ./rebuild_epub.spec
rm ./epub_tool.spec;
11 changes: 2 additions & 9 deletions pyinstallerForWindows.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
# for windows
pyinstaller -F 重构epub并反文件名混淆.py -n decrypt_epub;
echo "------decrypt_epub finished------";
pyinstaller -F 重构epub并加入文件名混淆.py -n encrypt_epub;
echo "------encrypt_epub finished------";
pyinstaller -F 重构epub为规范格式_v2.8.3.py -n rebuild_epub;
echo "------rebuild_epub finished------";
pyinstaller -F epub_tool.py -n epub_tool;
rm ./build;
rm ./decrypt_epub.spec;
rm ./encrypt_epub.spec;
rm ./rebuild_epub.spec
rm ./epub_tool.spec;
Binary file added utils/__pycache__/decrypt_epub.cpython-312.pyc
Binary file not shown.
Binary file added utils/__pycache__/encrypt_epub.cpython-312.pyc
Binary file not shown.
Binary file added utils/__pycache__/reformat_epub.cpython-312.pyc
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def creatNewHerf(_id, _href):
else:
image_silm=''
new_href = f"{_id_name}{image_silm}.{_id_extension.lower()}"
print(f"unmixed href: {_id}:{_href} -> {new_href}")
print(f"decrypt href: {_id}:{_href} -> {new_href}")
return new_href
############################################################
for id, href, mime, properties in self.manifest_list:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ def creatNewHerf(_id, _href):
new_href = f"_{new_href}{image_slim}.{_file_extension.lower()}"
if new_href not in self.toc_rn.values():
self.toc_rn[href] = new_href
print(f"mixed href: {_id}:{_href} -> {self.toc_rn[href]}")
print(f"encrypt href: {_id}:{_href} -> {self.toc_rn[href]}")
else:
self.toc_rn[href] = new_href
print(f"mixed href: {_id}:{_href} -> {new_href} 重复")
print(f"encrypt href: {_id}:{_href} -> {new_href} 重复")
return new_href

############################################################
Expand Down
File renamed without changes.

0 comments on commit 55f0102

Please sign in to comment.