mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2025-04-28 07:50:34 +05:30
Move BandcampExtractorHelper.getJsonData(String, String) to JsonUtils
This commit is contained in:
parent
70814dcfef
commit
a1688fe953
@ -28,23 +28,6 @@ public class BandcampExtractorHelper {
|
|||||||
public static final String BASE_URL = "https://bandcamp.com";
|
public static final String BASE_URL = "https://bandcamp.com";
|
||||||
public static final String BASE_API_URL = BASE_URL + "/api";
|
public static final String BASE_API_URL = BASE_URL + "/api";
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Get an attribute of a web page as JSON
|
|
||||||
*
|
|
||||||
* <p>Originally a part of bandcampDirect.</p>
|
|
||||||
*
|
|
||||||
* @param html The HTML where the JSON we're looking for is stored inside a
|
|
||||||
* variable inside some JavaScript block
|
|
||||||
* @param variable Name of the variable
|
|
||||||
* @return The JsonObject stored in the variable with this name
|
|
||||||
*/
|
|
||||||
public static JsonObject getJsonData(final String html, final String variable)
|
|
||||||
throws JsonParserException, ArrayIndexOutOfBoundsException {
|
|
||||||
final Document document = Jsoup.parse(html);
|
|
||||||
final String json = document.getElementsByAttribute(variable).attr(variable);
|
|
||||||
return JsonParser.object().from(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translate all these parameters together to the URL of the corresponding album or track
|
* Translate all these parameters together to the URL of the corresponding album or track
|
||||||
* using the mobile API
|
* using the mobile API
|
||||||
|
@ -21,7 +21,7 @@ import javax.annotation.Nonnull;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImageUrl;
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImageUrl;
|
||||||
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getJsonData;
|
import static org.schabi.newpipe.extractor.utils.JsonUtils.getJsonData;
|
||||||
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampStreamExtractor.getAlbumInfoJson;
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampStreamExtractor.getAlbumInfoJson;
|
||||||
|
|
||||||
public class BandcampPlaylistExtractor extends PlaylistExtractor {
|
public class BandcampPlaylistExtractor extends PlaylistExtractor {
|
||||||
|
@ -17,6 +17,7 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|||||||
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
|
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
|
||||||
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
||||||
import org.schabi.newpipe.extractor.stream.*;
|
import org.schabi.newpipe.extractor.stream.*;
|
||||||
|
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
||||||
import org.schabi.newpipe.extractor.utils.Utils;
|
import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -62,7 +63,7 @@ public class BandcampStreamExtractor extends StreamExtractor {
|
|||||||
*/
|
*/
|
||||||
public static JsonObject getAlbumInfoJson(final String html) throws ParsingException {
|
public static JsonObject getAlbumInfoJson(final String html) throws ParsingException {
|
||||||
try {
|
try {
|
||||||
return BandcampExtractorHelper.getJsonData(html, "data-tralbum");
|
return JsonUtils.getJsonData(html, "data-tralbum");
|
||||||
} catch (final JsonParserException e) {
|
} catch (final JsonParserException e) {
|
||||||
throw new ParsingException("Faulty JSON; page likely does not contain album data", e);
|
throw new ParsingException("Faulty JSON; page likely does not contain album data", e);
|
||||||
} catch (final ArrayIndexOutOfBoundsException e) {
|
} catch (final ArrayIndexOutOfBoundsException e) {
|
||||||
|
@ -9,6 +9,7 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|||||||
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
||||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
|
||||||
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper;
|
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper;
|
||||||
|
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -25,7 +26,7 @@ public class BandcampChannelLinkHandlerFactory extends ListLinkHandlerFactory {
|
|||||||
final String response = NewPipe.getDownloader().get(url).responseBody();
|
final String response = NewPipe.getDownloader().get(url).responseBody();
|
||||||
|
|
||||||
// Use band data embedded in website to extract ID
|
// Use band data embedded in website to extract ID
|
||||||
final JsonObject bandData = BandcampExtractorHelper.getJsonData(response, "data-band");
|
final JsonObject bandData = JsonUtils.getJsonData(response, "data-band");
|
||||||
|
|
||||||
return String.valueOf(bandData.getLong("id"));
|
return String.valueOf(bandData.getLong("id"));
|
||||||
|
|
||||||
|
@ -2,6 +2,10 @@ package org.schabi.newpipe.extractor.utils;
|
|||||||
|
|
||||||
import com.grack.nanojson.JsonArray;
|
import com.grack.nanojson.JsonArray;
|
||||||
import com.grack.nanojson.JsonObject;
|
import com.grack.nanojson.JsonObject;
|
||||||
|
import com.grack.nanojson.JsonParser;
|
||||||
|
import com.grack.nanojson.JsonParserException;
|
||||||
|
import org.jsoup.Jsoup;
|
||||||
|
import org.jsoup.nodes.Document;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -99,4 +103,34 @@ public class JsonUtils {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Get an attribute of a web page as JSON
|
||||||
|
*
|
||||||
|
* <p>Originally a part of bandcampDirect.</p>
|
||||||
|
* <p>Example HTML:</p>
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* <p data-town="{"name":"Mycenae","country":"Greece"}">This is Sparta!</p>
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
* <p>Calling this function to get the attribute <code>data-town</code> returns the JsonObject for</p>
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* {
|
||||||
|
* "name": "Mycenae",
|
||||||
|
* "country": "Greece"
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
* @param html The HTML where the JSON we're looking for is stored inside a
|
||||||
|
* variable inside some JavaScript block
|
||||||
|
* @param variable Name of the variable
|
||||||
|
* @return The JsonObject stored in the variable with this name
|
||||||
|
*/
|
||||||
|
public static JsonObject getJsonData(final String html, final String variable)
|
||||||
|
throws JsonParserException, ArrayIndexOutOfBoundsException {
|
||||||
|
final Document document = Jsoup.parse(html);
|
||||||
|
final String json = document.getElementsByAttribute(variable).attr(variable);
|
||||||
|
return JsonParser.object().from(json);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user