]>
Commit | Line | Data |
---|---|---|
cc52de43 | 1 | #!/usr/bin/env python3 |
ff88a05c | 2 | # coding: utf-8 |
3 | ||
e38df8f9 | 4 | from __future__ import unicode_literals |
5 | import sys | |
ff88a05c | 6 | import platform |
e38df8f9 | 7 | |
e36d50c5 | 8 | from PyInstaller.utils.hooks import collect_submodules |
e38df8f9 | 9 | from PyInstaller.utils.win32.versioninfo import ( |
10 | VarStruct, VarFileInfo, StringStruct, StringTable, | |
11 | StringFileInfo, FixedFileInfo, VSVersionInfo, SetVersion, | |
12 | ) | |
13 | import PyInstaller.__main__ | |
14 | ||
5d535b4a | 15 | arch = platform.architecture()[0][:2] |
ff88a05c | 16 | assert arch in ('32', '64') |
ff88a05c | 17 | _x86 = '_x86' if arch == '32' else '' |
e38df8f9 | 18 | |
5d535b4a | 19 | # Compatability with older arguments |
20 | opts = sys.argv[1:] | |
21 | if opts[0:1] in (['32'], ['64']): | |
22 | if arch != opts[0]: | |
23 | raise Exception(f'{opts[0]}bit executable cannot be built on a {arch}bit system') | |
24 | opts = opts[1:] | |
25 | opts = opts or ['--onefile'] | |
26 | ||
4c88ff87 | 27 | print(f'Building {arch}bit version with options {opts}') |
28 | ||
cc1dfc93 | 29 | FILE_DESCRIPTION = 'yt-dlp%s' % (' (32 Bit)' if _x86 else '') |
e38df8f9 | 30 | |
7a5c1cfe | 31 | exec(compile(open('yt_dlp/version.py').read(), 'yt_dlp/version.py', 'exec')) |
e38df8f9 | 32 | VERSION = locals()['__version__'] |
33 | ||
3dd264bf | 34 | VERSION_LIST = VERSION.split('.') |
e38df8f9 | 35 | VERSION_LIST = list(map(int, VERSION_LIST)) + [0] * (4 - len(VERSION_LIST)) |
36 | ||
37 | print('Version: %s%s' % (VERSION, _x86)) | |
38 | print('Remember to update the version using devscipts\\update-version.py') | |
39 | ||
40 | VERSION_FILE = VSVersionInfo( | |
41 | ffi=FixedFileInfo( | |
42 | filevers=VERSION_LIST, | |
43 | prodvers=VERSION_LIST, | |
44 | mask=0x3F, | |
45 | flags=0x0, | |
46 | OS=0x4, | |
47 | fileType=0x1, | |
48 | subtype=0x0, | |
49 | date=(0, 0), | |
50 | ), | |
51 | kids=[ | |
52 | StringFileInfo([ | |
53 | StringTable( | |
ff88a05c | 54 | '040904B0', [ |
7a5c1cfe P |
55 | StringStruct('Comments', 'yt-dlp%s Command Line Interface.' % _x86), |
56 | StringStruct('CompanyName', 'https://github.com/yt-dlp'), | |
ff88a05c | 57 | StringStruct('FileDescription', FILE_DESCRIPTION), |
58 | StringStruct('FileVersion', VERSION), | |
7a5c1cfe | 59 | StringStruct('InternalName', 'yt-dlp%s' % _x86), |
e38df8f9 | 60 | StringStruct( |
ff88a05c | 61 | 'LegalCopyright', |
7a5c1cfe | 62 | 'pukkandan.ytdlp@gmail.com | UNLICENSE', |
e38df8f9 | 63 | ), |
7a5c1cfe P |
64 | StringStruct('OriginalFilename', 'yt-dlp%s.exe' % _x86), |
65 | StringStruct('ProductName', 'yt-dlp%s' % _x86), | |
56ce9eb8 NA |
66 | StringStruct( |
67 | 'ProductVersion', | |
68 | '%s%s on Python %s' % (VERSION, _x86, platform.python_version())), | |
e38df8f9 | 69 | ])]), |
ff88a05c | 70 | VarFileInfo([VarStruct('Translation', [0, 1200])]) |
e38df8f9 | 71 | ] |
72 | ) | |
73 | ||
49e7e9c3 | 74 | |
75 | def pycryptodome_module(): | |
76 | try: | |
77 | import Cryptodome # noqa: F401 | |
78 | except ImportError: | |
79 | try: | |
80 | import Crypto # noqa: F401 | |
81 | print('WARNING: Using Crypto since Cryptodome is not available. ' | |
82 | 'Install with: pip install pycryptodomex', file=sys.stderr) | |
83 | return 'Crypto' | |
84 | except ImportError: | |
85 | pass | |
86 | return 'Cryptodome' | |
87 | ||
88 | ||
89 | dependancies = [pycryptodome_module(), 'mutagen'] + collect_submodules('websockets') | |
e36d50c5 | 90 | excluded_modules = ['test', 'ytdlp_plugins', 'youtube-dl', 'youtube-dlc'] |
91 | ||
e38df8f9 | 92 | PyInstaller.__main__.run([ |
7a5c1cfe | 93 | '--name=yt-dlp%s' % _x86, |
1aebc0f7 | 94 | '--icon=devscripts/logo.ico', |
e36d50c5 | 95 | *[f'--exclude-module={module}' for module in excluded_modules], |
96 | *[f'--hidden-import={module}' for module in dependancies], | |
46261325 | 97 | '--upx-exclude=vcruntime140.dll', |
4c88ff87 | 98 | '--noconfirm', |
99 | *opts, | |
7a5c1cfe | 100 | 'yt_dlp/__main__.py', |
e38df8f9 | 101 | ]) |
5d535b4a | 102 | SetVersion('dist/%syt-dlp%s.exe' % ('yt-dlp/' if '--onedir' in opts else '', _x86), VERSION_FILE) |