Created
April 16, 2025 09:08
-
-
Save dsebastien/a41fed9f67932bddbf30c6bade7ae2f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
// Input and output file paths | |
const inputFilePath = process.argv[2]; // First command-line argument | |
const baseName = path.basename(inputFilePath, path.extname(inputFilePath)); | |
const outputFilePath = path.join(path.dirname(inputFilePath), `${baseName} - YouTube.txt`); | |
// Check if input file path is provided | |
if (!inputFilePath) { | |
console.error('Please provide the path to the CSV file as an argument'); | |
console.error('Usage: node process-markers.js <input-file-path> [output-file-path]'); | |
process.exit(1); | |
} | |
// Process the file | |
try { | |
// Read the file content | |
const fileContent = fs.readFileSync(inputFilePath, 'utf16le'); // Adobe Premiere often exports UTF-16LE | |
// Split content into lines | |
const lines = fileContent.split('\n'); | |
// Remove the first line (header) and then process each line | |
const contentLines = lines.slice(1); | |
// Process each line | |
const processedLines = contentLines.map(line => { | |
// Skip empty lines | |
if (!line.trim()) return ''; | |
// Split the line by tabs | |
const columns = line.split('\t'); | |
// Extract the marker name (first column) | |
let markerName = columns[0] || ''; | |
// Extract the in timestamp (third column) and format it | |
let inTimestamp = ''; | |
if (columns[2]) { | |
// Extract just the hh:mm:ss part | |
const timeMatch = columns[2].match(/\d{2}:\d{2}:\d{2}/); | |
inTimestamp = timeMatch ? timeMatch[0] : columns[2]; | |
} | |
// Combine the marker name and formatted timestamp with a single space | |
return `${markerName} ${inTimestamp}`.trim(); | |
}); | |
// Join processed lines and write to output file | |
fs.writeFileSync(outputFilePath, processedLines.join('\n')); | |
console.log(`Processing complete! Output saved to: ${outputFilePath}`); | |
console.log(`Original file: ${inputFilePath}`); | |
console.log(`Generated text file: ${outputFilePath}`); | |
} catch (error) { | |
console.error('Error processing the file:', error.message); | |
process.exit(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment