-------------------------- <!DOCTYPE html> <html> <head> <title>Extract Timestamps</title> </head> <body> Extract Timestamps from YT Videodescriptions<br> <br> <label for="apiKey">API Key:</label> <input type="password" id="apiKey"> <label for="videoUrl">YouTube Video URL:</label> <input type="text" id="videoUrl" placeholder="yturl"> <input type="text" id="videolength" placeholder="videolength" style="width: 60px;"> <button onclick="extractTimestamps()">Extract Timestamps</button> <br><br><textarea id="timestamps" rows="10" cols="50"></textarea> <script> function extractTimestamps() { var apiKey = document.getElementById("apiKey").value; var videoUrl = document.getElementById("videoUrl").value; if (!apiKey || !videoUrl) { alert("Please enter the API key and video URL."); return; } var videoId = extractVideoId(videoUrl); var apiUrl = `https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&id=${videoId}&key=${apiKey}`; fetch(apiUrl) .then(response => response.json()) .then(data => { var description = data.items[0].snippet.description; var timestampsAndTitles = extractTimestampsAndTitles(description); var timestampsTextArea = document.getElementById("timestamps"); timestampsTextArea.value = timestampsAndTitles .map(item => `${item.timestamp} ${item.title}`) .join("\n"); var videoDuration = data.items[0].contentDetails.duration; var videoLength = convertISO8601Duration(videoDuration); var videoLengthInput = document.getElementById("videolength"); videoLengthInput.value = videoLength; }) .catch(error => { console.error("Error fetching video details:", error); alert("Error fetching video details. Please check the API key and video URL."); }); } function extractTimestampsAndTitles(description) { var regex = /(\d{1,2}:\d{2}(?::\d{2})?)\s+(.+)/g; var results = []; var match; while ((match = regex.exec(description)) !== null) { var timestamp = match[1]; var title = match[2]; results.push({ timestamp: timestamp, title: title }); } return results; } function extractVideoId(url) { var videoId = ""; var regexPatterns = [ /youtu\.be\/([\w-]+)/, /youtube\.com\/watch\?v=([\w-]+)/, /youtube\.com\/embed\/([\w-]+)/, /youtube\.com\/v\/([\w-]+)/, /youtube\.com\/watch\?.*v=([\w-]+)/ ]; for (var i = 0; i < regexPatterns.length; i++) { var match = url.match(regexPatterns[i]); if (match && match[1]) { videoId = match[1]; break; } } return videoId; } function convertISO8601Duration(duration) { var match = duration.match(/PT(\d+H)?(\d+M)?(\d+S)?/); var hours = match[1] ? parseInt(match[1]) : 0; var minutes = match[2] ? parseInt(match[2]) : 0; var seconds = match[3] ? parseInt(match[3]) : 0; // Format the length as xx:xx var formattedLength = ""; if (hours > 0) { formattedLength += hours.toString().padStart(2, "0") + ":"; } formattedLength += minutes.toString().padStart(2, "0") + ":"; formattedLength += seconds.toString().padStart(2, "0"); return formattedLength; } </script> </body> </html> <hr> <details><summary>Generate FFMPEG</summary> FFMPEG GEnerator <h1>FFmpeg Command Generator</h1> <!--<label for="timestamps">Timestamps:</label><br> <textarea id="timestamps" rows="10" cols="50"></textarea><br><br>--> <label for="sourcefilename">Source Filename:</label><br> <input type="text" id="sourcefilename"><br><br> <button id="submit">Generate Commands</button> <button onclick="replaceText()">Replace Text</button></details><br><br> <pre id="commands"></pre> <script> var timestampsTextarea = document.getElementById('timestamps'); var sourceFilenameTextbox = document.getElementById('sourcefilename'); var submitButton = document.getElementById('submit'); submitButton.addEventListener('click', function() { var timestampsValue = timestampsTextarea.value; var lines = timestampsValue.split('\n'); var sourceFilename = sourceFilenameTextbox.value; var ffmpegCommands = []; for (var i = 0; i < lines.length; i++) { var line = lines[i]; var parts = line.split(' '); var timestamp = parts[0]; var name = parts.slice(1).join(' '); // Generate the FFmpeg command var ffmpegCommand = 'ffmpeg -i "' + sourceFilename + '" -ss ' + timestamp + ' -to ' + (i < lines.length - 1 ? lines[i + 1].split(' ')[0] : '') + ' -c copy "' + name + '.mp3"'; ffmpegCommands.push(ffmpegCommand);} var commandsElement = document.getElementById('commands'); commandsElement.textContent = ffmpegCommands.join('\n'); }); </script> <script> function replaceText() { var commandsElement = document.getElementById("commands"); var videolength = document.getElementById("videolength").value; commandsElement.innerHTML = commandsElement.innerHTML.replace(/-to -c/g, "-to " + videolength + " -c");} </script> </plaintext>