6 from PyInstaller
.utils
.hooks
import collect_submodules
9 OS_NAME
= platform
.system()
10 if OS_NAME
== 'Windows':
11 from PyInstaller
.utils
.win32
.versioninfo
import (
12 VarStruct
, VarFileInfo
, StringStruct
, StringTable
,
13 StringFileInfo
, FixedFileInfo
, VSVersionInfo
, SetVersion
,
15 elif OS_NAME
== 'Darwin':
18 raise Exception('{OS_NAME} is not supported')
20 ARCH
= platform
.architecture()[0][:2]
24 opts
= parse_options()
25 version
= read_version()
27 suffix
= '_macos' if OS_NAME
== 'Darwin' else '_x86' if ARCH
== '32' else ''
28 final_file
= 'dist/%syt-dlp%s%s' % (
29 'yt-dlp/' if '--onedir' in opts
else '', suffix
, '.exe' if OS_NAME
== 'Windows' else '')
31 print(f
'Building yt-dlp v{version} {ARCH}bit for {OS_NAME} with options {opts}')
32 print('Remember to update the version using "devscripts/update-version.py"')
33 if not os
.path
.isfile('yt_dlp/extractor/lazy_extractors.py'):
34 print('WARNING: Building without lazy_extractors. Run '
35 '"devscripts/make_lazy_extractors.py" to build lazy extractors', file=sys
.stderr
)
36 print(f
'Destination: {final_file}\n')
39 f
'--name=yt-dlp{suffix}',
40 '--icon=devscripts/logo.ico',
41 '--upx-exclude=vcruntime140.dll',
43 *dependency_options(),
47 print(f
'Running PyInstaller with {opts}')
49 import PyInstaller
.__main
__
51 PyInstaller
.__main
__.run(opts
)
53 set_version_info(final_file
, version
)
57 # Compatability with older arguments
59 if opts
[0:1] in (['32'], ['64']):
61 raise Exception(f
'{opts[0]}bit executable cannot be built on a {ARCH}bit system')
63 return opts
or ['--onefile']
67 exec(compile(open('yt_dlp/version.py').read(), 'yt_dlp/version.py', 'exec'))
68 return locals()['__version__']
71 def version_to_list(version
):
72 version_list
= version
.split('.')
73 return list(map(int, version_list
)) + [0] * (4 - len(version_list
))
76 def dependency_options():
77 dependencies
= [pycryptodome_module(), 'mutagen', 'brotli'] + collect_submodules('websockets')
78 excluded_modules
= ['test', 'ytdlp_plugins', 'youtube-dl', 'youtube-dlc']
80 yield from (f
'--hidden-import={module}' for module
in dependencies
)
81 yield from (f
'--exclude-module={module}' for module
in excluded_modules
)
84 def pycryptodome_module():
86 import Cryptodome
# noqa: F401
89 import Crypto
# noqa: F401
90 print('WARNING: Using Crypto since Cryptodome is not available. '
91 'Install with: pip install pycryptodomex', file=sys
.stderr
)
98 def set_version_info(exe
, version
):
99 if OS_NAME
== 'Windows':
100 windows_set_version(exe
, version
)
103 def windows_set_version(exe
, version
):
104 version_list
= version_to_list(version
)
105 suffix
= '_x86' if ARCH
== '32' else ''
106 SetVersion(exe
, VSVersionInfo(
108 filevers
=version_list
,
109 prodvers
=version_list
,
118 StringFileInfo([StringTable('040904B0', [
119 StringStruct('Comments', 'yt-dlp%s Command Line Interface.' % suffix
),
120 StringStruct('CompanyName', 'https://github.com/yt-dlp'),
121 StringStruct('FileDescription', 'yt-dlp%s' % (' (32 Bit)' if ARCH
== '32' else '')),
122 StringStruct('FileVersion', version
),
123 StringStruct('InternalName', f
'yt-dlp{suffix}'),
124 StringStruct('LegalCopyright', 'pukkandan.ytdlp@gmail.com | UNLICENSE'),
125 StringStruct('OriginalFilename', f
'yt-dlp{suffix}.exe'),
126 StringStruct('ProductName', f
'yt-dlp{suffix}'),
128 'ProductVersion', f
'{version}{suffix} on Python {platform.python_version()}'),
129 ])]), VarFileInfo([VarStruct('Translation', [0, 1200])])
134 if __name__
== '__main__':