38 lines
868 B
Bash
Executable File
38 lines
868 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# Check if URL is provided
|
|
if [ -z "$1" ]; then
|
|
echo "Usage: $0 <youtube_video_url>"
|
|
exit 1
|
|
fi
|
|
|
|
URL=$1
|
|
VIDEO_ID=$(echo $URL | grep -o 'v=[^&]*' | cut -d '=' -f 2)
|
|
if [ -z "$VIDEO_ID" ]; then
|
|
VIDEO_ID=$(echo $URL | grep -o '[^/]*$')
|
|
fi
|
|
OUTPUT_FILE="${VIDEO_ID}.txt"
|
|
|
|
# Create a temporary Node.js script
|
|
cat << EOF > fetch_transcript.js
|
|
const { YoutubeTranscript } = require('youtube-transcript');
|
|
const fs = require('fs');
|
|
|
|
YoutubeTranscript.fetchTranscript('$VIDEO_ID')
|
|
.then(transcript => {
|
|
const transcriptText = transcript.map(item => item.text).join('\\n');
|
|
fs.writeFileSync('$OUTPUT_FILE', transcriptText);
|
|
console.log('Transcript saved to $OUTPUT_FILE');
|
|
})
|
|
.catch(err => {
|
|
console.error('Error fetching transcript:', err);
|
|
});
|
|
EOF
|
|
|
|
# Run the Node.js script
|
|
node fetch_transcript.js
|
|
|
|
# Clean up
|
|
rm fetch_transcript.js
|
|
|