3 # Allow direct execution
7 sys
.path
.insert(0, os
.path
.dirname(os
.path
.abspath(__file__
)))
11 from PyInstaller
.__main
__ import run
as run_pyinstaller
13 from devscripts
.utils
import read_version
15 OS_NAME
, MACHINE
, ARCH
= sys
.platform
, platform
.machine(), platform
.architecture()[0][:2]
16 if MACHINE
in ('x86_64', 'AMD64') or ('i' in MACHINE
and '86' in MACHINE
):
17 # NB: Windows x86 has MACHINE = AMD64 irrespective of bitness
18 MACHINE
= 'x86' if ARCH
== '32' else ''
22 opts
, version
= parse_options(), read_version()
24 onedir
= '--onedir' in opts
or '-D' in opts
25 if not onedir
and '-F' not in opts
and '--onefile' not in opts
:
26 opts
.append('--onefile')
28 name
, final_file
= exe(onedir
)
29 print(f
'Building yt-dlp v{version} for {OS_NAME} {platform.machine()} with options {opts}')
30 print('Remember to update the version using "devscripts/update-version.py"')
31 if not os
.path
.isfile('yt_dlp/extractor/lazy_extractors.py'):
32 print('WARNING: Building without lazy_extractors. Run '
33 '"devscripts/make_lazy_extractors.py" to build lazy extractors', file=sys
.stderr
)
34 print(f
'Destination: {final_file}\n')
38 '--icon=devscripts/logo.ico',
39 '--upx-exclude=vcruntime140.dll',
41 *dependency_options(),
46 print(f
'Running PyInstaller with {opts}')
48 set_version_info(final_file
, version
)
52 # Compatibility with older arguments
54 if opts
[0:1] in (['32'], ['64']):
56 raise Exception(f
'{opts[0]}bit executable cannot be built on a {ARCH}bit system')
62 """@returns (name, path)"""
63 name
= '_'.join(filter(None, (
65 {'win32': '', 'darwin': 'macos'}
.get(OS_NAME
, OS_NAME
),
68 return name
, ''.join(filter(None, (
70 onedir
and f
'{name}/',
72 OS_NAME
== 'win32' and '.exe'
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 # Due to the current implementation, these are auto-detected, but explicitly add them just in case
83 dependencies
= [pycryptodome_module(), 'mutagen', 'brotli', 'certifi', 'websockets']
84 excluded_modules
= ('youtube_dl', 'youtube_dlc', 'test', 'ytdlp_plugins', 'devscripts')
86 yield from (f
'--hidden-import={module}' for module
in dependencies
)
87 yield '--collect-submodules=websockets'
88 yield from (f
'--exclude-module={module}' for module
in excluded_modules
)
91 def pycryptodome_module():
93 import Cryptodome
# noqa: F401
96 import Crypto
# noqa: F401
97 print('WARNING: Using Crypto since Cryptodome is not available. '
98 'Install with: pip install pycryptodomex', file=sys
.stderr
)
105 def set_version_info(exe
, version
):
106 if OS_NAME
== 'win32':
107 windows_set_version(exe
, version
)
110 def windows_set_version(exe
, version
):
111 from PyInstaller
.utils
.win32
.versioninfo
import (
122 version_list
= version_to_list(version
)
123 suffix
= MACHINE
and f
'_{MACHINE}'
124 SetVersion(exe
, VSVersionInfo(
126 filevers
=version_list
,
127 prodvers
=version_list
,
136 StringFileInfo([StringTable('040904B0', [
137 StringStruct('Comments', 'yt-dlp%s Command Line Interface' % suffix
),
138 StringStruct('CompanyName', 'https://github.com/yt-dlp'),
139 StringStruct('FileDescription', 'yt-dlp%s' % (MACHINE
and f
' ({MACHINE})')),
140 StringStruct('FileVersion', version
),
141 StringStruct('InternalName', f
'yt-dlp{suffix}'),
142 StringStruct('LegalCopyright', 'pukkandan.ytdlp@gmail.com | UNLICENSE'),
143 StringStruct('OriginalFilename', f
'yt-dlp{suffix}.exe'),
144 StringStruct('ProductName', f
'yt-dlp{suffix}'),
146 'ProductVersion', f
'{version}{suffix} on Python {platform.python_version()}'),
147 ])]), VarFileInfo([VarStruct('Translation', [0, 1200])])
152 if __name__
== '__main__':