7 from PyInstaller
.__main
__ import run
as run_pyinstaller
9 OS_NAME
, MACHINE
, ARCH
= sys
.platform
, platform
.machine(), platform
.architecture()[0][:2]
10 if MACHINE
in ('x86_64', 'AMD64') or ('i' in MACHINE
and '86' in MACHINE
):
11 # NB: Windows x86 has MACHINE = AMD64 irrespective of bitness
12 MACHINE
= 'x86' if ARCH
== '32' else ''
16 opts
= parse_options()
17 version
= read_version('yt_dlp/version.py')
19 onedir
= '--onedir' in opts
or '-D' in opts
20 if not onedir
and '-F' not in opts
and '--onefile' not in opts
:
21 opts
.append('--onefile')
23 name
, final_file
= exe(onedir
)
24 print(f
'Building yt-dlp v{version} for {OS_NAME} {platform.machine()} with options {opts}')
25 print('Remember to update the version using "devscripts/update-version.py"')
26 if not os
.path
.isfile('yt_dlp/extractor/lazy_extractors.py'):
27 print('WARNING: Building without lazy_extractors. Run '
28 '"devscripts/make_lazy_extractors.py" to build lazy extractors', file=sys
.stderr
)
29 print(f
'Destination: {final_file}\n')
33 '--icon=devscripts/logo.ico',
34 '--upx-exclude=vcruntime140.dll',
36 *dependency_options(),
41 print(f
'Running PyInstaller with {opts}')
43 set_version_info(final_file
, version
)
47 # Compatibility with older arguments
49 if opts
[0:1] in (['32'], ['64']):
51 raise Exception(f
'{opts[0]}bit executable cannot be built on a {ARCH}bit system')
56 # Get the version from yt_dlp/version.py without importing the package
57 def read_version(fname
):
58 with open(fname
, encoding
='utf-8') as f
:
59 exec(compile(f
.read(), fname
, 'exec'))
60 return locals()['__version__']
64 """@returns (name, path)"""
65 name
= '_'.join(filter(None, (
67 {'win32': '', 'darwin': 'macos'}
.get(OS_NAME
, OS_NAME
),
70 return name
, ''.join(filter(None, (
72 onedir
and f
'{name}/',
74 OS_NAME
== 'win32' and '.exe'
78 def version_to_list(version
):
79 version_list
= version
.split('.')
80 return list(map(int, version_list
)) + [0] * (4 - len(version_list
))
83 def dependency_options():
84 # Due to the current implementation, these are auto-detected, but explicitly add them just in case
85 dependencies
= [pycryptodome_module(), 'mutagen', 'brotli', 'certifi', 'websockets']
86 excluded_modules
= ['test', 'ytdlp_plugins', 'youtube_dl', 'youtube_dlc']
88 yield from (f
'--hidden-import={module}' for module
in dependencies
)
89 yield '--collect-submodules=websockets'
90 yield from (f
'--exclude-module={module}' for module
in excluded_modules
)
93 def pycryptodome_module():
95 import Cryptodome
# noqa: F401
98 import Crypto
# noqa: F401
99 print('WARNING: Using Crypto since Cryptodome is not available. '
100 'Install with: pip install pycryptodomex', file=sys
.stderr
)
107 def set_version_info(exe
, version
):
108 if OS_NAME
== 'win32':
109 windows_set_version(exe
, version
)
112 def windows_set_version(exe
, version
):
113 from PyInstaller
.utils
.win32
.versioninfo
import (
124 version_list
= version_to_list(version
)
125 suffix
= MACHINE
and f
'_{MACHINE}'
126 SetVersion(exe
, VSVersionInfo(
128 filevers
=version_list
,
129 prodvers
=version_list
,
138 StringFileInfo([StringTable('040904B0', [
139 StringStruct('Comments', 'yt-dlp%s Command Line Interface' % suffix
),
140 StringStruct('CompanyName', 'https://github.com/yt-dlp'),
141 StringStruct('FileDescription', 'yt-dlp%s' % (MACHINE
and f
' ({MACHINE})')),
142 StringStruct('FileVersion', version
),
143 StringStruct('InternalName', f
'yt-dlp{suffix}'),
144 StringStruct('LegalCopyright', 'pukkandan.ytdlp@gmail.com | UNLICENSE'),
145 StringStruct('OriginalFilename', f
'yt-dlp{suffix}.exe'),
146 StringStruct('ProductName', f
'yt-dlp{suffix}'),
148 'ProductVersion', f
'{version}{suffix} on Python {platform.python_version()}'),
149 ])]), VarFileInfo([VarStruct('Translation', [0, 1200])])
154 if __name__
== '__main__':