Using Class instead of HashMap, removed downloadSubtitles method
This commit is contained in:
parent
6e3651fdf5
commit
72f9ac223e
|
@ -0,0 +1,31 @@
|
||||||
|
package org.schabi.newpipe.extractor;
|
||||||
|
|
||||||
|
public class Subtitles {
|
||||||
|
private String languageName;
|
||||||
|
private String languageCode;
|
||||||
|
private String URL;
|
||||||
|
private boolean autoGenerated;
|
||||||
|
|
||||||
|
public Subtitles(String languageName, String languageCode, String URL, boolean autoGenerated) {
|
||||||
|
this.languageName = languageName;
|
||||||
|
this.languageCode = languageCode;
|
||||||
|
this.URL = URL;
|
||||||
|
this.autoGenerated = autoGenerated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLanguageName() {
|
||||||
|
return languageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLanguageCode() {
|
||||||
|
return languageCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getURL() {
|
||||||
|
return URL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAutoGenerated() {
|
||||||
|
return autoGenerated;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,10 +3,7 @@ package org.schabi.newpipe.extractor.services.soundcloud;
|
||||||
import com.grack.nanojson.JsonObject;
|
import com.grack.nanojson.JsonObject;
|
||||||
import com.grack.nanojson.JsonParser;
|
import com.grack.nanojson.JsonParser;
|
||||||
import com.grack.nanojson.JsonParserException;
|
import com.grack.nanojson.JsonParserException;
|
||||||
import org.schabi.newpipe.extractor.Downloader;
|
import org.schabi.newpipe.extractor.*;
|
||||||
import org.schabi.newpipe.extractor.MediaFormat;
|
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
|
||||||
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
|
@ -195,13 +192,8 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HashMap<String, String[]> getSubtitlesList() throws IOException, ExtractionException, JsonParserException {
|
public Subtitles[] getSubtitles() throws IOException, ExtractionException, JsonParserException {
|
||||||
return new HashMap<>();
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String downloadSubtitles(String URL) throws IOException, ReCaptchaException {
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.mozilla.javascript.ScriptableObject;
|
||||||
import org.schabi.newpipe.extractor.Downloader;
|
import org.schabi.newpipe.extractor.Downloader;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
|
import org.schabi.newpipe.extractor.Subtitles;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
|
@ -421,40 +422,35 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HashMap<String, String[]> getSubtitlesList() throws IOException, ExtractionException, JsonParserException {
|
public Subtitles[] getSubtitles() throws IOException, ExtractionException, JsonParserException {
|
||||||
HashMap<String, String[]> result = new HashMap<>();
|
|
||||||
|
|
||||||
JsonObject playerConfig = getPlayerConfig(getPageHtml());
|
JsonObject playerConfig = getPlayerConfig(getPageHtml());
|
||||||
|
|
||||||
String playerResponse = playerConfig.getObject("args").getString("player_response");
|
String playerResponse = playerConfig.getObject("args").getString("player_response");
|
||||||
|
|
||||||
if (!JsonParser.object().from(playerResponse).has("captions")) {
|
if (!JsonParser.object().from(playerResponse).has("captions")) return null;
|
||||||
return new HashMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonObject captions = JsonParser.object().from(playerResponse).getObject("captions");
|
JsonObject captions = JsonParser.object().from(playerResponse).getObject("captions");
|
||||||
JsonArray captionsArray = captions.getObject("playerCaptionsTracklistRenderer").getArray("captionTracks");
|
JsonArray captionsArray = captions.getObject("playerCaptionsTracklistRenderer").getArray("captionTracks");
|
||||||
|
|
||||||
for (int x = 0; x < captionsArray.size(); x++) {
|
int captionsSize = captionsArray.size();
|
||||||
String captionsUrlAndName[] = new String[2];
|
Subtitles[] result = new Subtitles[captionsSize];
|
||||||
captionsUrlAndName[0] = captionsArray.getObject(x).getString("baseUrl");
|
|
||||||
captionsUrlAndName[1] = captionsArray.getObject(x).getObject("name").getString("simpleText");
|
|
||||||
String captionsLangCode = captionsArray.getObject(x).getString("vssId");
|
|
||||||
|
|
||||||
result.put(captionsLangCode, captionsUrlAndName);
|
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 captionsLangCode = captionsArray.getObject(x).getString("vssId");
|
||||||
|
String languageCode = captionsLangCode.replaceAll("(a\\.)|(\\.)", "");
|
||||||
|
|
||||||
|
boolean isAutoGenerated = captionsLangCode.startsWith("a.");
|
||||||
|
|
||||||
|
result[x] = new Subtitles(languageName, languageCode, URL, isAutoGenerated);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String downloadSubtitles(String URL) throws IOException, ReCaptchaException {
|
|
||||||
Downloader dl = NewPipe.getDownloader();
|
|
||||||
// Instead of the WebVTT 'vtt' we can use also Timed Text Markup Language 'ttml'
|
|
||||||
String URLasVTT = URL.replaceAll("&fmt=[^&]*", "&fmt=vtt");
|
|
||||||
return dl.download(URLasVTT);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamType getStreamType() throws ParsingException {
|
public StreamType getStreamType() throws ParsingException {
|
||||||
//todo: if implementing livestream support this value should be generated dynamically
|
//todo: if implementing livestream support this value should be generated dynamically
|
||||||
|
@ -703,7 +699,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
private String decryptSignature(String encryptedSig, String decryptionCode) throws DecryptException {
|
private String decryptSignature(String encryptedSig, String decryptionCode) throws DecryptException {
|
||||||
Context context = Context.enter();
|
Context context = Context.enter();
|
||||||
context.setOptimizationLevel(-1);
|
context.setOptimizationLevel(-1);
|
||||||
Object result = null;
|
Object result;
|
||||||
try {
|
try {
|
||||||
ScriptableObject scope = context.initStandardObjects();
|
ScriptableObject scope = context.initStandardObjects();
|
||||||
context.evaluateString(scope, decryptionCode, "decryptionCode", 1, null);
|
context.evaluateString(scope, decryptionCode, "decryptionCode", 1, null);
|
||||||
|
|
|
@ -23,13 +23,13 @@ package org.schabi.newpipe.extractor.stream;
|
||||||
import com.grack.nanojson.JsonParserException;
|
import com.grack.nanojson.JsonParserException;
|
||||||
import org.schabi.newpipe.extractor.Extractor;
|
import org.schabi.newpipe.extractor.Extractor;
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
|
import org.schabi.newpipe.extractor.Subtitles;
|
||||||
import org.schabi.newpipe.extractor.UrlIdHandler;
|
import org.schabi.newpipe.extractor.UrlIdHandler;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,8 +67,7 @@ public abstract class StreamExtractor extends Extractor {
|
||||||
public abstract List<AudioStream> getAudioStreams() throws IOException, ExtractionException;
|
public abstract List<AudioStream> getAudioStreams() throws IOException, ExtractionException;
|
||||||
public abstract List<VideoStream> getVideoStreams() throws IOException, ExtractionException;
|
public abstract List<VideoStream> getVideoStreams() throws IOException, ExtractionException;
|
||||||
public abstract List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionException;
|
public abstract List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionException;
|
||||||
public abstract HashMap<String, String[]> getSubtitlesList() throws IOException, ExtractionException, JsonParserException;
|
public abstract Subtitles[] getSubtitles() throws IOException, ExtractionException, JsonParserException;
|
||||||
public abstract String downloadSubtitles(String URL) throws IOException, ReCaptchaException;
|
|
||||||
|
|
||||||
public abstract StreamType getStreamType() throws ParsingException;
|
public abstract StreamType getStreamType() throws ParsingException;
|
||||||
public abstract StreamInfoItem getNextVideo() throws IOException, ExtractionException;
|
public abstract StreamInfoItem getNextVideo() throws IOException, ExtractionException;
|
||||||
|
|
Loading…
Reference in New Issue