]>
jfr.im git - yt-dlp.git/blob - pyinst.py
6 from PyInstaller
.utils
.hooks
import collect_submodules
8 OS_NAME
= platform
.system()
9 if OS_NAME
== 'Windows':
10 from PyInstaller
.utils
.win32
.versioninfo
import (
20 elif OS_NAME
== 'Darwin':
23 raise Exception('{OS_NAME} is not supported')
25 ARCH
= platform
.architecture()[0][:2]
29 opts
= parse_options()
30 version
= read_version()
32 suffix
= '_macos' if OS_NAME
== 'Darwin' else '_x86' if ARCH
== '32' else ''
33 final_file
= 'dist/%syt-dlp%s%s' % (
34 'yt-dlp/' if '--onedir' in opts
else '', suffix
, '.exe' if OS_NAME
== 'Windows' else '')
36 print(f
'Building yt-dlp v{version} {ARCH}bit for {OS_NAME} with options {opts}')
37 print('Remember to update the version using "devscripts/update-version.py"')
38 if not os
.path
.isfile('yt_dlp/extractor/lazy_extractors.py'):
39 print('WARNING: Building without lazy_extractors. Run '
40 '"devscripts/make_lazy_extractors.py" to build lazy extractors', file=sys
.stderr
)
41 print(f
'Destination: {final_file}\n')
44 f
'--name=yt-dlp{suffix}',
45 '--icon=devscripts/logo.ico',
46 '--upx-exclude=vcruntime140.dll',
48 *dependency_options(),
52 print(f
'Running PyInstaller with {opts}')
54 import PyInstaller
.__main
__
56 PyInstaller
.__main
__.run(opts
)
58 set_version_info(final_file
, version
)
62 # Compatability with older arguments
64 if opts
[0:1] in (['32'], ['64']):
66 raise Exception(f
'{opts[0]}bit executable cannot be built on a {ARCH}bit system')
68 return opts
or ['--onefile']
72 exec(compile(open('yt_dlp/version.py').read(), 'yt_dlp/version.py', 'exec'))
73 return locals()['__version__']
76 def version_to_list(version
):
77 version_list
= version
.split('.')
78 return list(map(int, version_list
)) + [0] * (4 - len(version_list
))
81 def dependency_options():
82 dependencies
= [pycryptodome_module(), 'mutagen', 'brotli', 'certifi'] + collect_submodules('websockets')
83 excluded_modules
= ['test', 'ytdlp_plugins', 'youtube-dl', 'youtube-dlc']
85 yield from (f
'--hidden-import={module}' for module
in dependencies
)
86 yield from (f
'--exclude-module={module}' for module
in excluded_modules
)
89 def pycryptodome_module():
91 import Cryptodome
# noqa: F401
94 import Crypto
# noqa: F401
95 print('WARNING: Using Crypto since Cryptodome is not available. '
96 'Install with: pip install pycryptodomex', file=sys
.stderr
)
103 def set_version_info(exe
, version
):
104 if OS_NAME
== 'Windows':
105 windows_set_version(exe
, version
)
108 def windows_set_version(exe
, version
):
109 version_list
= version_to_list(version
)
110 suffix
= '_x86' if ARCH
== '32' else ''
111 SetVersion(exe
, VSVersionInfo(
113 filevers
=version_list
,
114 prodvers
=version_list
,
123 StringFileInfo([StringTable('040904B0', [
124 StringStruct('Comments', 'yt-dlp%s Command Line Interface.' % suffix
),
125 StringStruct('CompanyName', 'https://github.com/yt-dlp'),
126 StringStruct('FileDescription', 'yt-dlp%s' % (' (32 Bit)' if ARCH
== '32' else '')),
127 StringStruct('FileVersion', version
),
128 StringStruct('InternalName', f
'yt-dlp{suffix}'),
129 StringStruct('LegalCopyright', 'pukkandan.ytdlp@gmail.com | UNLICENSE'),
130 StringStruct('OriginalFilename', f
'yt-dlp{suffix}.exe'),
131 StringStruct('ProductName', f
'yt-dlp{suffix}'),
133 'ProductVersion', f
'{version}{suffix} on Python {platform.python_version()}'),
134 ])]), VarFileInfo([VarStruct('Translation', [0, 1200])])
139 if __name__
== '__main__':