wangzhibo
2024-12-04 4c5a1f2f09f6906bf26a783d2fa345a5886a2335
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -*- mode: python ; coding: utf-8 -*-
 
import os
import shutil
from PyInstaller.utils.hooks import collect_all
import zipfile
import time
 
a = Analysis(
    ['video-splitor.py'],
    pathex=[],
    binaries=[],
    datas=[],
    hiddenimports=[],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    noarchive=False,
    optimize=0,
)
pyz = PYZ(a.pure)
 
exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.datas,
    [],
    name='videosplitorV0.1',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
    icon=['main.ico'],
)
 
# 定义额外拷贝的文件
path_ffmpeg = os.path.join(os.getcwd(), 'ffmpeg.exe')
path_checkmark = os.path.join(os.getcwd(), 'checkmark.png')
path_vlc_plugins = os.path.join(os.getcwd(), 'VLC.zip')
 
# 将 ffmpeg.exe 和 plugins 文件夹添加到 EXE 的同级目录
datas = [
    (path_ffmpeg, '.'), 
    (path_checkmark, '.'),
    (path_vlc_plugins, '.')
]
 
 
 
# 将额外的文件拷贝到目标目录
def post_processing_hook(app):
    # 获取生成的 dist 目录
    dist_dir = os.path.join(os.getcwd(), 'dist')
    
    if os.path.exists(path_ffmpeg):
        shutil.copy(path_ffmpeg, dist_dir)
    
    if os.path.exists(path_checkmark):
        shutil.copy(path_checkmark, dist_dir)
 
    if os.path.exists(path_vlc_plugins):
        copied_file_path = shutil.copy(path_vlc_plugins, dist_dir)
        with zipfile.ZipFile(copied_file_path, 'r') as zip_ref:
            zip_ref.extractall(dist_dir)
        time.sleep(1)  # 等待资源释放
        os.remove(copied_file_path)
 
# 在打包后的应用中执行文件拷贝操作
post_processing_hook(exe)