]> jfr.im git - yt-dlp.git/blob - pyinst.py
Do not verify thumbnail URLs by default
[yt-dlp.git] / pyinst.py
1 #!/usr/bin/env python3
2 # coding: utf-8
3
4 from __future__ import unicode_literals
5 import sys
6 import platform
7
8 from PyInstaller.utils.hooks import collect_submodules
9 from PyInstaller.utils.win32.versioninfo import (
10 VarStruct, VarFileInfo, StringStruct, StringTable,
11 StringFileInfo, FixedFileInfo, VSVersionInfo, SetVersion,
12 )
13 import PyInstaller.__main__
14
15 arch = platform.architecture()[0][:2]
16 assert arch in ('32', '64')
17 _x86 = '_x86' if arch == '32' else ''
18
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
27 print(f'Building {arch}bit version with options {opts}')
28
29 FILE_DESCRIPTION = 'yt-dlp%s' % (' (32 Bit)' if _x86 else '')
30
31 exec(compile(open('yt_dlp/version.py').read(), 'yt_dlp/version.py', 'exec'))
32 VERSION = locals()['__version__']
33
34 VERSION_LIST = VERSION.split('.')
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(
54 '040904B0', [
55 StringStruct('Comments', 'yt-dlp%s Command Line Interface.' % _x86),
56 StringStruct('CompanyName', 'https://github.com/yt-dlp'),
57 StringStruct('FileDescription', FILE_DESCRIPTION),
58 StringStruct('FileVersion', VERSION),
59 StringStruct('InternalName', 'yt-dlp%s' % _x86),
60 StringStruct(
61 'LegalCopyright',
62 'pukkandan.ytdlp@gmail.com | UNLICENSE',
63 ),
64 StringStruct('OriginalFilename', 'yt-dlp%s.exe' % _x86),
65 StringStruct('ProductName', 'yt-dlp%s' % _x86),
66 StringStruct(
67 'ProductVersion',
68 '%s%s on Python %s' % (VERSION, _x86, platform.python_version())),
69 ])]),
70 VarFileInfo([VarStruct('Translation', [0, 1200])])
71 ]
72 )
73
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')
90 excluded_modules = ['test', 'ytdlp_plugins', 'youtube-dl', 'youtube-dlc']
91
92 PyInstaller.__main__.run([
93 '--name=yt-dlp%s' % _x86,
94 '--icon=devscripts/logo.ico',
95 *[f'--exclude-module={module}' for module in excluded_modules],
96 *[f'--hidden-import={module}' for module in dependancies],
97 '--upx-exclude=vcruntime140.dll',
98 '--noconfirm',
99 *opts,
100 'yt_dlp/__main__.py',
101 ])
102 SetVersion('dist/%syt-dlp%s.exe' % ('yt-dlp/' if '--onedir' in opts else '', _x86), VERSION_FILE)