]> jfr.im git - yt-dlp.git/blame - pyinst.py
[docs,build] Change all pycryptodome references to pycryptodomex
[yt-dlp.git] / pyinst.py
CommitLineData
cc52de43 1#!/usr/bin/env python3
ff88a05c 2# coding: utf-8
3
e38df8f9 4from __future__ import unicode_literals
5import sys
ff88a05c 6import platform
e38df8f9 7
e36d50c5 8from PyInstaller.utils.hooks import collect_submodules
e38df8f9 9from PyInstaller.utils.win32.versioninfo import (
10 VarStruct, VarFileInfo, StringStruct, StringTable,
11 StringFileInfo, FixedFileInfo, VSVersionInfo, SetVersion,
12)
13import PyInstaller.__main__
14
5d535b4a 15arch = platform.architecture()[0][:2]
ff88a05c 16assert arch in ('32', '64')
ff88a05c 17_x86 = '_x86' if arch == '32' else ''
e38df8f9 18
5d535b4a 19# Compatability with older arguments
20opts = sys.argv[1:]
21if 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:]
25opts = opts or ['--onefile']
26
4c88ff87 27print(f'Building {arch}bit version with options {opts}')
28
cc1dfc93 29FILE_DESCRIPTION = 'yt-dlp%s' % (' (32 Bit)' if _x86 else '')
e38df8f9 30
7a5c1cfe 31exec(compile(open('yt_dlp/version.py').read(), 'yt_dlp/version.py', 'exec'))
e38df8f9 32VERSION = locals()['__version__']
33
3dd264bf 34VERSION_LIST = VERSION.split('.')
e38df8f9 35VERSION_LIST = list(map(int, VERSION_LIST)) + [0] * (4 - len(VERSION_LIST))
36
37print('Version: %s%s' % (VERSION, _x86))
38print('Remember to update the version using devscipts\\update-version.py')
39
40VERSION_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
75def 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
89dependancies = [pycryptodome_module(), 'mutagen'] + collect_submodules('websockets')
e36d50c5 90excluded_modules = ['test', 'ytdlp_plugins', 'youtube-dl', 'youtube-dlc']
91
e38df8f9 92PyInstaller.__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 102SetVersion('dist/%syt-dlp%s.exe' % ('yt-dlp/' if '--onedir' in opts else '', _x86), VERSION_FILE)