Skip to content

Commit 485bfbc

Browse files
committed
[SoundCloud] Move try-catch inside getOffsetFromUrl
1 parent aa6c17d commit 485bfbc

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSearchExtractor.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,13 @@ public InfoItemsPage<InfoItem> getPage(final Page page) throws IOException,
9292
} catch (final JsonParserException e) {
9393
throw new ParsingException("Could not parse json response", e);
9494
}
95-
final boolean hasNextPage;
96-
try {
97-
hasNextPage = getOffsetFromUrl(page.getUrl()) + ITEMS_PER_PAGE <= totalResults;
98-
} catch (MalformedURLException | UnsupportedEncodingException e) {
99-
throw new ParsingException("Could not get offset from page URL", e);
100-
}
101-
if (hasNextPage) {
95+
96+
if (getOffsetFromUrl(page.getUrl()) + ITEMS_PER_PAGE <= totalResults) {
10297
return new InfoItemsPage<>(collectItems(searchCollection),
10398
getNextPageFromCurrentUrl(page.getUrl(),
10499
currentOffset -> currentOffset + ITEMS_PER_PAGE));
105100
}
106101
return new InfoItemsPage<>(collectItems(searchCollection), null);
107-
108102
}
109103

110104
@Override
@@ -153,7 +147,7 @@ private InfoItemsCollector<InfoItem, InfoItemExtractor> collectItems(
153147

154148
private Page getNextPageFromCurrentUrl(final String currentUrl,
155149
final IntUnaryOperator newPageOffsetCalculator)
156-
throws MalformedURLException, UnsupportedEncodingException {
150+
throws ParsingException {
157151
final int currentPageOffset = getOffsetFromUrl(currentUrl);
158152

159153
return new Page(
@@ -162,8 +156,11 @@ private Page getNextPageFromCurrentUrl(final String currentUrl,
162156
"&offset=" + newPageOffsetCalculator.applyAsInt(currentPageOffset)));
163157
}
164158

165-
private int getOffsetFromUrl(final String url)
166-
throws MalformedURLException, UnsupportedEncodingException {
167-
return Integer.parseInt(Parser.compatParseMap(new URL(url).getQuery()).get("offset"));
159+
private int getOffsetFromUrl(final String url) throws ParsingException {
160+
try {
161+
return Integer.parseInt(Parser.compatParseMap(new URL(url).getQuery()).get("offset"));
162+
} catch (MalformedURLException | UnsupportedEncodingException e) {
163+
throw new ParsingException("Could not get offset from page URL", e);
164+
}
168165
}
169166
}

0 commit comments

Comments
 (0)