-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Thoroldvix/feat/playlist-transcripts
Add bulk retrieval of transcripts for playlists and channels
- Loading branch information
Showing
23 changed files
with
1,322 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
lib/src/main/java/io/github/thoroldvix/api/PlaylistsTranscriptApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.github.thoroldvix.api; | ||
|
||
import io.github.thoroldvix.internal.TranscriptApiFactory; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Retrieves transcripts for all videos in a playlist, or all videos for a specific channel. | ||
* <p> | ||
* Playlists and channel videos are retrieved from the YouTube API, so you will need to have a valid api key to use this. | ||
* </p> | ||
* <p> | ||
* To get implementation for this interface see {@link TranscriptApiFactory} | ||
* </p> | ||
*/ | ||
public interface PlaylistsTranscriptApi { | ||
|
||
/** | ||
* Retrieves transcript lists for all videos in the specified playlist using provided API key and cookies file from a specified path. | ||
* | ||
* @param playlistId The ID of the playlist | ||
* @param apiKey API key for the YouTube V3 API (see <a href="https://developers.google.com/youtube/v3/getting-started">Getting started</a>) | ||
* @param continueOnError Whether to continue if transcript retrieval fails for a video. If true, all transcripts that could not be retrieved will be skipped, | ||
* otherwise an exception will be thrown. | ||
* @param cookiesPath The file path to the text file containing the authentication cookies. Used in the case if some videos are age restricted see {<a href="https://github.com/Thoroldvix/youtube-transcript-api#cookies">Cookies</a>} | ||
* @return A map of video IDs to {@link TranscriptList} objects | ||
* @throws TranscriptRetrievalException If the retrieval of the transcript lists fails | ||
*/ | ||
Map<String, TranscriptList> listTranscriptsForPlaylist(String playlistId, String apiKey, String cookiesPath, boolean continueOnError) throws TranscriptRetrievalException; | ||
|
||
|
||
/** | ||
* Retrieves transcript lists for all videos in the specified playlist using provided API key. | ||
* | ||
* @param playlistId The ID of the playlist | ||
* @param apiKey API key for the YouTube V3 API (see <a href="https://developers.google.com/youtube/v3/getting-started">Getting started</a>) | ||
* @param continueOnError Whether to continue if transcript retrieval fails for a video. If true, all transcripts that could not be retrieved will be skipped, | ||
* otherwise an exception will be thrown. | ||
* @return A map of video IDs to {@link TranscriptList} objects | ||
* @throws TranscriptRetrievalException If the retrieval of the transcript lists fails | ||
*/ | ||
Map<String, TranscriptList> listTranscriptsForPlaylist(String playlistId, String apiKey, boolean continueOnError) throws TranscriptRetrievalException; | ||
|
||
|
||
/** | ||
* Retrieves transcript lists for all videos for the specified channel using provided API key and cookies file from a specified path. | ||
* | ||
* @param channelName The name of the channel | ||
* @param apiKey API key for the YouTube V3 API (see <a href="https://developers.google.com/youtube/v3/getting-started">Getting started</a>) | ||
* @param cookiesPath The file path to the text file containing the authentication cookies. Used in the case if some videos are age restricted see {<a href="https://github.com/Thoroldvix/youtube-transcript-api#cookies">Cookies</a>} | ||
* @param continueOnError Whether to continue if transcript retrieval fails for a video. If true, all transcripts that could not be retrieved will be skipped, | ||
* otherwise an exception will be thrown. | ||
* @return A map of video IDs to {@link TranscriptList} objects | ||
* @throws TranscriptRetrievalException If the retrieval of the transcript lists fails | ||
* @throws TranscriptRetrievalException If the retrieval of the transcript lists fails | ||
*/ | ||
Map<String, TranscriptList> listTranscriptsForChannel(String channelName, String apiKey, String cookiesPath, boolean continueOnError) throws TranscriptRetrievalException; | ||
|
||
|
||
/** | ||
* Retrieves transcript lists for all videos for the specified channel using provided API key. | ||
* | ||
* @param channelName The name of the channel | ||
* @param apiKey API key for the YouTube V3 API (see <a href="https://developers.google.com/youtube/v3/getting-started">Getting started</a>) | ||
* @param continueOnError Whether to continue if transcript retrieval fails for a video. If true, all transcripts that could not be retrieved will be skipped, | ||
* otherwise an exception will be thrown. | ||
* @return A map of video IDs to {@link TranscriptList} objects | ||
* @throws TranscriptRetrievalException If the retrieval of the transcript lists fails | ||
*/ | ||
Map<String, TranscriptList> listTranscriptsForChannel(String channelName, String apiKey, boolean continueOnError) throws TranscriptRetrievalException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
lib/src/main/java/io/github/thoroldvix/api/YtApiV3Endpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.github.thoroldvix.api; | ||
|
||
/** | ||
* The YouTube API V3 endpoints. Used by the {@link YoutubeClient}. | ||
*/ | ||
public enum YtApiV3Endpoint { | ||
PLAYLIST_ITEMS("playlistItems"), | ||
SEARCH("search"), | ||
CHANNELS("channels"); | ||
private final static String YOUTUBE_API_V3_BASE_URL = "https://www.googleapis.com/youtube/v3/"; | ||
|
||
private final String resource; | ||
private final String url; | ||
|
||
YtApiV3Endpoint(String resource) { | ||
this.url = YOUTUBE_API_V3_BASE_URL + resource; | ||
this.resource = resource; | ||
} | ||
|
||
public String url() { | ||
return url; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return resource; | ||
} | ||
} |
Oops, something went wrong.