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 '--additional-hooks-dir=yt_dlp/__pyinstaller',
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 set_version_info(exe
, version
):
81 if OS_NAME
== 'win32':
82 windows_set_version(exe
, version
)
85 def windows_set_version(exe
, version
):
86 from PyInstaller
.utils
.win32
.versioninfo
import (
97 from PyInstaller
.utils
.win32
.versioninfo
import SetVersion
98 except ImportError: # Pyinstaller >= 5.8
99 from PyInstaller
.utils
.win32
.versioninfo
import write_version_info_to_executable
as SetVersion
101 version_list
= version_to_list(version
)
102 suffix
= MACHINE
and f
'_{MACHINE}'
103 SetVersion(exe
, VSVersionInfo(
105 filevers
=version_list
,
106 prodvers
=version_list
,
115 StringFileInfo([StringTable('040904B0', [
116 StringStruct('Comments', 'yt-dlp%s Command Line Interface' % suffix
),
117 StringStruct('CompanyName', 'https://github.com/yt-dlp'),
118 StringStruct('FileDescription', 'yt-dlp%s' % (MACHINE
and f
' ({MACHINE})')),
119 StringStruct('FileVersion', version
),
120 StringStruct('InternalName', f
'yt-dlp{suffix}'),
121 StringStruct('LegalCopyright', 'pukkandan.ytdlp@gmail.com | UNLICENSE'),
122 StringStruct('OriginalFilename', f
'yt-dlp{suffix}.exe'),
123 StringStruct('ProductName', f
'yt-dlp{suffix}'),
125 'ProductVersion', f
'{version}{suffix} on Python {platform.python_version()}'),
126 ])]), VarFileInfo([VarStruct('Translation', [0, 1200])])
131 if __name__
== '__main__':