1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-24 17:10:33 +00:00

better detection for livestreams

This commit is contained in:
Christian Schabesberger 2016-02-21 22:25:45 +01:00
parent 851028997a
commit e08aa14eab

View File

@ -191,14 +191,17 @@ public class YoutubeStreamExtractor implements StreamExtractor {
JSONObject ytPlayerConfig; JSONObject ytPlayerConfig;
//attempt to load the youtube js player JSON arguments //attempt to load the youtube js player JSON arguments
String ps = ""; //used to determine if this is a livestream or not boolean isLiveStream = false; //used to determine if this is a livestream or not
try { try {
ytPlayerConfigRaw = ytPlayerConfigRaw =
Parser.matchGroup1("ytplayer.config\\s*=\\s*(\\{.*?\\});", pageContent); Parser.matchGroup1("ytplayer.config\\s*=\\s*(\\{.*?\\});", pageContent);
ytPlayerConfig = new JSONObject(ytPlayerConfigRaw); ytPlayerConfig = new JSONObject(ytPlayerConfigRaw);
playerArgs = ytPlayerConfig.getJSONObject("args"); playerArgs = ytPlayerConfig.getJSONObject("args");
if(playerArgs.has("ps")) {
ps = playerArgs.get("ps").toString(); // check if we have a live stream. We need to filter it, since its not yet supported.
if((playerArgs.has("ps") && playerArgs.get("ps").toString().equals("live"))
|| (playerArgs.get("url_encoded_fmt_stream_map").toString().isEmpty())) {
isLiveStream = true;
} }
} catch (Parser.RegexException e) { } catch (Parser.RegexException e) {
String errorReason = findErrorReason(doc); String errorReason = findErrorReason(doc);
@ -213,7 +216,7 @@ public class YoutubeStreamExtractor implements StreamExtractor {
} catch (JSONException e) { } catch (JSONException e) {
throw new ParsingException("Could not parse yt player config", e); throw new ParsingException("Could not parse yt player config", e);
} }
if (ps.equals("live")) { if (isLiveStream) {
throw new LiveStreamException(); throw new LiveStreamException();
} }