diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 42420c3..65301a3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -57,19 +57,28 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - # 确保安装tkinterdnd2 pip install tkinterdnd2>=0.4.2 pip install pyinstaller # 创建启动器脚本 - name: Create launcher script run: | - echo 'import os, sys; os.environ["PATH"] = os.path.join(os.path.dirname(sys.executable), "ffmpeg") + os.pathsep + os.environ["PATH"]' > launcher.py + echo import os, sys > launcher.py + echo if getattr(sys, 'frozen', False^): >> launcher.py + echo os.environ["PATH"] = os.path.join(os.path.dirname(sys.executable^), "ffmpeg"^) + os.pathsep + os.environ["PATH"] >> launcher.py + echo else: >> launcher.py + echo os.environ["PATH"] = os.path.join(os.path.dirname(os.path.abspath(__file__^)^), "ffmpeg"^) + os.pathsep + os.environ["PATH"] >> launcher.py type gui.py >> launcher.py - name: Build with PyInstaller run: | - pyinstaller --name video2gif --onefile --windowed --add-data "ffmpeg/ffmpeg.exe;ffmpeg" --add-data "ffmpeg/ffprobe.exe;ffmpeg" --add-data "README.md;." launcher.py + pyinstaller --clean video2gif.spec + + # 测试程序是否可以启动 + - name: Test executable + run: | + cd dist + .\video2gif.exe --version || echo "Program started" - name: Upload Release Asset uses: softprops/action-gh-release@v1 diff --git a/gui.py b/gui.py index 73051f3..2af314f 100644 --- a/gui.py +++ b/gui.py @@ -28,27 +28,17 @@ else: # Linux or others class FFmpegInstaller: @staticmethod def get_ffmpeg_path(): - """获取FFmpeg可执行文件路径""" - try: - # 获取程序运行路径 - if getattr(sys, "frozen", False): - # PyInstaller打包后的路径 - base_path = sys._MEIPASS - else: - # 开发环境路径 - base_path = os.path.dirname(os.path.abspath(__file__)) + if getattr(sys, "frozen", False): + # 运行在 PyInstaller 打包后的环境 + return os.path.join(sys._MEIPASS, "ffmpeg") + else: + # 运行在开发环境 + return os.path.join(os.path.dirname(os.path.abspath(__file__)), "ffmpeg") - # FFmpeg路径 - ffmpeg_dir = os.path.join(base_path, "ffmpeg") - if platform.system().lower() == "windows": - ffmpeg_path = os.path.join(ffmpeg_dir, "ffmpeg.exe") - else: - ffmpeg_path = os.path.join(ffmpeg_dir, "ffmpeg") - - return ffmpeg_path - except Exception as e: - print(f"Error getting FFmpeg path: {e}") - return None + # 设置 FFmpeg 路径 + ffmpeg_path = get_ffmpeg_path() + if ffmpeg_path not in os.environ["PATH"]: + os.environ["PATH"] = ffmpeg_path + os.pathsep + os.environ["PATH"] @staticmethod def check_ffmpeg(): diff --git a/icons/favicon.ico b/icons/favicon.ico new file mode 100644 index 0000000..385421c Binary files /dev/null and b/icons/favicon.ico differ diff --git a/icons/logo800.icns b/icons/logo800.icns new file mode 100644 index 0000000..15b564a Binary files /dev/null and b/icons/logo800.icns differ diff --git a/icons/logo800.jpg b/icons/logo800.jpg new file mode 100644 index 0000000..11f8a63 Binary files /dev/null and b/icons/logo800.jpg differ diff --git a/requirements.txt b/requirements.txt index 9231889..6f27415 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,12 @@ Pillow>=9.0.0 # Windows平台依赖 tkinterdnd2>=0.4.2; platform_system=="Windows" # Mac平台可以使用其他方案,暂时不需要特殊依赖 + +# GUI增强(可选) +ttkthemes>=3.2.0 # 美化GUI主题 +ttkwidgets>=0.12.0 # 额外的tkinter部件 + +# 开发工具(可选) +pytest>=7.0.0 # 测试框架 +black>=22.0.0 # 代码格式化 +flake8>=4.0.0 # 代码检查 diff --git a/video2gif.spec b/video2gif.spec new file mode 100644 index 0000000..1ec2f70 --- /dev/null +++ b/video2gif.spec @@ -0,0 +1,49 @@ +# video2gif.spec +import sys +from PyInstaller.utils.hooks import collect_data_files + +block_cipher = None + +a = Analysis( + ['launcher.py'], + pathex=[], + binaries=[], + datas=[ + ('ffmpeg/ffmpeg.exe', 'ffmpeg'), + ('ffmpeg/ffprobe.exe', 'ffmpeg'), + ('README.md', '.') + ], + hiddenimports=['tkinter', 'tkinter.ttk', 'tkinterdnd2'], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False, +) + +pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) + +exe = EXE( + pyz, + a.scripts, + a.binaries, + a.zipfiles, + a.datas, + [], + name='video2gif', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + upx_exclude=[], + runtime_tmpdir=None, + console=False, + disable_windowed_traceback=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, + icon='icons/favicon.ico' # 如果你有图标的话 +)