https://github.com/aliencube/youtube-subtitles-extractor
This is the library to retrieve subtitles from a given YouTube video, inspired by https://github.com/devhims/youtube-caption-extractor
https://github.com/aliencube/youtube-subtitles-extractor
caption hacktoberfest subtitle video youtube
Last synced: 7 months ago
JSON representation
This is the library to retrieve subtitles from a given YouTube video, inspired by https://github.com/devhims/youtube-caption-extractor
- Host: GitHub
- URL: https://github.com/aliencube/youtube-subtitles-extractor
- Owner: aliencube
- License: mit
- Created: 2023-09-20T07:54:33.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-17T07:42:47.000Z (10 months ago)
- Last Synced: 2025-06-27T01:39:38.841Z (8 months ago)
- Topics: caption, hacktoberfest, subtitle, video, youtube
- Language: C#
- Homepage:
- Size: 45.9 KB
- Stars: 9
- Watchers: 2
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#  YouTube Subtitles Extractor
 [](https://www.nuget.org/packages/Aliencube.YouTubeSubtitlesExtractor) [](https://www.nuget.org/packages/Aliencube.YouTubeSubtitlesExtractor)
This is the NuGet package library that retrieves subtitles from a given YouTube video, inspired by [@devhims](https://github.com/devhims)' [YouTube Caption Extractor](https://github.com/devhims/youtube-caption-extractor).
## Known Issues
- If you use this library on your [Blazor WebAssembly](https://learn.microsoft.com/aspnet/core/blazor/hosting-models#blazor-webassembly) project, you might encounter the [CORS error](https://developer.mozilla.org/docs/Web/HTTP/CORS). The only workaround is to use a facade API to retrieve the subtitles.
## Getting Started
1. Install the [NuGet package](https://www.nuget.org/packages/Aliencube.YouTubeSubtitlesExtractor) to your project.
1. Add the namespace to your code.
```csharp
using Aliencube.YouTubeSubtitlesExtractor;
```
1. Get the YouTube video URL.
```csharp
var youtubeUrl = "https://www.youtube.com/watch?v=i8tMiWHK05M";
```
1. Create an instance of `YouTubeVideo` class.
```csharp
var http = new HttpClient();
var youtube = new YouTubeVideo(http);
```
1. Extract subtitles from the given YouTube video URL. There are a few options to extract subtitles.
```csharp
// Extract video details from the given YouTube video URL.
VideoDetails details = await youtube.ExtractVideoDetailsAsync(youtubeUrl);
// Extract a single subtitle from the given YouTube video URL.
// - defaults to English (en)
Subtitle subtitle = await youtube.ExtractSubtitleAsync(youtubeUrl);
// Extract a single subtitle from the given YouTube video URL with the specified language code.
// eg) Korean (ko)
Subtitle subtitle = await youtube.ExtractSubtitleAsync(youtubeUrl, "ko");
// Extract list of subtitles from the given VideoOptions instance.
// eg) English and Korean (ko)
var options = new VideoOptions { Url = youtubeUrl, LanguageCodes = { "en", "ko" } };
List subtitles = await youtube.ExtractSubtitlesAsync(options);
```
## Sample Console App
You can find a sample console app to extract YouTube video details from [here](./samples/YouTubeSubtitlesExtractor.ConsoleApp). Alternatively, run the following command to run the console app.
```bash
dotnet run --project ./samples/YouTubeSubtitlesExtractor.ConsoleApp
```
Then, enter a YouTube link to get the details and available language codes. After you enter the language code, it will display the subtitles in the given language.
## Issues or Feedbacks
Please leave any issues or feedbacks on the [GitHub Issue page](https://github.com/aliencube/youtube-subtitles-extractor/issues).
## TO-DOs
- [ ] devcontainer settings
## Acknowledgments
- Icons made by [Freepik](https://www.flaticon.com/authors/freepik) from [flaticon.com](https://flaticon.com/).