# node-youtube-subtitles

> Getting YouTube subtitles without API keys.

Latest version **1.1.0** (published 2021-10-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-youtube-subtitles
pnpm add node-youtube-subtitles
yarn add node-youtube-subtitles
bun add node-youtube-subtitles
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2021-10-30 |
| First published | 2021-10-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=12.0.0 |
| Dependencies | 1 |
| Unpacked size | 5.6 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Neo |
| Maintainers | neoration |
| Keywords | youtube, node, node.js, subtitle, caption |

## Links

- npm: https://www.npmjs.com/package/node-youtube-subtitles
- Repository: https://github.com/Neoration/node-youtube-subtitles
- Issues: https://github.com/Neoration/node-youtube-subtitles/issues
- npm.io page: https://npm.io/package/node-youtube-subtitles

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^0.24.0

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2021-10-30
- 1.0.21 — 2021-10-29
- 1.0.2 — 2021-10-29
- 1.0.1 — 2021-10-29
- 1.0.0 — 2021-10-29

## README

# Node Youtube Subtitles  
This library allows you to obtain subtitles for a YouTube video through a link or ID without an API key.  
it returns Promise, you need to use `await` to get the return value.  
## getSubtitles()  
| PARAMETERS 	| TYPE 	| OPTIONAL 	| DESCRIPTION 	|
|---	|---	|---	|---	|
| url 	| YoutubeURLResolvable 	| `N` 	| Get subtitles for the video based on the URL or video ID. 	|
| options 	| Object 	| `Y` 	| You can set the subtitle language or have the timing string return.  	|    

If the video ID or URL is not valid, return an empty array.  

---
### Basics
```ts
const urls = [
  "https://www.youtube.com/watch?v=_GBw7lBfMkM",
  "https://youtu.be/_GBw7lBfMkM",
  "_GBw7lBfMkM",
];

for (const url of urls) {
  const sub = await getSubtitles(url);
  console.log(sub);
  // All return the SAME RESULT.
}
```
#### Return values 
```
[
  {
    startMs: 30520,
    durationMs: 2920,
    subtitle: 'At 2 AM at the train crossing,'
  },
  {
    startMs: 33440,
    durationMs: 2600,
    subtitle: 'I was carrying a telescope.'
  },
  ...
]
```
The above code returns the value below.  
---
### Designating a language
```ts
const url = "https://www.youtube.com/watch?v=DoDCr--yMNY";
const sub = await getSubtitles(url, { lang: "ko" });
// Return the Korean caption
}
```
If a language is not specified, the default value is "en".  
#### Return values 
```
[
  {
    startMs: 600,
    durationMs: 2800,
    subtitle: '달도 지구도 태양도'
  },
  {
    startMs: 3400,
    durationMs: 2100,
    subtitle: '빼앗아'
  },
  ...
]
```
---
### Getting the timing string
```ts
const url = "https://youtu.be/ESx_hy1n7HA";
const sub = await getSubtitles(url, { timingString: true });
}
```
#### Return values 
```
[
  ...
  {
    startMs: 125708,
    durationMs: 2953,
    startTiming: '00:02:25.708',
    endTiming: '00:02:28.661',
    subtitle: 'Challenging your god'
  },
  {
    startMs: 128661,
    durationMs: 2563,
    startTiming: '00:02:28.661',
    endTiming: '00:02:31.224',
    subtitle: 'You have made some'
  },
  ...
]
```
---
### Mix
```ts
const url = "DoDCr--yMNY";
const sub = await getSubtitles(url, { lang: "ko", timingString: true });
}
```
#### Return values 
```
[
  {
    startMs: 600,
    startTiming: '00:00:00.600',
    endTiming: '00:00:03.400',
    durationMs: 2800,
    subtitle: '달도 지구도 태양도'
  },
  {
    startMs: 3400,
    startTiming: '00:00:03.400',
    endTiming: '00:00:05.500',
    durationMs: 2100,
    subtitle: '빼앗아'
  },
  ...
]
```

---
_Source: https://npm.io/package/node-youtube-subtitles · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
