6 from PyInstaller
.__main
__ import run
as run_pyinstaller
8 OS_NAME
, ARCH
= sys
.platform
, platform
.architecture()[0][:2]
12 opts
= parse_options()
13 version
= read_version('yt_dlp/version.py')
15 onedir
= '--onedir' in opts
or '-D' in opts
16 if not onedir
and '-F' not in opts
and '--onefile' not in opts
:
17 opts
.append('--onefile')
19 name
, final_file
= exe(onedir
)
20 print(f
'Building yt-dlp v{version} {ARCH}bit for {OS_NAME} with options {opts}')
21 print('Remember to update the version using "devscripts/update-version.py"')
22 if not os
.path
.isfile('yt_dlp/extractor/lazy_extractors.py'):
23 print('WARNING: Building without lazy_extractors. Run '
24 '"devscripts/make_lazy_extractors.py" to build lazy extractors', file=sys
.stderr
)
25 print(f
'Destination: {final_file}\n')
29 '--icon=devscripts/logo.ico',
30 '--upx-exclude=vcruntime140.dll',
32 # NB: Modules that are only imported dynamically must be added here.
33 # --collect-submodules may not work correctly if user has a yt-dlp installed via PIP
34 '--hidden-import=yt_dlp.compat._legacy',
35 *dependency_options(),
40 print(f
'Running PyInstaller with {opts}')
42 set_version_info(final_file
, version
)
46 # Compatability with older arguments
48 if opts
[0:1] in (['32'], ['64']):
50 raise Exception(f
'{opts[0]}bit executable cannot be built on a {ARCH}bit system')
55 # Get the version from yt_dlp/version.py without importing the package
56 def read_version(fname
):
57 with open(fname
, encoding
='utf-8') as f
:
58 exec(compile(f
.read(), fname
, 'exec'))
59 return locals()['__version__']
63 """@returns (name, path)"""
64 name
= '_'.join(filter(None, (
66 {'win32': '', 'darwin': 'macos'}
.get(OS_NAME
, OS_NAME
),
67 ARCH
== '32' and 'x86'
69 return name
, ''.join(filter(None, (
71 onedir
and f
'{name}/',
73 OS_NAME
== 'win32' and '.exe'
77 def version_to_list(version
):
78 version_list
= version
.split('.')
79 return list(map(int, version_list
)) + [0] * (4 - len(version_list
))
82 def dependency_options():
83 # Due to the current implementation, these are auto-detected, but explicitly add them just in case
84 dependencies
= [pycryptodome_module(), 'mutagen', 'brotli', 'certifi', 'websockets']
85 excluded_modules
= ['test', 'ytdlp_plugins', 'youtube_dl', 'youtube_dlc']
87 yield from (f
'--hidden-import={module}' for module
in dependencies
)
88 yield '--collect-submodules=websockets'
89 yield from (f
'--exclude-module={module}' for module
in excluded_modules
)
92 def pycryptodome_module():
94 import Cryptodome
# noqa: F401
97 import Crypto
# noqa: F401
98 print('WARNING: Using Crypto since Cryptodome is not available. '
99 'Install with: pip install pycryptodomex', file=sys
.stderr
)
106 def set_version_info(exe
, version
):
107 if OS_NAME
== 'win32':
108 windows_set_version(exe
, version
)
111 def windows_set_version(exe
, version
):
112 from PyInstaller
.utils
.win32
.versioninfo
import (
123 version_list
= version_to_list(version
)
124 suffix
= '_x86' if ARCH
== '32' else ''
125 SetVersion(exe
, VSVersionInfo(
127 filevers
=version_list
,
128 prodvers
=version_list
,
137 StringFileInfo([StringTable('040904B0', [
138 StringStruct('Comments', 'yt-dlp%s Command Line Interface.' % suffix
),
139 StringStruct('CompanyName', 'https://github.com/yt-dlp'),
140 StringStruct('FileDescription', 'yt-dlp%s' % (' (32 Bit)' if ARCH
== '32' else '')),
141 StringStruct('FileVersion', version
),
142 StringStruct('InternalName', f
'yt-dlp{suffix}'),
143 StringStruct('LegalCopyright', 'pukkandan.ytdlp@gmail.com | UNLICENSE'),
144 StringStruct('OriginalFilename', f
'yt-dlp{suffix}.exe'),
145 StringStruct('ProductName', f
'yt-dlp{suffix}'),
147 'ProductVersion', f
'{version}{suffix} on Python {platform.python_version()}'),
148 ])]), VarFileInfo([VarStruct('Translation', [0, 1200])])
153 if __name__
== '__main__':