mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2025-04-28 16:00:33 +05:30
[SoundCloud] Move try-catch inside getOffsetFromUrl
This commit is contained in:
parent
aa6c17dc77
commit
485bfbca9d
@ -92,19 +92,13 @@ public class SoundcloudSearchExtractor extends SearchExtractor {
|
|||||||
} catch (final JsonParserException e) {
|
} catch (final JsonParserException e) {
|
||||||
throw new ParsingException("Could not parse json response", e);
|
throw new ParsingException("Could not parse json response", e);
|
||||||
}
|
}
|
||||||
final boolean hasNextPage;
|
|
||||||
try {
|
if (getOffsetFromUrl(page.getUrl()) + ITEMS_PER_PAGE <= totalResults) {
|
||||||
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) {
|
|
||||||
return new InfoItemsPage<>(collectItems(searchCollection),
|
return new InfoItemsPage<>(collectItems(searchCollection),
|
||||||
getNextPageFromCurrentUrl(page.getUrl(),
|
getNextPageFromCurrentUrl(page.getUrl(),
|
||||||
currentOffset -> currentOffset + ITEMS_PER_PAGE));
|
currentOffset -> currentOffset + ITEMS_PER_PAGE));
|
||||||
}
|
}
|
||||||
return new InfoItemsPage<>(collectItems(searchCollection), null);
|
return new InfoItemsPage<>(collectItems(searchCollection), null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -153,7 +147,7 @@ public class SoundcloudSearchExtractor extends SearchExtractor {
|
|||||||
|
|
||||||
private Page getNextPageFromCurrentUrl(final String currentUrl,
|
private Page getNextPageFromCurrentUrl(final String currentUrl,
|
||||||
final IntUnaryOperator newPageOffsetCalculator)
|
final IntUnaryOperator newPageOffsetCalculator)
|
||||||
throws MalformedURLException, UnsupportedEncodingException {
|
throws ParsingException {
|
||||||
final int currentPageOffset = getOffsetFromUrl(currentUrl);
|
final int currentPageOffset = getOffsetFromUrl(currentUrl);
|
||||||
|
|
||||||
return new Page(
|
return new Page(
|
||||||
@ -162,8 +156,11 @@ public class SoundcloudSearchExtractor extends SearchExtractor {
|
|||||||
"&offset=" + newPageOffsetCalculator.applyAsInt(currentPageOffset)));
|
"&offset=" + newPageOffsetCalculator.applyAsInt(currentPageOffset)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getOffsetFromUrl(final String url)
|
private int getOffsetFromUrl(final String url) throws ParsingException {
|
||||||
throws MalformedURLException, UnsupportedEncodingException {
|
try {
|
||||||
return Integer.parseInt(Parser.compatParseMap(new URL(url).getQuery()).get("offset"));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user