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().lower(), platform
.architecture()[0][:2]
16 if MACHINE
in ('x86', 'x86_64', 'amd64', 'i386', 'i686'):
17 MACHINE
= 'x86' if ARCH
== '32' else ''
21 opts
, version
= parse_options(), read_version()
23 onedir
= '--onedir' in opts
or '-D' in opts
24 if not onedir
and '-F' not in opts
and '--onefile' not in opts
:
25 opts
.append('--onefile')
27 name
, final_file
= exe(onedir
)
28 print(f
'Building yt-dlp v{version} for {OS_NAME} {platform.machine()} with options {opts}')
29 print('Remember to update the version using "devscripts/update-version.py"')
30 if not os
.path
.isfile('yt_dlp/extractor/lazy_extractors.py'):
31 print('WARNING: Building without lazy_extractors. Run '
32 '"devscripts/make_lazy_extractors.py" to build lazy extractors', file=sys
.stderr
)
33 print(f
'Destination: {final_file}\n')
37 '--icon=devscripts/logo.ico',
38 '--upx-exclude=vcruntime140.dll',
40 *dependency_options(),
45 print(f
'Running PyInstaller with {opts}')
47 set_version_info(final_file
, version
)
51 # Compatibility with older arguments
53 if opts
[0:1] in (['32'], ['64']):
55 raise Exception(f
'{opts[0]}bit executable cannot be built on a {ARCH}bit system')
61 """@returns (name, path)"""
62 name
= '_'.join(filter(None, (
64 {'win32': '', 'darwin': 'macos'}.get(OS_NAME
, OS_NAME
),
67 return name
, ''.join(filter(None, (
69 onedir
and f
'{name}/',
71 OS_NAME
== 'win32' and '.exe'
75 def version_to_list(version
):
76 version_list
= version
.split('.')
77 return list(map(int, version_list
)) + [0] * (4 - len(version_list
))
80 def dependency_options():
81 # Due to the current implementation, these are auto-detected, but explicitly add them just in case
82 dependencies
= [pycryptodome_module(), 'mutagen', 'brotli', 'certifi', 'websockets']
83 excluded_modules
= ('youtube_dl', 'youtube_dlc', 'test', 'ytdlp_plugins', 'devscripts')
85 yield from (f
'--hidden-import={module}' for module
in dependencies
)
86 yield '--collect-submodules=websockets'
87 yield from (f
'--exclude-module={module}' for module
in excluded_modules
)
90 def pycryptodome_module():
92 import Cryptodome
# noqa: F401
95 import Crypto
# noqa: F401
96 print('WARNING: Using Crypto since Cryptodome is not available. '
97 'Install with: pip install pycryptodomex', file=sys
.stderr
)
104 def set_version_info(exe
, version
):
105 if OS_NAME
== 'win32':
106 windows_set_version(exe
, version
)
109 def windows_set_version(exe
, version
):
110 from PyInstaller
.utils
.win32
.versioninfo
import (
121 version_list
= version_to_list(version
)
122 suffix
= MACHINE
and f
'_{MACHINE}'
123 SetVersion(exe
, VSVersionInfo(
125 filevers
=version_list
,
126 prodvers
=version_list
,
135 StringFileInfo([StringTable('040904B0', [
136 StringStruct('Comments', 'yt-dlp%s Command Line Interface' % suffix
),
137 StringStruct('CompanyName', 'https://github.com/yt-dlp'),
138 StringStruct('FileDescription', 'yt-dlp%s' % (MACHINE
and f
' ({MACHINE})')),
139 StringStruct('FileVersion', version
),
140 StringStruct('InternalName', f
'yt-dlp{suffix}'),
141 StringStruct('LegalCopyright', 'pukkandan.ytdlp@gmail.com | UNLICENSE'),
142 StringStruct('OriginalFilename', f
'yt-dlp{suffix}.exe'),
143 StringStruct('ProductName', f
'yt-dlp{suffix}'),
145 'ProductVersion', f
'{version}{suffix} on Python {platform.python_version()}'),
146 ])]), VarFileInfo([VarStruct('Translation', [0, 1200])])
151 if __name__
== '__main__':