Some tooling cleanup

This commit is contained in:
Brahim Hadriche committed 2023-07-05 21:00:10 -04:00
1 parent 80bcd4c870
commit 70d66f874d
17 files changed
+145 -46

No files matched your search

File renamed without changes.
+3
View File
@@ -1,3 +1,6 @@
// Description: Generates images for the project.
// Converts SVGs to PNGs and resizes them to the correct dimensions.
const fs = require('fs');
const path = require('path');
const { convertFile } = require('convert-svg-to-png');
+15 -4
View File
@@ -1,14 +1,25 @@
// Description: Generates the SponsorBlock config for Playlet
const fs = require('fs');
const path = require('path');
const { ArgumentParser } = require('argparse')
if (process.argv.length !== 3) {
console.error("Invalid usage! usage: npm run generate-sponsorblock-config -- sponsorblock_root");
exit(-1);
function getArgumentParser() {
const parser = new ArgumentParser({
description: 'Generate SponsorBlock config'
});
parser.add_argument('--sponsorblock-root', { help: 'Local path to the SponsorBlock repository', required: true });
return parser;
}
const parser = getArgumentParser();
const args = parser.parse_args()
const PLAYLEY_CONFIG_PATH = "./playlet-lib/src/config/sponsorblock_config.json"
const sponsorblockRoot = process.argv[2];
const sponsorblockRoot = args.sponsorblock_root;
const configExamplePath = path.join(sponsorblockRoot, "config.json.example")
const englishLocalePath = path.join(sponsorblockRoot, "public/_locales/en/messages.json")
+13 -4
View File
@@ -1,14 +1,23 @@
const dotenv = require('dotenv');
const fs = require('fs');
const path = require('path');
const envFile = path.join(__dirname, '../.env');
function getEnvVars() {
let envVars = process.env;
if (fs.existsSync('.vscode/.env')) {
const envConfig = dotenv.parse(fs.readFileSync('.vscode/.env'));
if (fs.existsSync(envFile)) {
const envConfig = dotenv.parse(fs.readFileSync(envFile));
envVars = { ...envVars, ...envConfig };
}
return envVars;
}
module.exports = getEnvVars;
if (typeof module !== 'undefined' && module.exports) {
module.exports = getEnvVars;
}
if (typeof exports !== 'undefined') {
exports.getEnvVars = getEnvVars;
}
+20 -13
View File
@@ -1,5 +1,5 @@
// This script reads recommendations, subscriptions, watch later, liked, and history from Youtube
// and imports them into invidious.
// Description: Read recommendations, subscriptions, watch later, liked, and history from Youtube
// and import them into invidious. Requires yt-dlp to be installed.
const { ArgumentParser } = require('argparse')
const fs = require('fs');
@@ -7,6 +7,20 @@ const getEnvVars = require('./get-env-vars');
const spawn = require('child_process').spawn;
const express = require('express')
const ip = require('ip');
const fetch = require('cross-fetch');
function getArgumentParser() {
const parser = new ArgumentParser({
description: 'Sync Youtube profile with Invidious'
});
parser.add_argument('--browser', { help: 'Use cookies from browser' });
parser.add_argument('--invidious', { help: 'Invidious instance to sync to' });
parser.add_argument('--output-file', { help: 'Write profile to Invidious JSON compatible file' });
parser.add_argument('--playlist-limit', { help: 'Maximum playlist video count', default: 500 });
return parser;
}
const config = getEnvVars();
const PLAYLEY_SERVER = `http://${config.ROKU_DEV_TARGET}:8888`;
@@ -167,8 +181,8 @@ async function getInvidiousInstance() {
throw new Error("Playlet not logged in")
}
console.log(`Invidious instance: ${state.invidious.logged_in_instance}`)
return state.invidious.logged_in_instance;
console.log(`Invidious instance: ${state.invidious.current_instance}`)
return state.invidious.current_instance;
}
async function getAccessToken(invidiousInstance) {
@@ -216,16 +230,9 @@ async function deleteAccessToken(invidiousInstance, token) {
let invidiousInstance = undefined
let token = undefined;
try {
const parser = new ArgumentParser({
description: 'Sync Youtube profile with Invidious'
});
const parser = getArgumentParser()
const args = parser.parse_args()
parser.add_argument('--browser', { help: 'Use cookies from browser' });
parser.add_argument('--invidious', { help: 'Invidious instance to sync to' });
parser.add_argument('--output-file', { help: 'Write profile to Invidious JSON compatible file' });
parser.add_argument('--playlist-limit', { help: 'Maximum playlist video count', default: 500 });
let args = parser.parse_args()
invidiousInstance = args.invidious
browser = args.browser
outputFile = args.output_file
+16 -5
View File
@@ -1,14 +1,24 @@
// Description: Take a screenshot of the Roku device
const { ArgumentParser } = require('argparse')
const rokuDeploy = require('roku-deploy');
const fs = require('fs');
const { exit } = require('process');
const getEnvVars = require('./get-env-vars');
if(process.argv.length !== 3) {
console.error("Invalid usage! usage: npm run screenshot -- filename");
exit(-1);
function getArgumentParser() {
const parser = new ArgumentParser({
description: 'Take a screenshot of the Roku device'
});
parser.add_argument('filename', { help: 'Path where the screenshot will be saved (without extension)' });
return parser;
}
const filename = process.argv[2];
const parser = getArgumentParser();
const args = parser.parse_args()
const filename = args.filename;
const config = getEnvVars();
const options = {
@@ -25,5 +35,6 @@ const options = {
}
catch (error) {
console.error(error);
throw error;
}
})();
+7
View File
@@ -1,3 +1,6 @@
// Description: Publish, sign the package and retrieve it from the Roku device
// It expects release/playelt.zip to exist
const getEnvVars = require('./get-env-vars');
const rokuDeploy = require('roku-deploy');
@@ -16,12 +19,16 @@ const options = {
(async () => {
try {
// Sideload playlet.zip
await rokuDeploy.publish(options);
// Sign the package
const remotePkgPath = await rokuDeploy.signExistingPackage(options);
// Retrieve the signed package
const localPkgFilePath = await rokuDeploy.retrieveSignedPackage(remotePkgPath, options);
console.log(`Created signed package: ${localPkgFilePath}`)
}
catch (error) {
console.error(error);
throw error;
}
})();
+4
View File
@@ -1,3 +1,7 @@
// Description: Updates the git commit hash in the manifest files.
// It will update both Playlet and Playlet-lib manifest files.
// It will abort if there are any changes in the working directory.
const fs = require('fs');
const shell = require('shelljs');
+4
View File
@@ -1,3 +1,7 @@
// Description: Updates the version in the manifest files.
// Reads the version from the root package.json and updates the manifest files,
// as well as the package.json files in the playlet-web folder.
const fs = require('fs');
const { execSync } = require("child_process");