From 72f6bd96d32e5ebe5a776dda8921368397c94ab5 Mon Sep 17 00:00:00 2001 From: trld Date: Thu, 13 Jun 2024 16:14:20 +0300 Subject: [PATCH] docs: update README.md --- README.md | 64 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index a315bcb..27093ab 100644 --- a/README.md +++ b/README.md @@ -81,8 +81,11 @@ for [finding specific transcripts](#find-transcripts) by language or by type (ma TranscriptList transcriptList = youtubeTranscriptApi.listTranscripts("videoId"); // Iterate over transcript list -for(Transcript transcript : transcriptList) { - System.out.println(transcript); +for( +Transcript transcript :transcriptList){ + System.out. + +println(transcript); } // Find transcript in specific language @@ -290,48 +293,49 @@ Playlists and channels information is retrieved from the [YouTube V3 API](https://developers.google.com/youtube/v3/docs/), so you will need to provide API key for all methods. +All methods take a `TranscriptRequest` object as a parameter, +which contains the following fields: + +- `apiKey` - YouTube API key. +- `stopOnError`(optional, defaults to `true`) - Whether to stop on the first error or continue. If true, the method will + fail fast by throwing an error if one of the transcripts could not be retrieved, + otherwise it will ignore failed transcripts. + +- `cookies` (optional) - Path to [cookies.txt](#cookies) file. + +All methods return a map which contains the video ID as a key and the corresponding result as a value. + ```java // Create a new default PlaylistsTranscriptApi instance PlaylistsTranscriptApi playlistsTranscriptApi = TranscriptApiFactory.createDefaultPlaylistsApi(); +//Create request object +TranscriptRequest request = new TranscriptRequest("apiKey"); + // Retrieve all available transcripts for a given playlist -Map transcriptLists = playlistsTranscriptApi.listTranscriptsForPlaylist( - "playlistId", - "apiKey", - true); +Map transcriptLists = playlistsTranscriptApi.listTranscriptsForPlaylist("playlistId", request); // Retrieve all available transcripts for a given channel -Map transcriptLists = playlistsTranscriptApi.listTranscriptsForChannel( - "channelName", - "apiKey", - true); +Map transcriptLists = playlistsTranscriptApi.listTranscriptsForChannel("channelName", request); ``` -As you can see, there is also a boolean flag `continueOnError`, which tells whether to continue if transcript retrieval -fails for a video or not. For example, if it's set to `true`, all transcripts that could not be retrieved will be -skipped, if -it's set to `false`, operation will fail fast on the first error. - -All methods are also have overloaded versions which accept path to [cookies.txt](#cookies) file. +Same as with the `YoutubeTranscriptApi`, you can also fetch transcript content directly +using [fallback languages](#use-fallback-language) if needed. ```java -// Retrieve all available transcripts for a given playlist -Map transcriptLists = playlistsTranscriptApi.listTranscriptsForPlaylist( - "playlistId", - "apiKey", - true, - "path/to/cookies.txt" -); +//Create request object +TranscriptRequest request = new TranscriptRequest("apiKey"); -// Retrieve all available transcripts for a given channel -Map transcriptLists = playlistsTranscriptApi.listTranscriptsForChannel( - "channelName", - "apiKey", - true, - "path/to/cookies.txt" -); +// Retrieve transcript content for all videos in a playlist +Map transcriptLists = playlistsTranscriptApi.getTranscriptsForPlaylist("playlistId", request); + +// Retrieve transcript content for all videos in a channel +Map transcriptLists = playlistsTranscriptApi.getTranscriptsForChannel("channelName", request, "en, de"); ``` +> **Note:** If you want to get transcript content in a different format, refer +> to [Use Formatters](#use-formatters). + ## 🤓 How it works Within each YouTube video page, there exists JSON data containing all the transcript information, including an