From a63128bd452e03c6e3a3e6088ee3e05321c6fd7b Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Mon, 12 Sep 2016 00:51:03 +0200 Subject: [PATCH] add addblock --- .../newpipe/extractor/FoundAdException.java | 30 +++++++++++++++++++ .../extractor/StreamPreviewInfoCollector.java | 4 ++- .../youtube/YoutubeStreamUrlIdHandler.java | 6 ++-- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/extractor/FoundAdException.java diff --git a/app/src/main/java/org/schabi/newpipe/extractor/FoundAdException.java b/app/src/main/java/org/schabi/newpipe/extractor/FoundAdException.java new file mode 100644 index 000000000..036ec902a --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/extractor/FoundAdException.java @@ -0,0 +1,30 @@ +package org.schabi.newpipe.extractor; + +/** + * Created by Christian Schabesberger on 12.09.16. + * + * Copyright (C) Christian Schabesberger 2016 + * FoundAdException.java is part of NewPipe. + * + * NewPipe is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NewPipe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NewPipe. If not, see . + */ + +public class FoundAdException extends ParsingException { + public FoundAdException(String message) { + super(message); + } + public FoundAdException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoCollector.java b/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoCollector.java index 676e0988c..7c890c0f3 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoCollector.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoCollector.java @@ -62,7 +62,7 @@ public class StreamPreviewInfoCollector { resultItem.title = extractor.getTitle(); resultItem.stream_type = extractor.getStreamType(); - // optional iformation + // optional information try { resultItem.duration = extractor.getDuration(); } catch (Exception e) { @@ -89,6 +89,8 @@ public class StreamPreviewInfoCollector { addError(e); } itemList.add(resultItem); + } catch(FoundAdException ae) { + System.out.println("AD_WARNING: " + ae.getMessage()); } catch (Exception e) { addError(e); } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandler.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandler.java index 4ff51b540..9096ffbb3 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandler.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandler.java @@ -1,5 +1,6 @@ package org.schabi.newpipe.extractor.services.youtube; +import org.schabi.newpipe.extractor.FoundAdException; import org.schabi.newpipe.extractor.Parser; import org.schabi.newpipe.extractor.ParsingException; import org.schabi.newpipe.extractor.UrlIdHandler; @@ -56,8 +57,9 @@ public class YoutubeStreamUrlIdHandler implements UrlIdHandler { else if(url.contains("vnd.youtube")) { id = Parser.matchGroup1("([\\-a-zA-Z0-9_]{11}).*", url); - } - else { + } else if(url.contains("googleads")) { + throw new FoundAdException("Error found add: " + url); + } else { id = Parser.matchGroup1("[?&]v=([\\-a-zA-Z0-9_]{11})", url); } }