Skip to content

Commit b25a6e6

Browse files
committed
docs: update README.md
1 parent a699289 commit b25a6e6

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed

README.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
## 📖 Introduction
1313

1414
Java library which allows you to retrieve subtitles/transcripts for a YouTube video.
15-
It supports manual and automatically generated subtitles and does not use headless browser for scraping.
15+
It supports manual and automatically generated subtitles, bulk transcript retrieval for all videos in the playlist or
16+
on the channel and does not use headless browser for scraping.
1617
Inspired by [Python library](https://github.com/jdepoix/youtube-transcript-api).
1718

1819
## 🤖 Features
@@ -21,6 +22,8 @@ Inspired by [Python library](https://github.com/jdepoix/youtube-transcript-api).
2122

2223
✅ Automatically generated transcripts retrieval
2324

25+
✅ Bulk transcript retrieval for all videos in the playlist or channel
26+
2427
✅ Transcript translation
2528

2629
✅ Transcript formatting
@@ -79,7 +82,7 @@ TranscriptList transcriptList = youtubeTranscriptApi.listTranscripts("videoId");
7982

8083
// Iterate over transcript list
8184
for(Transcript transcript : transcriptList) {
82-
System.out.println(transcript);
85+
System.out.println(transcript);
8386
}
8487

8588
// Find transcript in specific language
@@ -143,6 +146,8 @@ TranscriptContent transcriptContent = youtubeTranscriptApi.listTranscripts("vide
143146
TranscriptContent transcriptContent = youtubeTranscriptApi.getTranscript("videoId");
144147
```
145148

149+
For bulk transcript retrieval see [Bulk Transcript Retrieval](#bulk-transcript-retrieval).
150+
146151
## 🔧 Detailed Usage
147152

148153
### Use fallback language
@@ -241,7 +246,7 @@ TranscriptFormatter jsonFormatter = TranscriptFormatters.jsonFormatter();
241246
String formattedContent = jsonFormatter.format(transcriptContent);
242247
````
243248

244-
### YoutubeClient customization
249+
### YoutubeClient Customization
245250

246251
By default, `YoutubeTranscriptApi` uses Java 11 HttpClient for making requests to YouTube, if you want to use a
247252
different client,
@@ -275,6 +280,52 @@ TranscriptList transcriptList = youtubeTranscriptApi.listTranscriptsWithCookies(
275280
TranscriptContent transcriptContent = youtubeTranscriptApi.getTranscriptWithCookies("videoId", "path/to/cookies.txt", "en");
276281
```
277282

283+
### Bulk Transcript Retrieval
284+
285+
All bulk transcript retrieval operations are done via the `PlaylistsTranscriptApi` interface. Same as with the
286+
`YoutubeTranscriptApi`,
287+
you can create a new instance of the PlaylistsTranscriptApi by calling the `createDefaultPlaylistsApi` method of the
288+
`TranscriptApiFactory`.
289+
Playlists and channels information is retrieved from
290+
the [YouTube V3 API](https://developers.google.com/youtube/v3/docs/),
291+
so you will need to provide API key for all methods.
292+
293+
```java
294+
// Create a new default PlaylistsTranscriptApi instance
295+
PlaylistsTranscriptApi playlistsTranscriptApi = TranscriptApiFactory.createDefaultPlaylistsApi();
296+
297+
// Retrieve all available transcripts for a given playlist
298+
Map<String, TranscriptList> transcriptLists = playlistsTranscriptApi.listTranscriptsForPlaylist("playlistId", "apiKey", true);
299+
300+
// Retrieve all available transcripts for a given channel
301+
Map<String, TranscriptList> transcriptLists = playlistsTranscriptApi.listTranscriptsForChannel("channelName", "apiKey", true);
302+
```
303+
304+
As you can see, there is also a boolean flag `continueOnError`, which tells whether to continue if transcript retrieval
305+
fails for a video or not. For example, if it's set to `true`, all transcripts that could not be retrieved will be
306+
skipped, if
307+
it's set to `false`, operation will fail fast on the first error.
308+
309+
All methods are also have overloaded versions which accept path to [cookies.txt](#cookies) file.
310+
311+
```java
312+
// Retrieve all available transcripts for a given playlist
313+
Map<String, TranscriptList> transcriptLists = playlistsTranscriptApi.listTranscriptsForPlaylist(
314+
"playlistId",
315+
"apiKey",
316+
true,
317+
"path/to/cookies.txt"
318+
);
319+
320+
// Retrieve all available transcripts for a given channel
321+
Map<String, TranscriptList> transcriptLists = playlistsTranscriptApi.listTranscriptsForChannel(
322+
"channelName",
323+
"apiKey",
324+
true,
325+
"path/to/cookies.txt"
326+
);
327+
```
328+
278329
## 🤓 How it works
279330

280331
Within each YouTube video page, there exists JSON data containing all the transcript information, including an

0 commit comments

Comments
 (0)