From e08aa14eab347de1709ea05d86b9d77a7cb0f63c Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 21 Feb 2016 22:25:45 +0100 Subject: [PATCH] better detection for livestreams --- .../services/youtube/YoutubeStreamExtractor.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java index 39a465393..e15de78ab 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java @@ -191,14 +191,17 @@ public class YoutubeStreamExtractor implements StreamExtractor { JSONObject ytPlayerConfig; //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 { ytPlayerConfigRaw = Parser.matchGroup1("ytplayer.config\\s*=\\s*(\\{.*?\\});", pageContent); ytPlayerConfig = new JSONObject(ytPlayerConfigRaw); 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) { String errorReason = findErrorReason(doc); @@ -213,7 +216,7 @@ public class YoutubeStreamExtractor implements StreamExtractor { } catch (JSONException e) { throw new ParsingException("Could not parse yt player config", e); } - if (ps.equals("live")) { + if (isLiveStream) { throw new LiveStreamException(); }