Skip to content

Commit f742a6b

Browse files
committed
code optimization
1 parent 9701c7d commit f742a6b

4 files changed

Lines changed: 9 additions & 38 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCConferenceLinkHandlerFactory.java

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package org.schabi.newpipe.extractor.services.media_ccc.linkHandler;
22

3-
import org.schabi.newpipe.extractor.exceptions.FoundAdException;
43
import org.schabi.newpipe.extractor.exceptions.ParsingException;
54
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
65
import org.schabi.newpipe.extractor.utils.Parser;
7-
import org.schabi.newpipe.extractor.utils.Utils;
86

9-
import java.net.MalformedURLException;
10-
import java.net.URL;
117
import java.util.List;
128

139
public class MediaCCCConferenceLinkHandlerFactory extends ListLinkHandlerFactory {
@@ -18,41 +14,22 @@ public String getUrl(String id, List<String> contentFilter, String sortFilter) t
1814
}
1915

2016
@Override
21-
public String getId(String urlString) throws ParsingException {
22-
if (urlString.startsWith("https://api.media.ccc.de/public/conferences/")) {
23-
return urlString.replace("https://api.media.ccc.de/public/conferences/", "");
24-
} else if (urlString.startsWith("https://media.ccc.de/c/")) {
25-
return Parser.matchGroup1("https://media.ccc.de/c/([^?#]*)", urlString);
17+
public String getId(String url) throws ParsingException {
18+
if (url.startsWith("https://api.media.ccc.de/public/conferences/")) {
19+
return url.replace("https://api.media.ccc.de/public/conferences/", "");
20+
} else if (url.startsWith("https://media.ccc.de/c/")) {
21+
return Parser.matchGroup1("https://media.ccc.de/c/([^?#]*)", url);
22+
} else if (url.startsWith("https://media.ccc.de/b/")) {
23+
return Parser.matchGroup1("https://media.ccc.de/b/([^?#]*)", url);
2624
}
27-
28-
URL url;
29-
try {
30-
url = Utils.stringToURL(urlString);
31-
} catch (MalformedURLException e) {
32-
throw new IllegalArgumentException("The given URL is not valid");
33-
}
34-
35-
String path = url.getPath();
36-
// remove leading "/" of URL-path if URL-path is given
37-
if (!path.isEmpty()) {
38-
path = path.substring(1);
39-
}
40-
41-
if (path.contains("b/")) {
42-
return path.substring(2);
43-
}
44-
4525
throw new ParsingException("Could not get id from url: " + url);
46-
4726
}
4827

4928
@Override
5029
public boolean onAcceptUrl(String url) throws ParsingException {
5130
try {
5231
getId(url);
5332
return true;
54-
} catch (FoundAdException fe) {
55-
throw fe;
5633
} catch (ParsingException e) {
5734
return false;
5835
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCStreamLinkHandlerFactory.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public String getId(String urlString) throws ParsingException {
3030
path = path.substring(1);
3131
}
3232

33-
if (path.contains("v/")) {
33+
if (path.startsWith("v/")) {
3434
return path.substring(2);
3535
}
3636

@@ -47,8 +47,6 @@ public boolean onAcceptUrl(String url) throws ParsingException {
4747
try {
4848
getId(url);
4949
return true;
50-
} catch (FoundAdException fe) {
51-
throw fe;
5250
} catch (ParsingException e) {
5351
return false;
5452
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCConferenceExtractorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCConferenceExtractor;
88

99
import static junit.framework.TestCase.assertEquals;
10-
import static junit.framework.TestCase.assertTrue;
10+
import static org.junit.Assert.assertTrue;
1111
import static org.schabi.newpipe.extractor.ServiceList.MediaCCC;
1212

1313
/**

extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCStreamExtractorTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
package org.schabi.newpipe.extractor.services.media_ccc;
22

3-
import com.grack.nanojson.JsonObject;
43
import org.junit.Assert;
54
import org.junit.BeforeClass;
65
import org.junit.Test;
76
import org.schabi.newpipe.DownloaderTestImpl;
87
import org.schabi.newpipe.extractor.NewPipe;
9-
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
108
import org.schabi.newpipe.extractor.exceptions.ParsingException;
119
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCStreamExtractor;
1210

13-
import java.io.IOException;
1411
import java.text.ParseException;
1512
import java.text.SimpleDateFormat;
1613
import java.util.Calendar;
1714

1815
import static java.util.Objects.requireNonNull;
1916
import static junit.framework.TestCase.assertEquals;
20-
import static org.junit.Assert.assertFalse;
2117
import static org.schabi.newpipe.extractor.ServiceList.MediaCCC;
2218

2319
/**

0 commit comments

Comments
 (0)