]> jfr.im git - yt-dlp.git/blob - pyinst.py
[build] Use pycryptodomex for PyInstaller (#1179)
[yt-dlp.git] / pyinst.py
1 #!/usr/bin/env python3
2 # coding: utf-8
3
4 from __future__ import unicode_literals
5 import sys
6 # import os
7 import platform
8
9 from PyInstaller.utils.hooks import collect_submodules
10 from PyInstaller.utils.win32.versioninfo import (
11 VarStruct, VarFileInfo, StringStruct, StringTable,
12 StringFileInfo, FixedFileInfo, VSVersionInfo, SetVersion,
13 )
14 import PyInstaller.__main__
15
16 arch = platform.architecture()[0][:2]
17 assert arch in ('32', '64')
18 _x86 = '_x86' if arch == '32' else ''
19
20 # Compatability with older arguments
21 opts = sys.argv[1:]
22 if opts[0:1] in (['32'], ['64']):
23 if arch != opts[0]:
24 raise Exception(f'{opts[0]}bit executable cannot be built on a {arch}bit system')
25 opts = opts[1:]
26 opts = opts or ['--onefile']
27
28 print(f'Building {arch}bit version with options {opts}')
29
30 FILE_DESCRIPTION = 'yt-dlp%s' % (' (32 Bit)' if _x86 else '')
31
32 # root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
33 # print('Changing working directory to %s' % root_dir)
34 # os.chdir(root_dir)
35
36 exec(compile(open('yt_dlp/version.py').read(), 'yt_dlp/version.py', 'exec'))
37 VERSION = locals()['__version__']
38
39 VERSION_LIST = VERSION.split('.')
40 VERSION_LIST = list(map(int, VERSION_LIST)) + [0] * (4 - len(VERSION_LIST))
41
42 print('Version: %s%s' % (VERSION, _x86))
43 print('Remember to update the version using devscipts\\update-version.py')
44
45 VERSION_FILE = VSVersionInfo(
46 ffi=FixedFileInfo(
47 filevers=VERSION_LIST,
48 prodvers=VERSION_LIST,
49 mask=0x3F,
50 flags=0x0,
51 OS=0x4,
52 fileType=0x1,
53 subtype=0x0,
54 date=(0, 0),
55 ),
56 kids=[
57 StringFileInfo([
58 StringTable(
59 '040904B0', [
60 StringStruct('Comments', 'yt-dlp%s Command Line Interface.' % _x86),
61 StringStruct('CompanyName', 'https://github.com/yt-dlp'),
62 StringStruct('FileDescription', FILE_DESCRIPTION),
63 StringStruct('FileVersion', VERSION),
64 StringStruct('InternalName', 'yt-dlp%s' % _x86),
65 StringStruct(
66 'LegalCopyright',
67 'pukkandan.ytdlp@gmail.com | UNLICENSE',
68 ),
69 StringStruct('OriginalFilename', 'yt-dlp%s.exe' % _x86),
70 StringStruct('ProductName', 'yt-dlp%s' % _x86),
71 StringStruct(
72 'ProductVersion',
73 '%s%s on Python %s' % (VERSION, _x86, platform.python_version())),
74 ])]),
75 VarFileInfo([VarStruct('Translation', [0, 1200])])
76 ]
77 )
78
79 dependancies = ['Cryptodome', 'mutagen'] + collect_submodules('websockets')
80 excluded_modules = ['test', 'ytdlp_plugins', 'youtube-dl', 'youtube-dlc']
81
82 PyInstaller.__main__.run([
83 '--name=yt-dlp%s' % _x86,
84 '--icon=devscripts/logo.ico',
85 *[f'--exclude-module={module}' for module in excluded_modules],
86 *[f'--hidden-import={module}' for module in dependancies],
87 '--upx-exclude=vcruntime140.dll',
88 '--noconfirm',
89 *opts,
90 'yt_dlp/__main__.py',
91 ])
92 SetVersion('dist/%syt-dlp%s.exe' % ('yt-dlp/' if '--onedir' in opts else '', _x86), VERSION_FILE)