Changed the way of getting subtitles data type, removed language name from Subtitles class
This commit is contained in:
parent
79e49ce374
commit
310b34558b
|
@ -1,21 +1,20 @@
|
|||
package org.schabi.newpipe.extractor;
|
||||
|
||||
import org.schabi.newpipe.extractor.stream.SubtitlesFormat;
|
||||
|
||||
public class Subtitles {
|
||||
private String languageName;
|
||||
private String languageCode;
|
||||
private String URL;
|
||||
private SubtitlesFormat format;
|
||||
private String languageCode, URL;
|
||||
private boolean autoGenerated;
|
||||
|
||||
public Subtitles(String languageName, String languageCode, String URL, boolean autoGenerated) {
|
||||
this.languageName = languageName;
|
||||
public Subtitles(SubtitlesFormat format, String languageCode, String URL, boolean autoGenerated) {
|
||||
this.format = format;
|
||||
this.languageCode = languageCode;
|
||||
this.URL = URL;
|
||||
this.autoGenerated = autoGenerated;
|
||||
}
|
||||
|
||||
public String getLanguageName() {
|
||||
return languageName;
|
||||
}
|
||||
public SubtitlesFormat getFileType() { return format; }
|
||||
|
||||
public String getLanguageCode() {
|
||||
return languageCode;
|
||||
|
|
|
@ -12,9 +12,7 @@ import org.schabi.newpipe.extractor.stream.*;
|
|||
import org.schabi.newpipe.extractor.utils.Parser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class SoundcloudStreamExtractor extends StreamExtractor {
|
||||
private JsonObject track;
|
||||
|
@ -150,7 +148,12 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Subtitles[] getSubtitles() throws IOException, ExtractionException, JsonParserException {
|
||||
public List<Subtitles> getSubtitlesDefault() throws IOException, ExtractionException, JsonParserException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Subtitles> getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException, JsonParserException {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -380,7 +380,12 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Subtitles[] getSubtitles() throws IOException, ExtractionException, JsonParserException {
|
||||
public List<Subtitles> getSubtitlesDefault() throws IOException, ExtractionException, JsonParserException {
|
||||
return getSubtitles(SubtitlesFormat.TTML);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Subtitles> getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException, JsonParserException {
|
||||
JsonObject playerConfig = getPlayerConfig(getPageHtml());
|
||||
String playerResponse = playerConfig.getObject("args").getString("player_response");
|
||||
|
||||
|
@ -394,19 +399,18 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||
// Should not happen, if there is the "captions" object, it should always has some captions in it
|
||||
if(captionsSize == 0) return null;
|
||||
|
||||
Subtitles[] result = new Subtitles[captionsSize];
|
||||
List<Subtitles> result = new ArrayList<>();
|
||||
for (int x = 0; x < captionsSize; x++) {
|
||||
String baseUrl = captionsArray.getObject(x).getString("baseUrl");
|
||||
|
||||
String languageName = captionsArray.getObject(x).getObject("name").getString("simpleText");
|
||||
String URL = baseUrl.replaceAll("&fmt=[^&]*", "&fmt=vtt");
|
||||
String extension = format.getExtension();
|
||||
|
||||
String URL = baseUrl.replaceAll("&fmt=[^&]*", "&fmt=" + extension);
|
||||
String captionsLangCode = captionsArray.getObject(x).getString("vssId");
|
||||
String languageCode = captionsLangCode.replaceAll("(a\\.)|(\\.)", "");
|
||||
|
||||
boolean isAutoGenerated = captionsLangCode.startsWith("a.");
|
||||
String languageCode = captionsLangCode.replaceFirst((isAutoGenerated) ? "a." : ".", "");
|
||||
|
||||
result[x] = new Subtitles(languageName, languageCode, URL, isAutoGenerated);
|
||||
result.add(new Subtitles(format, languageCode, URL, isAutoGenerated));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -112,7 +112,9 @@ public abstract class StreamExtractor extends Extractor {
|
|||
public abstract List<AudioStream> getAudioStreams() throws IOException, ExtractionException;
|
||||
public abstract List<VideoStream> getVideoStreams() throws IOException, ExtractionException;
|
||||
public abstract List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionException;
|
||||
public abstract Subtitles[] getSubtitles() throws IOException, ExtractionException, JsonParserException;
|
||||
public abstract List<Subtitles> getSubtitlesDefault() throws IOException, ExtractionException, JsonParserException;
|
||||
|
||||
public abstract List<Subtitles> getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException, JsonParserException;
|
||||
|
||||
public abstract StreamType getStreamType() throws ParsingException;
|
||||
public abstract StreamInfoItem getNextVideo() throws IOException, ExtractionException;
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package org.schabi.newpipe.extractor.stream;
|
||||
|
||||
import org.schabi.newpipe.extractor.Subtitles;
|
||||
|
||||
public enum SubtitlesFormat {
|
||||
// YouTube subtitles formats
|
||||
// TRANSCRIPT(3) is default YT format based on TTML,
|
||||
// but unlike VTT or TTML, it is NOT W3 standard
|
||||
VTT (0x0, "vtt"),
|
||||
TTML (0x1, "ttml"),
|
||||
TRANSCRIPT1 (0x2, "srv1"),
|
||||
TRANSCRIPT2 (0x3, "srv2"),
|
||||
TRANSCRIPT3 (0x4, "srv3");
|
||||
|
||||
private int id;
|
||||
private String extension;
|
||||
|
||||
SubtitlesFormat(int id, String extension) {
|
||||
this.id = id;
|
||||
this.extension = extension;
|
||||
}
|
||||
|
||||
public String getExtension() {
|
||||
return extension;
|
||||
}
|
||||
}
|
|
@ -5,13 +5,16 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.Subtitles;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
|
||||
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||
import org.schabi.newpipe.extractor.stream.SubtitlesFormat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||
|
@ -104,7 +107,14 @@ public class SoundcloudStreamExtractorDefaultTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetSubtitles() throws IOException, ExtractionException, JsonParserException {
|
||||
assertTrue(extractor.getSubtitles() == null);
|
||||
public void testGetSubtitlesListDefault() throws IOException, ExtractionException, JsonParserException {
|
||||
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
|
||||
assertTrue(extractor.getSubtitlesDefault() == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSubtitlesList() throws IOException, ExtractionException, JsonParserException {
|
||||
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
|
||||
assertTrue(extractor.getSubtitles(SubtitlesFormat.VTT) == null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,7 @@ import org.schabi.newpipe.Downloader;
|
|||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
|
||||
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||
import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||
import org.schabi.newpipe.extractor.stream.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
@ -151,9 +148,15 @@ public class YoutubeStreamExtractorDefaultTest {
|
|||
assertTrue(relatedVideos.getErrors().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSubtitlesListDefault() throws IOException, ExtractionException, JsonParserException {
|
||||
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
|
||||
assertTrue(extractor.getSubtitlesDefault() == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSubtitlesList() throws IOException, ExtractionException, JsonParserException {
|
||||
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
|
||||
assertTrue(extractor.getSubtitles() == null);
|
||||
assertTrue(extractor.getSubtitles(SubtitlesFormat.VTT) == null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.schabi.newpipe.extractor.NewPipe;
|
|||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
||||
import org.schabi.newpipe.extractor.stream.SubtitlesFormat;
|
||||
import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -105,8 +106,16 @@ public class YoutubeStreamExtractorRestrictedTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetSubtitles() throws IOException, ExtractionException, JsonParserException {
|
||||
assertTrue(extractor.getSubtitles() == null);
|
||||
public void testGetSubtitlesListDefault() throws IOException, ExtractionException, JsonParserException {
|
||||
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
|
||||
assertTrue(extractor.getSubtitlesDefault() == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSubtitlesList() throws IOException, ExtractionException, JsonParserException {
|
||||
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
|
||||
assertTrue(extractor.getSubtitles(SubtitlesFormat.VTT) == null);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue