### Install Ragtitles npm Package
Source: https://github.com/andraz/ragtitles/blob/main/README.md
Installs the ragtitles npm package using npm. This is the first step to using the module in your project.
```bash
npm install ragtitles
```
--------------------------------
### AI Model Prompt for Video Analysis
Source: https://github.com/andraz/ragtitles/blob/main/README.md
This example demonstrates a prompt for the 'gemini-1.5-pro-exp-0801' model, designed to identify interesting segments within a time-stamped video transcript. It instructs the model to find key moments, provide approximate minute markers, and suggest topics for those minutes. The provided transcript snippet shows the expected input format.
```text
using the provided seconds offset prefixed transcript, find the most interesting parts of the video and give me the approximate minute in the video I should focus on and topic in that minute
0 this was the very first transistor and
2 it was made in
3 1947 by 1978 the industry had Advanced
[... rest of transcript ...]
```
--------------------------------
### Get First 10 Ragtitles with Timestamps from YouTube URL (Bash)
Source: https://github.com/andraz/ragtitles/blob/main/README.md
Downloads subtitles from a YouTube URL, converts them to ragtitles format with timestamps, and then uses the 'head' command to display only the first 10 lines. This is useful for quickly previewing subtitle content.
```bash
npx tsx cli.ts https://www.youtube.com/watch?v=RuVS7MsQk4Y --time | head -n 10
```
--------------------------------
### Convert Timestamp to Seconds with JavaScript
Source: https://context7.com/andraz/ragtitles/llms.txt
Parses VTT timestamp strings and converts them to integer seconds from the video start. It takes a VTT timestamp string (e.g., '00:00:45.320 --> 00:00:47.100') as input and returns the start time in seconds as an integer, or null if the timestamp is invalid. Dependencies include the 'ragtitles/src/convertStartTime' module.
```javascript
import convertStartTime from 'ragtitles/src/convertStartTime'
const timestamp1 = convertStartTime('00:00:45.320 --> 00:00:47.100')
console.log(timestamp1) // Output: 45
const timestamp2 = convertStartTime('01:23:15.890 --> 01:23:18.200')
console.log(timestamp2) // Output: 4995
const invalid = convertStartTime('invalid timestamp')
console.log(invalid) // Output: null
```
--------------------------------
### Get SponsorBlock Segments for YouTube Videos
Source: https://context7.com/andraz/ragtitles/llms.txt
Retrieve spam segments (sponsors, intros, outros, self-promos) for any YouTube video using the SponsorBlock API. Allows filtering by specific segment categories.
```javascript
import getSegments from 'ragtitles/src/sponsorblock'
// Get all spam segments for a video
const segments = await getSegments('https://www.youtube.com/watch?v=UPrkC1LdlLY')
console.log(segments)
// Output:
// [
// { category: "preview", start: 0, end: 7 },
// { category: "selfpromo", start: 296, end: 323 },
// { category: "sponsor", start: 1279, end: 1326 },
// { category: "outro", start: 1935, end: 1940 }
// ]
// Filter by specific categories
const onlySponsors = await getSegments(
'https://www.youtube.com/watch?v=UPrkC1LdlLY',
['sponsor'],
['skip']
)
// CLI usage
npx tsx src/sponsorblock.ts https://www.youtube.com/watch?v=UPrkC1LdlLY
```
--------------------------------
### Filter YouTube Spam with Ragtitles CLI
Source: https://github.com/andraz/ragtitles/blob/main/README.md
Execute the Ragtitles CLI tool to filter spam from a YouTube video URL. This command analyzes the video and outputs a JSON array detailing spam segments with their start and end timestamps. It helps in cleaning data before processing.
```bash
npx tsx src/sponsorblock.ts https://www.youtube.com/watch?v=UPrkC1LdlLY
```
--------------------------------
### Ragtitles Spam Detection Output Format
Source: https://github.com/andraz/ragtitles/blob/main/README.md
The output from the Ragtitles spam filtering command is a JSON array. Each object in the array represents a detected spam segment, specifying its category (e.g., 'preview', 'selfpromo', 'sponsor') and its start and end timestamps in seconds.
```json
[
{
"category": "preview",
"start": 0,
"end": 7
},
{
"category": "preview",
"start": 68,
"end": 74
},
{
"category": "selfpromo",
"start": 296,
"end": 323
},
{
"category": "selfpromo",
"start": 861,
"end": 876
},
{
"category": "preview",
"start": 1233,
"end": 1238
},
{
"category": "sponsor",
"start": 1279,
"end": 1326
},
{
"category": "preview",
"start": 1483,
"end": 1489
},
{
"category": "selfpromo",
"start": 1516,
"end": 1529
},
{
"category": "filler",
"start": 1864,
"end": 1868
},
{
"category": "outro",
"start": 1935,
"end": 1940
}
]
```
--------------------------------
### Run Project Tests with npm
Source: https://github.com/andraz/ragtitles/blob/main/README.md
Execute the project's test suite using the npm test command. This is a standard command for verifying the functionality and integrity of the Ragtitles project.
```bash
npm test
```
--------------------------------
### Ragtitles CLI for VTT Files and YouTube URLs
Source: https://context7.com/andraz/ragtitles/llms.txt
Process local VTT files or YouTube URLs directly from the command line. Supports optional timestamp prefixes and can pipe output for further processing or saving to files.
```bash
# Process a local VTT file
npx tsx cli.ts video.en.vtt
# Process with timestamps
npx tsx cli.ts video.en.vtt --time
# Output:
# 0 this was the very first transistor and
# 2 it was made in
# 3 1947 by 1978 the industry had Advanced
# Download and process YouTube video automatically
npx tsx cli.ts https://www.youtube.com/watch?v=RuVS7MsQk4Y --time
# Extract specific time ranges
npx tsx cli.ts https://www.youtube.com/watch?v=RuVS7MsQk4Y | head -n 50 | tail -n 20 | tr '\n' ' '
# Output: Single line of text from lines 31-50
# Save to file for LLM context
npx tsx cli.ts https://www.youtube.com/watch?v=RuVS7MsQk4Y --time > transcript.txt
```
--------------------------------
### Convert VTT File using Ragtitles CLI (Bash)
Source: https://github.com/andraz/ragtitles/blob/main/README.md
Converts a local VTT subtitle file to the ragtitles format using the command-line interface provided by the npm package. The output is printed to the console. Requires Node.js and npm/npx.
```bash
npx tsx cli.ts filename.vtt
```
--------------------------------
### Download and Convert YouTube Subtitles using Ragtitles CLI (Bash)
Source: https://github.com/andraz/ragtitles/blob/main/README.md
Downloads subtitles from a YouTube URL and converts them to the ragtitles format using the CLI utility. The output is printed to the console. Requires Node.js and npm/npx.
```bash
npx tsx cli.ts https://www.youtube.com/watch?v=RuVS7MsQk4Y
```
--------------------------------
### Open Processed Transcript in VSCode
Source: https://github.com/andraz/ragtitles/blob/main/README.md
This command chain first processes a YouTube video transcript using npx tsx, saving the output to a temporary file named 'tmp.txt'. It then uses the 'code' command to open this file directly in Visual Studio Code. This allows for quick review and editing of the transcript data.
```bash
npx tsx cli.ts https://www.youtube.com/watch?v=RuVS7MsQk4Y --time > tmp.txt && code tmp.txt
```
--------------------------------
### Download YouTube Subtitles with yt-dlp (Bash)
Source: https://github.com/andraz/ragtitles/blob/main/README.md
Downloads autogenerated subtitles from a YouTube video using the yt-dlp command-line tool. The `--write-auto-subs` flag ensures only autogenerated subtitles are downloaded, and `--skip-download` prevents video downloading. This is a prerequisite for converting VTT files.
```bash
python -m yt_dlp https://www.youtube.com/watch?v=qrbhlNPSwzY --write-auto-subs --skip-download
```
--------------------------------
### Download and Convert YouTube Subtitles with Timestamps using Ragtitles CLI (Bash)
Source: https://github.com/andraz/ragtitles/blob/main/README.md
Downloads subtitles from a YouTube URL and converts them to the ragtitles format, including timestamps in seconds for each line. The output is printed to the console. Requires Node.js and npm/npx.
```bash
npx tsx cli.ts https://www.youtube.com/watch?v=RuVS7MsQk4Y --time
```
--------------------------------
### Extract Text Snippet from Video Transcript
Source: https://github.com/andraz/ragtitles/blob/main/README.md
This command uses npx tsx to execute a script, piping its output through head and tail to select a specific range of lines. The 'tr' command then replaces newline characters with spaces, creating a single line of text. This is useful for extracting a concise summary from the beginning of a video transcript.
```bash
npx tsx cli.ts https://www.youtube.com/watch?v=RuVS7MsQk4Y | head -n 50 | tail -n 20 | tr '\n' ' '
```
--------------------------------
### Preprocess VTT Data with JavaScript
Source: https://context7.com/andraz/ragtitles/llms.txt
Cleans raw VTT data by removing headers, HTML tags, empty lines, and unreasonably short timestamps. It takes raw VTT content as a string and returns an array of cleaned lines. Dependencies include the 'ragtitles/src/preprocessVTTData' module.
```javascript
import preprocessVTTData from 'ragtitles/src/preprocessVTTData'
const rawVTT = `WEBVTT
Kind: captions
Language: en
00:00:00.160 --> 00:00:02.350 align:start position:0%
lost another colony
00:00:02.350 --> 00:00:02.360 align:start position:0%
00:00:02.360 --> 00:00:04.269 align:start position:0%
make sure the next one`
const cleaned = preprocessVTTData(rawVTT)
console.log(cleaned)
// Output: Array of clean lines without metadata, HTML tags, or short timestamps
// ["00:00:00.160 --> 00:00:02.350", "lost another colony", "00:00:02.360 --> 00:00:04.269", "make sure the next one"]
```
--------------------------------
### Convert VTT Data to Ragtitles Format (JavaScript)
Source: https://github.com/andraz/ragtitles/blob/main/README.md
Converts standard VTT subtitle data into a RAG-friendly format using the ragtitles npm module. The input is a string containing VTT data, and the output is an array of objects, each with a 'time' (in seconds) and 'text' property. This format is suitable for RAG ingestion.
```javascript
import convert from 'ragtitles'
const vttData = `WEBVTT
Kind: captions
Language: en
00:00:00.160 --> 00:00:02.350 align:start position:0%
lost<00:00:00.520> another<00:00:00.880> colony<00:00:01.240> to<00:00:01.439> Raiders<00:00:02.120> let's
00:00:02.350 --> 00:00:02.360 align:start position:0%
lost another colony to Raiders let's
00:00:02.360 --> 00:00:04.269 align:start position:0%
lost another colony to Raiders let's
make<00:00:02.520> sure<00:00:02.879> the<00:00:03.040> next<00:00:03.280> one<00:00:03.520> doesn't<00:00:03.840> suffer
00:00:04.269 --> 00:00:04.279 align:start position:0%
make sure the next one doesn't suffer
00:00:04.279 --> 00:00:06.789 align:start position:0%
make sure the next one doesn't suffer
the<00:00:04.520> same<00:00:04.839> fate<00:00:05.279> shall<00:00:05.640> we<00:00:06.040> today<00:00:06.399> we're<00:00:06.680> going
00:00:06.789 --> 00:00:06.799 align:start position:0%
the same fate shall we today we're going
`
const convertedData = convert(vttData)
console.log(convertedData)
```
--------------------------------
### Remove Spam Segments from Timestamped Sentences
Source: https://context7.com/andraz/ragtitles/llms.txt
Filters an array of timestamped sentences by removing content that falls within specified SponsorBlock spam segments. Requires the sentences and a YouTube video URL for context.
```javascript
import removeSpam from 'ragtitles/src/removeSpam'
const sentences = [
{ time: 0, text: "Welcome to the video intro" },
{ time: 10, text: "This is the actual content" },
{ time: 1280, text: "This video is sponsored by" },
{ time: 1330, text: "Back to the main content" }
]
const cleaned = await removeSpam(sentences, 'https://www.youtube.com/watch?v=VIDEO_ID')
console.log(cleaned)
// Output:
// [
// { time: 10, text: "This is the actual content" },
// { time: 1330, text: "Back to the main content" }
// ]
// Intro and sponsor segments are automatically removed
```
--------------------------------
### Convert Ragtitles Array to String Format (JavaScript)
Source: https://github.com/andraz/ragtitles/blob/main/README.md
Converts the array of objects generated by the ragtitles converter into a single string, where each line is prefixed with the timestamp in seconds followed by the text. This format is useful for direct in-context ingestion into LLM prompts.
```javascript
const stringData = convertedData.map((d) => `${d.time} ${d.text}`)
console.log(stringData.join('\n'))
```
--------------------------------
### Convert VTT to RAG Format with Ragtitles
Source: https://context7.com/andraz/ragtitles/llms.txt
Transforms raw YouTube VTT subtitle data into an optimized array of timestamped sentences suitable for RAG ingestion. Supports optional spam filtering using a YouTube URL.
```javascript
import convert from 'ragtitles'
const vttData = `WEBVTT
Kind: captions
Language: en
00:00:00.160 --> 00:00:02.350 align:start position:0%
lost<00:00:00.520> another<00:00:00.880> colony<00:00:01.240> to<00:00:01.439> Raiders<00:00:02.120> let's
00:00:02.350 --> 00:00:02.360 align:start position:0%
lost another colony to Raiders let's
00:00:02.360 --> 00:00:04.269 align:start position:0%
lost another colony to Raiders let's
make<00:00:02.520> sure<00:00:02.879> the<00:00:03.040> next<00:00:03.280> one<00:00:03.520> doesn't<00:00:03.840> suffer
00:00:04.269 --> 00:00:04.279 align:start position:0%
make sure the next one doesn't suffer
00:00:04.279 --> 00:00:06.789 align:start position:0%
make sure the next one doesn't suffer
the<00:00:04.520> same<00:00:04.839> fate`
// Convert without spam filtering
const result = await convert(vttData)
console.log(result)
// Output:
// [
// { time: 0, text: "lost another colony to Raiders let's" },
// { time: 2, text: "make sure the next one doesn't suffer" },
// { time: 4, text: "the same fate shall we today we're going" }
// ]
// Convert with automatic spam filtering (requires YouTube URL)
const resultWithFiltering = await convert(vttData, 'https://www.youtube.com/watch?v=VIDEO_ID')
console.log(resultWithFiltering)
// Output: Same as above but with sponsor/intro/outro segments removed
```
--------------------------------
### Check if Line is Timestamp with JavaScript
Source: https://context7.com/andraz/ragtitles/llms.txt
Validates whether a given line string contains a VTT timestamp marker. It takes a string as input and returns a boolean: true if it's a timestamp, false otherwise. Dependencies include the 'ragtitles/src/isTimestamp' module.
```javascript
import isTimestamp from 'ragtitles/src/isTimestamp'
console.log(isTimestamp('00:00:00.160 --> 00:00:02.350')) // Output: true
console.log(isTimestamp('This is just text')) // Output: false
console.log(isTimestamp('lost another colony to Raiders')) // Output: false
```
--------------------------------
### Remove Lingering Text with JavaScript
Source: https://context7.com/andraz/ragtitles/llms.txt
Eliminates overlapping text that appears in consecutive subtitle entries, ensuring each sentence contains only new content. It takes an array of sentence objects (each with a 'time' and 'text' property) and returns a new array with lingering text removed. Dependencies include the 'ragtitles/src/removeLingeringText' module.
```javascript
import removeLingeringText from 'ragtitles/src/removeLingeringText'
const sentences = [
{ time: 0, text: 'Hello, how are you?' },
{ time: 1, text: 'Hello, how are you? I am fine, thank you.' },
{ time: 2, text: 'I am fine, thank you. How about you?' }
]
const cleaned = removeLingeringText(sentences)
console.log(cleaned)
// Output:
// [
// { time: 0, text: 'Hello, how are you?' },
// { time: 1, text: 'I am fine, thank you.' },
// { time: 2, text: 'How about you?' }
// ]
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.