skills
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
---
|
||||
name: youtube-transcript
|
||||
description: Fetch transcripts from YouTube videos for summarization and analysis.
|
||||
---
|
||||
|
||||
# YouTube Transcript
|
||||
|
||||
Fetch transcripts from YouTube videos.
|
||||
|
||||
## Setup
|
||||
|
||||
```bash
|
||||
cd {baseDir}
|
||||
npm install
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
{baseDir}/transcript.js <video-id-or-url>
|
||||
```
|
||||
|
||||
Accepts video ID or full URL:
|
||||
- `EBw7gsDPAYQ`
|
||||
- `https://www.youtube.com/watch?v=EBw7gsDPAYQ`
|
||||
- `https://youtu.be/EBw7gsDPAYQ`
|
||||
|
||||
## Output
|
||||
|
||||
Timestamped transcript entries:
|
||||
|
||||
```
|
||||
[0:00] All right. So, I got this UniFi Theta
|
||||
[0:15] I took the camera out, painted it
|
||||
[1:23] And here's the final result
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- Requires the video to have captions/transcripts available
|
||||
- Works with auto-generated and manual transcripts
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "youtube-transcript",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"youtube-transcript-plus": "^1.0.4"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { YoutubeTranscript } from 'youtube-transcript-plus';
|
||||
|
||||
const videoId = process.argv[2];
|
||||
|
||||
if (!videoId) {
|
||||
console.error('Usage: transcript.js <video-id-or-url>');
|
||||
console.error('Example: transcript.js EBw7gsDPAYQ');
|
||||
console.error('Example: transcript.js https://www.youtube.com/watch?v=EBw7gsDPAYQ');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Extract video ID if full URL is provided
|
||||
let extractedId = videoId;
|
||||
if (videoId.includes('youtube.com') || videoId.includes('youtu.be')) {
|
||||
const match = videoId.match(/(?:v=|youtu\.be\/)([a-zA-Z0-9_-]{11})/);
|
||||
if (match) {
|
||||
extractedId = match[1];
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const transcript = await YoutubeTranscript.fetchTranscript(extractedId);
|
||||
|
||||
for (const entry of transcript) {
|
||||
const timestamp = formatTimestamp(entry.offset / 1000);
|
||||
console.log(`[${timestamp}] ${entry.text}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching transcript:', error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function formatTimestamp(seconds) {
|
||||
const h = Math.floor(seconds / 3600);
|
||||
const m = Math.floor((seconds % 3600) / 60);
|
||||
const s = Math.floor(seconds % 60);
|
||||
|
||||
if (h > 0) {
|
||||
return `${h}:${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`;
|
||||
}
|
||||
return `${m}:${s.toString().padStart(2, '0')}`;
|
||||
}
|
||||
Reference in New Issue
Block a user