Update 2025-04-12_09:56:11
This commit is contained in:
37
fetch_transcript.sh
Executable file
37
fetch_transcript.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/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
|
||||
|
Reference in New Issue
Block a user