[SoundCloud] Move try-catch inside getOffsetFromUrl

This commit is contained in:
Stypox 2023-08-06 11:35:37 +02:00
parent aa6c17dc77
commit 485bfbca9d
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
1 changed files with 9 additions and 12 deletions

View File

@ -92,19 +92,13 @@ public class SoundcloudSearchExtractor extends SearchExtractor {
} catch (final JsonParserException e) {
throw new ParsingException("Could not parse json response", e);
}
final boolean hasNextPage;
try {
hasNextPage = getOffsetFromUrl(page.getUrl()) + ITEMS_PER_PAGE <= totalResults;
} catch (MalformedURLException | UnsupportedEncodingException e) {
throw new ParsingException("Could not get offset from page URL", e);
}
if (hasNextPage) {
if (getOffsetFromUrl(page.getUrl()) + ITEMS_PER_PAGE <= totalResults) {
return new InfoItemsPage<>(collectItems(searchCollection),
getNextPageFromCurrentUrl(page.getUrl(),
currentOffset -> currentOffset + ITEMS_PER_PAGE));
}
return new InfoItemsPage<>(collectItems(searchCollection), null);
}
@Override
@ -153,7 +147,7 @@ public class SoundcloudSearchExtractor extends SearchExtractor {
private Page getNextPageFromCurrentUrl(final String currentUrl,
final IntUnaryOperator newPageOffsetCalculator)
throws MalformedURLException, UnsupportedEncodingException {
throws ParsingException {
final int currentPageOffset = getOffsetFromUrl(currentUrl);
return new Page(
@ -162,8 +156,11 @@ public class SoundcloudSearchExtractor extends SearchExtractor {
"&offset=" + newPageOffsetCalculator.applyAsInt(currentPageOffset)));
}
private int getOffsetFromUrl(final String url)
throws MalformedURLException, UnsupportedEncodingException {
return Integer.parseInt(Parser.compatParseMap(new URL(url).getQuery()).get("offset"));
private int getOffsetFromUrl(final String url) throws ParsingException {
try {
return Integer.parseInt(Parser.compatParseMap(new URL(url).getQuery()).get("offset"));
} catch (MalformedURLException | UnsupportedEncodingException e) {
throw new ParsingException("Could not get offset from page URL", e);
}
}
}