|
1 | | -package org.schabi.newpipe.extractor.stream; |
2 | | - |
3 | | -import org.schabi.newpipe.extractor.MediaFormat; |
4 | | - |
5 | | -import java.io.Serializable; |
6 | | -import java.util.Locale; |
7 | | - |
8 | | -public class SubtitlesStream extends Stream implements Serializable { |
9 | | - private final MediaFormat format; |
10 | | - private final Locale locale; |
11 | | - private final boolean autoGenerated; |
12 | | - private final String code; |
13 | | - |
14 | | - public SubtitlesStream(MediaFormat format, String languageCode, String url, boolean autoGenerated) { |
15 | | - super(url, format); |
16 | | - |
17 | | - /* |
18 | | - * Locale.forLanguageTag only for API >= 21 |
19 | | - * Locale.Builder only for API >= 21 |
20 | | - * Country codes doesn't work well without |
21 | | - */ |
22 | | - final String[] splits = languageCode.split("-"); |
23 | | - switch (splits.length) { |
24 | | - default: |
25 | | - this.locale = new Locale(splits[0]); |
26 | | - break; |
27 | | - case 3: |
28 | | - this.locale = new Locale(splits[0], splits[1], splits[2]);// complex variants doesn't work! |
29 | | - break; |
30 | | - case 2: |
31 | | - this.locale = new Locale(splits[0], splits[1]); |
32 | | - break; |
33 | | - } |
34 | | - this.code = languageCode; |
35 | | - this.format = format; |
36 | | - this.autoGenerated = autoGenerated; |
37 | | - } |
38 | | - |
39 | | - public String getExtension() { |
40 | | - return format.suffix; |
41 | | - } |
42 | | - |
43 | | - public boolean isAutoGenerated() { |
44 | | - return autoGenerated; |
45 | | - } |
46 | | - |
47 | | - @Override |
48 | | - public boolean equalStats(Stream cmp) { |
49 | | - return super.equalStats(cmp) && |
50 | | - cmp instanceof SubtitlesStream && |
51 | | - code.equals(((SubtitlesStream) cmp).code) && |
52 | | - autoGenerated == ((SubtitlesStream) cmp).autoGenerated; |
53 | | - } |
54 | | - |
55 | | - public String getDisplayLanguageName() { |
56 | | - return locale.getDisplayName(locale); |
57 | | - } |
58 | | - |
59 | | - public String getLanguageTag() { |
60 | | - return code; |
61 | | - } |
62 | | - |
63 | | - public Locale getLocale() { |
64 | | - return locale; |
65 | | - } |
66 | | - |
67 | | -} |
| 1 | +package org.schabi.newpipe.extractor.stream; |
| 2 | + |
| 3 | +import org.schabi.newpipe.extractor.MediaFormat; |
| 4 | + |
| 5 | +import java.io.Serializable; |
| 6 | +import java.util.Locale; |
| 7 | + |
| 8 | +public class SubtitlesStream extends Stream implements Serializable { |
| 9 | + private final MediaFormat format; |
| 10 | + private final Locale locale; |
| 11 | + private final boolean autoGenerated; |
| 12 | + private final String code; |
| 13 | + |
| 14 | + public SubtitlesStream(MediaFormat format, String languageCode, String url, boolean autoGenerated) { |
| 15 | + super(url, format); |
| 16 | + |
| 17 | + /* |
| 18 | + * Locale.forLanguageTag only for API >= 21 |
| 19 | + * Locale.Builder only for API >= 21 |
| 20 | + * Country codes doesn't work well without |
| 21 | + */ |
| 22 | + final String[] splits = languageCode.split("-"); |
| 23 | + switch (splits.length) { |
| 24 | + default: |
| 25 | + this.locale = new Locale(splits[0]); |
| 26 | + break; |
| 27 | + case 3: |
| 28 | + this.locale = new Locale(splits[0], splits[1], splits[2]);// complex variants doesn't work! |
| 29 | + break; |
| 30 | + case 2: |
| 31 | + this.locale = new Locale(splits[0], splits[1]); |
| 32 | + break; |
| 33 | + } |
| 34 | + this.code = languageCode; |
| 35 | + this.format = format; |
| 36 | + this.autoGenerated = autoGenerated; |
| 37 | + } |
| 38 | + |
| 39 | + public String getExtension() { |
| 40 | + return format.suffix; |
| 41 | + } |
| 42 | + |
| 43 | + public boolean isAutoGenerated() { |
| 44 | + return autoGenerated; |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public boolean equalStats(Stream cmp) { |
| 49 | + return super.equalStats(cmp) && |
| 50 | + cmp instanceof SubtitlesStream && |
| 51 | + code.equals(((SubtitlesStream) cmp).code) && |
| 52 | + autoGenerated == ((SubtitlesStream) cmp).autoGenerated; |
| 53 | + } |
| 54 | + |
| 55 | + public String getDisplayLanguageName() { |
| 56 | + return locale.getDisplayName(locale); |
| 57 | + } |
| 58 | + |
| 59 | + public String getLanguageTag() { |
| 60 | + return code; |
| 61 | + } |
| 62 | + |
| 63 | + public Locale getLocale() { |
| 64 | + return locale; |
| 65 | + } |
| 66 | + |
| 67 | +} |
0 commit comments