🎥 Make videos programmatically with React
rip stuff out
Jonny Burgere98c48f8afdf
diff --git a/packages/renderer/src/browser.ts b/packages/renderer/src/browser.tsindex 5801f8e2c7..7eedd9be01 100644--- a/packages/renderer/src/browser.ts+++ b/packages/renderer/src/browser.ts@@ -1,3 +1,3 @@-export type Browser = 'chrome' | 'firefox';+export type Browser = 'chrome';export const DEFAULT_BROWSER: Browser = 'chrome';diff --git a/packages/renderer/src/browser/BrowserFetcher.ts b/packages/renderer/src/browser/BrowserFetcher.tsindex 4931302aa0..9515fe1e7c 100644--- a/packages/renderer/src/browser/BrowserFetcher.ts+++ b/packages/renderer/src/browser/BrowserFetcher.ts@@ -20,7 +20,6 @@ import * as fs from 'node:fs';import * as http from 'node:http';import * as os from 'node:os';import * as path from 'node:path';-import util from 'node:util';import extractZip from 'extract-zip';@@ -29,91 +28,26 @@ import {promisify} from 'node:util';import {assert} from './assert';import type {Product} from './Product';-import {deleteDirectory} from '../delete-directory';import {getDownloadsCacheDir} from './get-download-destination';-const downloadURLs: Record<Product, Partial<Record<Platform, string>>> = {- chrome: {- linux: '%s/chromium-browser-snapshots/Linux_x64/%d/%s.zip',- linux_arm: '%s/chromium-browser-snapshots/Linux_x64/%d/%s.zip',- mac: '%s/chromium-browser-snapshots/Mac/%d/%s.zip',- mac_arm:- 'https://github.com/Alex313031/Thorium-Special/releases/download/M103.0.5037.0-1/Thorium_MacOS_ARM64.dmg',- win32: '%s/chromium-browser-snapshots/Win/%d/%s.zip',- win64: '%s/chromium-browser-snapshots/Win_x64/%d/%s.zip',- },- firefox: {- linux: '%s/firefox-%s.en-US.%s-x86_64.tar.bz2',- // TODO- linux_arm: '%s/firefox-%s.en-US.%s-x86_64.tar.bz2',- mac: '%s/firefox-%s.en-US.%s.dmg',- // TODO- mac_arm: '%s/firefox-%s.en-US.%s.dmg',- win32: '%s/firefox-%s.en-US.%s.zip',- win64: '%s/firefox-%s.en-US.%s.zip',- },+const downloadURLs: Record<Platform, string> = {+ linux:+ 'https://github.com/Alex313031/thorium/releases/download/M114.0.5735.205/thorium-browser_114.0.5735.205_amd64.zip',+ mac: 'https://github.com/Alex313031/Thorium-Special/releases/download/M114.0.5735.205-1/Thorium_MacOS_X64.dmg',+ mac_arm:+ 'https://github.com/Alex313031/Thorium-Special/releases/download/M114.0.5735.205-1/Thorium_MacOS_ARM.dmg',+ win64:+ 'https://github.com/Alex313031/Thorium-Win/releases/download/M114.0.5735.205/Thorium_114.0.5735.205.zip',};-const browserConfig = {- chrome: {- host: 'https://storage.googleapis.com',- destination: '.chromium',- },- firefox: {- host: 'https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central',- destination: '.firefox',- },-} as const;--type Platform = 'linux' | 'linux_arm' | 'mac' | 'mac_arm' | 'win32' | 'win64';--function archiveName(- product: Product,- platform: Platform,- revision: string-): string {- switch (product) {- case 'chrome':- switch (platform) {- case 'linux_arm':- case 'linux':- return 'chrome-linux';- case 'mac_arm':- case 'mac':- return 'chrome-mac';- case 'win32':- case 'win64':- // Windows archive name changed at r591479.- return parseInt(revision, 10) > 591479- ? 'Thorium_107.0.5271.0\\BIN'- : 'chrome-win32';- default:- throw new Error('unknown browser');- }+type Platform = 'linux' | 'mac' | 'mac_arm' | 'win64';- case 'firefox':- return platform;- default:- throw new Error('unknown browser');- }+function archiveName(platform: Platform): string {+ return downloadURLs[platform].split('/').pop() as string;}-function _downloadURL(- product: Product,- platform: Platform,- host: string,- revision: string-): string {- if (platform === 'win64' || platform === 'win32') {- return 'https://remotionchromium-binaries.s3.eu-central-1.amazonaws.com/thorium-107.zip';- }-- return util.format(- downloadURLs[product][platform],- host,- revision,- archiveName(product, platform, revision)- );+export function getThoriumDownloadUrl(platform: Platform): string {+ return downloadURLs[platform];}const readdirAsync = fs.promises.readdir;@@ -134,7 +68,6 @@ interface BrowserFetcherRevisionInfo {executablePath: string;url: string;local: boolean;- revision: string;product: string;}@@ -144,12 +77,7 @@ export const getPlatform = (product: Product): Platform => {case 'darwin':switch (product) {case 'chrome':- return os.arch() === 'arm64' &&- PUPPETEER_EXPERIMENTAL_CHROMIUM_MAC_ARM- ? 'mac_arm'- : 'mac';- case 'firefox':- return 'mac';+ return os.arch() === 'arm64' ? 'mac_arm' : 'mac';default:throw new Error('unknown browser');}@@ -157,42 +85,37 @@ export const getPlatform = (product: Product): Platform => {case 'linux':return 'linux';case 'win32':- return os.arch() === 'x64' ? 'win64' : 'win32';+ return 'win64';default:assert(false, 'Unsupported platform: ' + platform);}};-export const getDownloadsFolder = (product: Product) => {- return path.join(getDownloadsCacheDir(), browserConfig[product].destination);-};+const destination = '.chromium';-export const getDownloadHost = (product: Product) => {- return browserConfig[product].host;+export const getDownloadsFolder = () => {+ return path.join(getDownloadsCacheDir(), destination);};export const download = async ({- revision,progressCallback,product,platform,- downloadHost,downloadsFolder,+ downloadURL,}: {- revision: string;progressCallback: (x: number, y: number) => void;product: Product;platform: Platform;- downloadHost: string;downloadsFolder: string;+ downloadURL: string;}): Promise<BrowserFetcherRevisionInfo | undefined> => {- const url = _downloadURL(product, platform, downloadHost, revision);- const fileName = url.split('/').pop();- assert(fileName, `A malformed download URL was found: ${url}.`);+ const fileName = downloadURL.split('/').pop();+ assert(fileName, `A malformed download URL was found: ${downloadURL}.`);const archivePath = path.join(downloadsFolder, fileName);- const outputPath = getFolderPath(revision, downloadsFolder, platform);+ const outputPath = getFolderPath(downloadsFolder, platform);if (await existsAsync(outputPath)) {- return getRevisionInfo(revision, product);+ return getRevisionInfo(product);}if (!(await existsAsync(downloadsFolder))) {@@ -208,7 +131,7 @@ export const download = async ({}try {- await _downloadFile(url, archivePath, progressCallback);+ await _downloadFile(downloadURL, archivePath, progressCallback);await install(archivePath, outputPath);} finally {if (await existsAsync(archivePath)) {@@ -216,7 +139,7 @@ export const download = async ({}}- const revisionInfo = getRevisionInfo(revision, product);+ const revisionInfo = getRevisionInfo(product);if (revisionInfo) {await chmodAsync(revisionInfo.executablePath, 0o755);}@@ -224,61 +147,23 @@ export const download = async ({return revisionInfo;};-export const localRevisions = async (- downloadsFolder: string,- product: Product,- platform: Platform-): Promise<string[]> => {- if (!(await existsAsync(downloadsFolder))) {- return [];- }-- const fileNames = await readdirAsync(downloadsFolder);- return fileNames- .map((fileName) => {- return parseFolderPath(product, fileName);- })- .filter(- (- entry- ): entry is {product: string; platform: string; revision: string} => {- return (entry && entry.platform === platform) ?? false;- }- )- .map((entry) => {- return entry.revision;- });-};--export const removeBrowser = async (- revision: string,- folderPath: string-): Promise<void> => {- assert(- await existsAsync(folderPath),- `Failed to remove: revision ${revision} is not downloaded`- );- deleteDirectory(folderPath);-};-export const getFolderPath = (- revision: string,downloadsFolder: string,platform: Platform): string => {- return path.resolve(downloadsFolder, `${platform}-${revision}`);+ return path.resolve(downloadsFolder, `${platform}`);};-const getExecutablePath = (product: Product, revision: string) => {- const downloadsFolder = getDownloadsFolder(product);+const getExecutablePath = (product: Product) => {+ const downloadsFolder = getDownloadsFolder();const platform = getPlatform(product);- const folderPath = getFolderPath(revision, downloadsFolder, platform);+ const folderPath = getFolderPath(downloadsFolder, platform);if (product === 'chrome') {if (platform === 'mac' || platform === 'mac_arm') {return path.join(folderPath,- archiveName(product, platform, revision),+ archiveName(platform),'Chromium.app','Contents','MacOS',@@ -287,67 +172,28 @@ const getExecutablePath = (product: Product, revision: string) => {}if (platform === 'linux') {- return path.join(- folderPath,- archiveName(product, platform, revision),- 'chrome'- );+ return path.join(folderPath, archiveName(platform), 'thorium');}- if (platform === 'win32' || platform === 'win64') {- return path.join(- folderPath,- archiveName(product, platform, revision),- 'thorium.exe'- );+ if (platform === 'win64') {+ return path.join(folderPath, archiveName(platform), 'thorium.exe');}-- throw new Error('Unsupported platform: ' + platform);- }-- if (product === 'firefox') {- if (platform === 'mac' || platform === 'mac_arm') {- return path.join(- folderPath,- 'Firefox Nightly.app',- 'Contents',- 'MacOS',- 'firefox'- );- }-- if (platform === 'linux') {- return path.join(folderPath, 'firefox', 'firefox');- }-- if (platform === 'win32' || platform === 'win64') {- return path.join(folderPath, 'firefox', 'firefox.exe');- }-- throw new Error('Unsupported platform: ' + platform);}throw new Error('Unsupported product: ' + product);};export const getRevisionInfo = (- revision: string,product: Product): BrowserFetcherRevisionInfo => {- const executablePath = getExecutablePath(product, revision);- const downloadsFolder = getDownloadsFolder(product);+ const executablePath = getExecutablePath(product);+ const downloadsFolder = getDownloadsFolder();const platform = getPlatform(product);- const folderPath = getFolderPath(revision, downloadsFolder, platform);+ const folderPath = getFolderPath(downloadsFolder, platform);- const url = _downloadURL(- product,- platform,- getDownloadHost(product),- revision- );+ const url = getThoriumDownloadUrl(platform);const local = fs.existsSync(folderPath);return {- revision,executablePath,folderPath,local,@@ -356,24 +202,6 @@ export const getRevisionInfo = (};};-function parseFolderPath(- product: Product,- folderPath: string-): {product: string; platform: string; revision: string} | undefined {- const name = path.basename(folderPath);- const splits = name.split('-');- if (splits.length !== 2) {- return;- }-- const [platform, revision] = splits;- if (!revision || !platform || !(platform in downloadURLs[product])) {- return;- }-- return {product, platform, revision};-}-function _downloadFile(url: string,destinationPath: string,@@ -543,3 +371,23 @@ function httpRequest(request.end();return request;}++function handleArm64(): void {+ let exists = fs.existsSync('/usr/bin/chromium-browser');+ if (exists) {+ return;+ }++ exists = fs.existsSync('/usr/bin/chromium');+ if (exists) {+ return;+ }++ console.error(+ 'The chromium binary is not available for arm64.' ++ '\nIf you are on Ubuntu, you can install with: ' ++ '\n\n sudo apt install chromium\n' ++ '\n\n sudo apt install chromium-browser\n'+ );+ throw new Error();+}diff --git a/packages/renderer/src/browser/Launcher.ts b/packages/renderer/src/browser/Launcher.tsindex 6f510886b8..ceffdcbda6 100644--- a/packages/renderer/src/browser/Launcher.ts+++ b/packages/renderer/src/browser/Launcher.ts@@ -36,12 +36,6 @@ export interface ProductLauncher {}export class ChromeLauncher implements ProductLauncher {- _preferredRevision: string;-- constructor(preferredRevision: string) {- this._preferredRevision = preferredRevision;- }-async launch(options: PuppeteerNodeLaunchOptions): Promise<HeadlessBrowser> {const {args = [],@@ -137,9 +131,9 @@ function resolveExecutablePath(launcher: ChromeLauncher): {executablePath: string;missingText?: string;} {- const {product, _preferredRevision} = launcher;+ const {product} = launcher;- const revisionInfo = getRevisionInfo(_preferredRevision, 'chrome');+ const revisionInfo = getRevisionInfo('chrome');const firefoxHelp = `Run \`PUPPETEER_PRODUCT=firefox npm install\` to download a supported Firefox browser binary.`;const chromeHelp = `Run \`npm install\` to download the correct Chromium revision.`;diff --git a/packages/renderer/src/browser/Product.ts b/packages/renderer/src/browser/Product.tsindex 312b17ce80..7a7e0751a2 100644--- a/packages/renderer/src/browser/Product.ts+++ b/packages/renderer/src/browser/Product.ts@@ -14,4 +14,4 @@* limitations under the License.*/-export type Product = 'chrome' | 'firefox';+export type Product = 'chrome';diff --git a/packages/renderer/src/browser/PuppeteerNode.ts b/packages/renderer/src/browser/PuppeteerNode.tsindex dff2e16027..4add7c744e 100644--- a/packages/renderer/src/browser/PuppeteerNode.ts+++ b/packages/renderer/src/browser/PuppeteerNode.ts@@ -23,7 +23,6 @@ import type {LaunchOptions,} from './LaunchOptions';import type {Product} from './Product';-import {PUPPETEER_REVISIONS} from './revisions';interface PuppeteerLaunchOptionsextends LaunchOptions,@@ -37,12 +36,9 @@ export class PuppeteerNode {#lazyLauncher?: ProductLauncher;#productName?: Product;- _preferredRevision: string;-- constructor(settings: {preferredRevision: string; productName?: Product}) {- const {preferredRevision, productName} = settings;+ constructor(settings: {productName?: Product}) {+ const {productName} = settings;this.#productName = productName;- this._preferredRevision = preferredRevision;this.launch = this.launch.bind(this);this.executablePath = this.executablePath.bind(this);@@ -65,13 +61,7 @@ export class PuppeteerNode {!this.#lazyLauncher ||this.#lazyLauncher.product !== this.#productName) {- switch (this.#productName) {- case 'chrome':- default:- this._preferredRevision = PUPPETEER_REVISIONS.chromium;- }-- this.#lazyLauncher = new ChromeLauncher(this._preferredRevision);+ this.#lazyLauncher = new ChromeLauncher();}return this.#lazyLauncher;diff --git a/packages/renderer/src/browser/create-browser-fetcher.ts b/packages/renderer/src/browser/create-browser-fetcher.tsindex b804ad8e81..ec08fe4aa6 100644--- a/packages/renderer/src/browser/create-browser-fetcher.ts+++ b/packages/renderer/src/browser/create-browser-fetcher.ts@@ -14,74 +14,38 @@* limitations under the License.*/+import {Log} from '../logger';import {download,- getDownloadHost,getDownloadsFolder,- getFolderPath,getPlatform,getRevisionInfo,- localRevisions,- removeBrowser,+ getThoriumDownloadUrl,} from './BrowserFetcher';import type {Product} from './Product';-import {PUPPETEER_REVISIONS} from './revisions';const supportedProducts = {chrome: 'Chromium',- firefox: 'Firefox Nightly',} as const;-function getRevision(product: Product): string {- if (product === 'chrome') {- return PUPPETEER_REVISIONS.chromium;- }-- throw new Error(`Unsupported product ${product}`);-}-export async function downloadBrowser(product: Product): Promise<void> {- const revision = getRevision(product);- const revisionInfo = getRevisionInfo(revision, product);+ const revisionInfo = getRevisionInfo(product);await download({- revision: revisionInfo.revision,progressCallback: (downloadedBytes, totalBytes) => {- console.log(- 'Downloading',- supportedProducts[product],+ Log.info(+ 'Downloading Thorium',toMegabytes(downloadedBytes) + '/' + toMegabytes(totalBytes));},product,platform: getPlatform(product),- downloadHost: getDownloadHost(product),- downloadsFolder: getDownloadsFolder(product),+ downloadsFolder: getDownloadsFolder(),+ downloadURL: getThoriumDownloadUrl(getPlatform(product)),});- const _localRevisions = await localRevisions(- getDownloadsFolder(product),- product,- getPlatform(product)- );- console.log(- `${supportedProducts[product]} (${revisionInfo.revision}) downloaded to ${revisionInfo.folderPath}`- );- await Promise.all(- _localRevisions- .filter((__revision) => {- return __revision !== revisionInfo.revision;- })- .map((__revision) => {- return removeBrowser(- __revision,- getFolderPath(- revision,- getDownloadsFolder(product),- getPlatform(product)- )- );- })+ Log.info(+ `${supportedProducts[product]} (${revisionInfo.url}) downloaded to ${revisionInfo.folderPath}`);}diff --git a/packages/renderer/src/browser/node.ts b/packages/renderer/src/browser/node.tsindex 8360cddb30..5a12ad25bc 100644--- a/packages/renderer/src/browser/node.ts+++ b/packages/renderer/src/browser/node.ts@@ -1,7 +1,5 @@import {PuppeteerNode} from './PuppeteerNode';-import {PUPPETEER_REVISIONS} from './revisions';export const puppeteer = new PuppeteerNode({- preferredRevision: PUPPETEER_REVISIONS.chromium,productName: undefined,});diff --git a/packages/renderer/src/browser/revisions.ts b/packages/renderer/src/browser/revisions.tsdeleted file mode 100644index c3acf1cfb1..0000000000--- a/packages/renderer/src/browser/revisions.ts+++ /dev/null@@ -1,23 +0,0 @@-/**- * Copyright 2020 Google Inc. All rights reserved.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--type Revisions = Readonly<{- readonly chromium: string;-}>;--export const PUPPETEER_REVISIONS: Revisions = {- chromium: '1002410',-};diff --git a/packages/renderer/src/get-local-browser-executable.ts b/packages/renderer/src/get-local-browser-executable.tsindex ef21e7042a..835cc8a478 100644--- a/packages/renderer/src/get-local-browser-executable.ts+++ b/packages/renderer/src/get-local-browser-executable.ts@@ -5,7 +5,6 @@ import type {BrowserExecutable} from './browser-executable';import {getRevisionInfo} from './browser/BrowserFetcher';import {downloadBrowser} from './browser/create-browser-fetcher';import type {Product} from './browser/Product';-import {PUPPETEER_REVISIONS} from './browser/revisions';const getSearchPathsForProduct = (product: Product) => {if (product === 'chrome') {@@ -43,10 +42,6 @@ const getSearchPathsForProduct = (product: Product) => {].filter(Boolean) as string[];}- if (product === 'firefox') {- return [].filter(Boolean) as string[];- }-throw new TypeError(`Unknown browser product: ${product}`);};@@ -98,7 +93,7 @@ const getBrowserStatus = (return {path: localBrowser, type: 'local-browser'};}- const revision = getRevisionInfo(PUPPETEER_REVISIONS.chromium, product);+ const revision = getRevisionInfo(product);if (revision.local && fs.existsSync(revision.executablePath)) {return {path: revision.executablePath, type: 'local-puppeteer-browser'};}diff --git a/packages/renderer/src/open-browser.ts b/packages/renderer/src/open-browser.tsindex 92e56cb95d..67f872fbd1 100644--- a/packages/renderer/src/open-browser.ts+++ b/packages/renderer/src/open-browser.ts@@ -75,6 +75,7 @@ export const internalOpenBrowser = async ({viewport,logLevel,}: InternalOpenBrowserOptions): Promise<HeadlessBrowser> => {+ // @ts-expect-error Firefoxif (browser === 'firefox') {throw new TypeError('Firefox supported is not yet turned on. Stay tuned for the future.'