1212
1313public final class SubtitlesStream extends Stream {
1414 private final MediaFormat format ;
15+ @ Nullable
16+ private final Locale baseLocale ;
1517 private final Locale locale ;
1618 private final boolean autoGenerated ;
1719 private final boolean autoTranslated ;
@@ -31,6 +33,8 @@ public static final class Builder {
3133 @ Nullable
3234 private String manifestUrl ;
3335 private String languageCode ;
36+ @ Nullable
37+ private String baseLanguageCode ;
3438 // Use of the Boolean class instead of the primitive type needed for setter call check
3539 private Boolean autoGenerated ;
3640 private Boolean autoTranslated ;
@@ -142,6 +146,18 @@ public Builder setLanguageCode(@Nonnull final String languageCode) {
142146 return this ;
143147 }
144148
149+ /**
150+ * Set the language code of the base language used to auto-translate
151+ * the {@link SubtitlesStream} to the current language code.
152+ *
153+ * @param baseLanguageCode the language code of the {@link SubtitlesStream}
154+ * @return this {@link Builder} instance
155+ */
156+ public Builder setBaseLanguageCode (@ Nullable final String baseLanguageCode ) {
157+ this .baseLanguageCode = baseLanguageCode ;
158+ return this ;
159+ }
160+
145161 /**
146162 * Set whether the subtitles have been auto-generated by the streaming service.
147163 *
@@ -222,26 +238,29 @@ public SubtitlesStream build() throws ParsingException {
222238 }
223239
224240 return new SubtitlesStream (id , content , isUrl , mediaFormat , deliveryMethod ,
225- languageCode , autoGenerated , autoTranslated , manifestUrl );
241+ languageCode , autoGenerated , autoTranslated , baseLanguageCode , manifestUrl );
226242 }
227243 }
228244
229245 /**
230246 * Create a new subtitles stream.
231247 *
232- * @param id the identifier which uniquely identifies the stream, e.g. for YouTube
233- * this would be the itag
234- * @param content the content or the URL of the stream, depending on whether isUrl is
235- * true
236- * @param isUrl whether content is the URL or the actual content of e.g. a DASH
237- * manifest
238- * @param mediaFormat the {@link MediaFormat} used by the stream
239- * @param deliveryMethod the {@link DeliveryMethod} of the stream
240- * @param languageCode the language code of the stream
241- * @param autoGenerated whether the subtitles are auto-generated by the streaming service
242- * @param autoTranslated whether the subtitles are auto-translated by the streaming service
243- * @param manifestUrl the URL of the manifest this stream comes from (if applicable,
244- * otherwise null)
248+ * @param id the identifier which uniquely identifies the stream, e.g. for YouTube
249+ * this would be the itag
250+ * @param content the content or the URL of the stream, depending on whether isUrl is
251+ * true
252+ * @param isUrl whether content is the URL or the actual content of e.g. a DASH
253+ * manifest
254+ * @param mediaFormat the {@link MediaFormat} used by the stream
255+ * @param deliveryMethod the {@link DeliveryMethod} of the stream
256+ * @param languageCode the language code of the stream
257+ * @param autoGenerated whether the subtitles are auto-generated by the streaming service
258+ * @param autoTranslated whether the subtitles are auto-translated by the streaming service
259+ * @param baseLanguageCode the language code of the base language used to translate
260+ * the subtitles to the current language
261+ * or null if the subtitles are not auto-translated
262+ * @param manifestUrl the URL of the manifest this stream comes from (if applicable,
263+ * otherwise null)
245264 */
246265 @ SuppressWarnings ("checkstyle:ParameterNumber" )
247266 private SubtitlesStream (@ Nonnull final String id ,
@@ -252,6 +271,7 @@ private SubtitlesStream(@Nonnull final String id,
252271 @ Nonnull final String languageCode ,
253272 final boolean autoGenerated ,
254273 final boolean autoTranslated ,
274+ @ Nullable final String baseLanguageCode ,
255275 @ Nullable final String manifestUrl ) throws ParsingException {
256276 super (id , content , isUrl , mediaFormat , deliveryMethod , manifestUrl );
257277 this .locale = LocaleCompat .forLanguageTag (languageCode ).orElseThrow (
@@ -261,6 +281,13 @@ private SubtitlesStream(@Nonnull final String id,
261281 this .format = mediaFormat ;
262282 this .autoGenerated = autoGenerated ;
263283 this .autoTranslated = autoTranslated ;
284+ if (baseLanguageCode == null ) {
285+ this .baseLocale = null ;
286+ } else {
287+ this .baseLocale = LocaleCompat .forLanguageTag (baseLanguageCode ).orElseThrow (
288+ () -> new ParsingException (
289+ "not a valid locale language code: " + baseLanguageCode ));
290+ }
264291 }
265292
266293 /**
@@ -337,6 +364,37 @@ public Locale getLocale() {
337364 return locale ;
338365 }
339366
367+ /**
368+ * Get the {@link Locale baseLocale} which was used to automatically translated the subtitles
369+ * into the current {@link #locale}.
370+ *
371+ * @return the {@link Locale baseLocale} for the subtitle translation
372+ * or {@code null} if the subtitle is not auto-translated
373+ */
374+ @ Nullable
375+ public Locale getBaseLocale () {
376+ return baseLocale ;
377+ }
378+
379+ /**
380+ * Get the display base language name of the subtitles.
381+ *
382+ * @return the display language name of the subtitles
383+ */
384+ public String getDisplayBaseLanguageName () {
385+ return locale .getDisplayName (locale );
386+ }
387+
388+ /**
389+ * Get the language tag of the subtitles.
390+ *
391+ * @return the language tag of the subtitles
392+ */
393+ public String getBaseLanguageTag () {
394+ return code ;
395+ }
396+
397+
340398 /**
341399 * No subtitles which are currently extracted use an {@link ItagItem}, so {@code null} is
342400 * returned by this method.
@@ -348,4 +406,16 @@ public Locale getLocale() {
348406 public ItagItem getItagItem () {
349407 return null ;
350408 }
409+
410+ @ Override
411+ public String toString () {
412+ return "SubtitlesStream{"
413+ + "format=" + format
414+ + ", baseLocale=" + baseLocale
415+ + ", locale=" + locale
416+ + ", autoGenerated=" + autoGenerated
417+ + ", autoTranslated=" + autoTranslated
418+ + ", code='" + code + '\''
419+ + '}' ;
420+ }
351421}
0 commit comments