]>
Commit | Line | Data |
---|---|---|
cc52de43 | 1 | #!/usr/bin/env python3 |
54007a45 | 2 | |
115add43 | 3 | # Allow direct execution |
733d8e8f | 4 | import os |
733d8e8f | 5 | import sys |
0e5927ee | 6 | |
115add43 | 7 | sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
8 | ||
9 | import platform | |
10 | ||
c1714454 | 11 | from PyInstaller.__main__ import run as run_pyinstaller |
733d8e8f | 12 | |
115add43 | 13 | from devscripts.utils import read_version |
14 | ||
17fc3dc4 M |
15 | OS_NAME, MACHINE, ARCH = sys.platform, platform.machine().lower(), platform.architecture()[0][:2] |
16 | if MACHINE in ('x86', 'x86_64', 'amd64', 'i386', 'i686'): | |
d08e1e68 | 17 | MACHINE = 'x86' if ARCH == '32' else '' |
e38df8f9 | 18 | |
0e5927ee | 19 | |
733d8e8f | 20 | def main(): |
115add43 | 21 | opts, version = parse_options(), read_version() |
c1714454 | 22 | |
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') | |
5d535b4a | 26 | |
b5899f4f | 27 | name, final_file = exe(onedir) |
52009769 | 28 | print(f'Building yt-dlp v{version} for {OS_NAME} {platform.machine()} with options {opts}') |
49a57e70 | 29 | print('Remember to update the version using "devscripts/update-version.py"') |
733d8e8f | 30 | if not os.path.isfile('yt_dlp/extractor/lazy_extractors.py'): |
31 | print('WARNING: Building without lazy_extractors. Run ' | |
49a57e70 | 32 | '"devscripts/make_lazy_extractors.py" to build lazy extractors', file=sys.stderr) |
733d8e8f | 33 | print(f'Destination: {final_file}\n') |
e38df8f9 | 34 | |
733d8e8f | 35 | opts = [ |
e1e1ea54 | 36 | f'--name={name}', |
733d8e8f | 37 | '--icon=devscripts/logo.ico', |
38 | '--upx-exclude=vcruntime140.dll', | |
39 | '--noconfirm', | |
acb1042a | 40 | '--additional-hooks-dir=yt_dlp/__pyinstaller', |
733d8e8f | 41 | *opts, |
42 | 'yt_dlp/__main__.py', | |
43 | ] | |
733d8e8f | 44 | |
c1714454 | 45 | print(f'Running PyInstaller with {opts}') |
46 | run_pyinstaller(opts) | |
733d8e8f | 47 | set_version_info(final_file, version) |
48 | ||
49 | ||
50 | def parse_options(): | |
962ffcf8 | 51 | # Compatibility with older arguments |
733d8e8f | 52 | opts = sys.argv[1:] |
53 | if opts[0:1] in (['32'], ['64']): | |
54 | if ARCH != opts[0]: | |
55 | raise Exception(f'{opts[0]}bit executable cannot be built on a {ARCH}bit system') | |
56 | opts = opts[1:] | |
c1714454 | 57 | return opts |
e38df8f9 | 58 | |
733d8e8f | 59 | |
b5899f4f | 60 | def exe(onedir): |
61 | """@returns (name, path)""" | |
62 | name = '_'.join(filter(None, ( | |
63 | 'yt-dlp', | |
e4afcfde | 64 | {'win32': '', 'darwin': 'macos'}.get(OS_NAME, OS_NAME), |
17fc3dc4 | 65 | MACHINE, |
b5899f4f | 66 | ))) |
67 | return name, ''.join(filter(None, ( | |
68 | 'dist/', | |
69 | onedir and f'{name}/', | |
70 | name, | |
71 | OS_NAME == 'win32' and '.exe' | |
72 | ))) | |
73 | ||
74 | ||
733d8e8f | 75 | def version_to_list(version): |
76 | version_list = version.split('.') | |
77 | return list(map(int, version_list)) + [0] * (4 - len(version_list)) | |
78 | ||
79 | ||
733d8e8f | 80 | def set_version_info(exe, version): |
1890fc63 | 81 | if OS_NAME == 'win32': |
733d8e8f | 82 | windows_set_version(exe, version) |
83 | ||
84 | ||
85 | def windows_set_version(exe, version): | |
b5899f4f | 86 | from PyInstaller.utils.win32.versioninfo import ( |
87 | FixedFileInfo, | |
88 | SetVersion, | |
89 | StringFileInfo, | |
90 | StringStruct, | |
91 | StringTable, | |
92 | VarFileInfo, | |
93 | VarStruct, | |
94 | VSVersionInfo, | |
95 | ) | |
96 | ||
733d8e8f | 97 | version_list = version_to_list(version) |
52009769 | 98 | suffix = MACHINE and f'_{MACHINE}' |
733d8e8f | 99 | SetVersion(exe, VSVersionInfo( |
100 | ffi=FixedFileInfo( | |
101 | filevers=version_list, | |
102 | prodvers=version_list, | |
103 | mask=0x3F, | |
104 | flags=0x0, | |
105 | OS=0x4, | |
106 | fileType=0x1, | |
107 | subtype=0x0, | |
108 | date=(0, 0), | |
109 | ), | |
110 | kids=[ | |
111 | StringFileInfo([StringTable('040904B0', [ | |
52009769 | 112 | StringStruct('Comments', 'yt-dlp%s Command Line Interface' % suffix), |
733d8e8f | 113 | StringStruct('CompanyName', 'https://github.com/yt-dlp'), |
52009769 | 114 | StringStruct('FileDescription', 'yt-dlp%s' % (MACHINE and f' ({MACHINE})')), |
733d8e8f | 115 | StringStruct('FileVersion', version), |
116 | StringStruct('InternalName', f'yt-dlp{suffix}'), | |
117 | StringStruct('LegalCopyright', 'pukkandan.ytdlp@gmail.com | UNLICENSE'), | |
118 | StringStruct('OriginalFilename', f'yt-dlp{suffix}.exe'), | |
119 | StringStruct('ProductName', f'yt-dlp{suffix}'), | |
120 | StringStruct( | |
121 | 'ProductVersion', f'{version}{suffix} on Python {platform.python_version()}'), | |
122 | ])]), VarFileInfo([VarStruct('Translation', [0, 1200])]) | |
123 | ] | |
124 | )) | |
e36d50c5 | 125 | |
0e5927ee | 126 | |
733d8e8f | 127 | if __name__ == '__main__': |
128 | main() |