]> jfr.im git - yt-dlp.git/blobdiff - pyinst.py
[extractor/playsuisse] Add extractor (#845)
[yt-dlp.git] / pyinst.py
index bc3c58ff8bf9046dc172def7cdd62ed38265715c..de3504b35544b5261563fdfe57f57ca7e83bfad6 100644 (file)
--- a/pyinst.py
+++ b/pyinst.py
@@ -5,24 +5,8 @@
 
 from PyInstaller.__main__ import run as run_pyinstaller
 
-OS_NAME = platform.system()
-if OS_NAME == 'Windows':
-    from PyInstaller.utils.win32.versioninfo import (
-        FixedFileInfo,
-        SetVersion,
-        StringFileInfo,
-        StringStruct,
-        StringTable,
-        VarFileInfo,
-        VarStruct,
-        VSVersionInfo,
-    )
-elif OS_NAME == 'Darwin':
-    pass
-else:
-    raise Exception(f'{OS_NAME} is not supported')
 
-ARCH = platform.architecture()[0][:2]
+OS_NAME, ARCH = sys.platform, platform.architecture()[0][:2]
 
 
 def main():
@@ -33,10 +17,7 @@ def main():
     if not onedir and '-F' not in opts and '--onefile' not in opts:
         opts.append('--onefile')
 
-    suffix = '_macos' if OS_NAME == 'Darwin' else '_x86' if ARCH == '32' else ''
-    final_file = 'dist/%syt-dlp%s%s' % (
-        'yt-dlp/' if onedir else '', suffix, '.exe' if OS_NAME == 'Windows' else '')
-
+    name, final_file = exe(onedir)
     print(f'Building yt-dlp v{version} {ARCH}bit for {OS_NAME} with options {opts}')
     print('Remember to update the version using  "devscripts/update-version.py"')
     if not os.path.isfile('yt_dlp/extractor/lazy_extractors.py'):
@@ -45,7 +26,7 @@ def main():
     print(f'Destination: {final_file}\n')
 
     opts = [
-        f'--name=yt-dlp{suffix}',
+        f'--name={name}',
         '--icon=devscripts/logo.ico',
         '--upx-exclude=vcruntime140.dll',
         '--noconfirm',
@@ -79,6 +60,21 @@ def read_version(fname):
         return locals()['__version__']
 
 
+def exe(onedir):
+    """@returns (name, path)"""
+    name = '_'.join(filter(None, (
+        'yt-dlp',
+        OS_NAME == 'darwin' and 'macos',
+        ARCH == '32' and 'x86'
+    )))
+    return name, ''.join(filter(None, (
+        'dist/',
+        onedir and f'{name}/',
+        name,
+        OS_NAME == 'win32' and '.exe'
+    )))
+
+
 def version_to_list(version):
     version_list = version.split('.')
     return list(map(int, version_list)) + [0] * (4 - len(version_list))
@@ -114,6 +110,17 @@ def set_version_info(exe, version):
 
 
 def windows_set_version(exe, version):
+    from PyInstaller.utils.win32.versioninfo import (
+        FixedFileInfo,
+        SetVersion,
+        StringFileInfo,
+        StringStruct,
+        StringTable,
+        VarFileInfo,
+        VarStruct,
+        VSVersionInfo,
+    )
+
     version_list = version_to_list(version)
     suffix = '_x86' if ARCH == '32' else ''
     SetVersion(exe, VSVersionInfo(