7 from PyInstaller
.__main
__ import run
as run_pyinstaller
9 OS_NAME
, MACHINE
= sys
.platform
, platform
.machine()
10 if MACHINE
in ('x86_64', 'amd64'):
12 elif 'i' in MACHINE
and '86' in MACHINE
:
17 opts
= parse_options()
18 version
= read_version('yt_dlp/version.py')
20 onedir
= '--onedir' in opts
or '-D' in opts
21 if not onedir
and '-F' not in opts
and '--onefile' not in opts
:
22 opts
.append('--onefile')
24 name
, final_file
= exe(onedir
)
25 print(f
'Building yt-dlp v{version} for {OS_NAME} {platform.machine()} with options {opts}')
26 print('Remember to update the version using "devscripts/update-version.py"')
27 if not os
.path
.isfile('yt_dlp/extractor/lazy_extractors.py'):
28 print('WARNING: Building without lazy_extractors. Run '
29 '"devscripts/make_lazy_extractors.py" to build lazy extractors', file=sys
.stderr
)
30 print(f
'Destination: {final_file}\n')
34 '--icon=devscripts/logo.ico',
35 '--upx-exclude=vcruntime140.dll',
37 # NB: Modules that are only imported dynamically must be added here.
38 # --collect-submodules may not work correctly if user has a yt-dlp installed via PIP
39 '--hidden-import=yt_dlp.compat._legacy',
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']):
54 ARCH
= platform
.architecture()[0][:2]
56 raise Exception(f
'{opts[0]}bit executable cannot be built on a {ARCH}bit system')
61 # Get the version from yt_dlp/version.py without importing the package
62 def read_version(fname
):
63 with open(fname
, encoding
='utf-8') as f
:
64 exec(compile(f
.read(), fname
, 'exec'))
65 return locals()['__version__']
69 """@returns (name, path)"""
70 name
= '_'.join(filter(None, (
72 {'win32': '', 'darwin': 'macos'}
.get(OS_NAME
, OS_NAME
),
75 return name
, ''.join(filter(None, (
77 onedir
and f
'{name}/',
79 OS_NAME
== 'win32' and '.exe'
83 def version_to_list(version
):
84 version_list
= version
.split('.')
85 return list(map(int, version_list
)) + [0] * (4 - len(version_list
))
88 def dependency_options():
89 # Due to the current implementation, these are auto-detected, but explicitly add them just in case
90 dependencies
= [pycryptodome_module(), 'mutagen', 'brotli', 'certifi', 'websockets']
91 excluded_modules
= ['test', 'ytdlp_plugins', 'youtube_dl', 'youtube_dlc']
93 yield from (f
'--hidden-import={module}' for module
in dependencies
)
94 yield '--collect-submodules=websockets'
95 yield from (f
'--exclude-module={module}' for module
in excluded_modules
)
98 def pycryptodome_module():
100 import Cryptodome
# noqa: F401
103 import Crypto
# noqa: F401
104 print('WARNING: Using Crypto since Cryptodome is not available. '
105 'Install with: pip install pycryptodomex', file=sys
.stderr
)
112 def set_version_info(exe
, version
):
113 if OS_NAME
== 'win32':
114 windows_set_version(exe
, version
)
117 def windows_set_version(exe
, version
):
118 from PyInstaller
.utils
.win32
.versioninfo
import (
129 version_list
= version_to_list(version
)
130 suffix
= MACHINE
and f
'_{MACHINE}'
131 SetVersion(exe
, VSVersionInfo(
133 filevers
=version_list
,
134 prodvers
=version_list
,
143 StringFileInfo([StringTable('040904B0', [
144 StringStruct('Comments', 'yt-dlp%s Command Line Interface' % suffix
),
145 StringStruct('CompanyName', 'https://github.com/yt-dlp'),
146 StringStruct('FileDescription', 'yt-dlp%s' % (MACHINE
and f
' ({MACHINE})')),
147 StringStruct('FileVersion', version
),
148 StringStruct('InternalName', f
'yt-dlp{suffix}'),
149 StringStruct('LegalCopyright', 'pukkandan.ytdlp@gmail.com | UNLICENSE'),
150 StringStruct('OriginalFilename', f
'yt-dlp{suffix}.exe'),
151 StringStruct('ProductName', f
'yt-dlp{suffix}'),
153 'ProductVersion', f
'{version}{suffix} on Python {platform.python_version()}'),
154 ])]), VarFileInfo([VarStruct('Translation', [0, 1200])])
159 if __name__
== '__main__':