Skip to content

Commit

Permalink
Add method for fetching embed rumble video id
Browse files Browse the repository at this point in the history
  • Loading branch information
Benau committed Sep 8, 2024
1 parent ff22536 commit 9de2c95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,17 @@ public static synchronized Map<String, List<String>> getMinimalHeaders() {
}
return HEADERS;
}

public static String getEmbedVideoId(final String rb) {
final String VALID_URL = "https?://(?:www\\.)?rumble\\.com/embed/(?:[0-9a-z]+\\.)?(?<id>[0-9a-z]+)";
final String EMBED_REGEX = "(?:<(?:script|iframe)[^>]+\\bsrc=|[\"']embedUrl[\"']\\s*:\\s*)[\"'](?<url>" + VALID_URL + ")";
Pattern pattern = Pattern.compile(EMBED_REGEX);
Matcher matcher = pattern.matcher(rb);
if (matcher.find()) {
// Remove v (first character) from the id
return matcher.group(2).substring(1);
} else {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public class RumbleStreamExtractor extends StreamExtractor {

private Document doc;
JsonObject embedJsonStreamInfoObj;
private String realVideoId = null;

private int ageLimit = -1;
private List<VideoStream> videoStreams;
Expand Down Expand Up @@ -398,12 +397,13 @@ public void onFetchPage(@Nonnull final Downloader downloader)
throws IOException, ExtractionException {

final Response response = downloader.get(getUrl());
doc = Jsoup.parse(response.responseBody(), getUrl());
final String rb = response.responseBody();
doc = Jsoup.parse(rb, getUrl());

checkIfVideoIsAccessible(response);

final String queryUrl = "https://rumble.com/embedJS/u3/?request=video&ver=2&v="
+ extractAndGetRealVideoId();
final String queryUrl = "https://rumble.com/embedJS/u3/?request=video&ver=2&v=v"
+ RumbleParsingHelper.getEmbedVideoId(rb);

final Response response2 = downloader.get(
queryUrl);
Expand Down Expand Up @@ -504,35 +504,6 @@ public List<SubtitlesStream> getSubtitles(final MediaFormat format) {
return Collections.emptyList();
}

private String extractAndGetRealVideoId() {
if (realVideoId != null) {
return realVideoId;
}

final String jsonString =
doc.getElementsByAttributeValueContaining("type", "application/ld+json")
.first().childNodes().get(0).toString();

// extract the internal video id for a rumble video
final JsonArray jsonObj;
try {
jsonObj = JsonParser.array().from(jsonString);
final String embedUrl = jsonObj.getObject(0).getString("embedUrl");


final URL url = Utils.stringToURL(embedUrl);
final String[] splitPaths = url.getPath().split("/");

if (splitPaths.length == 3 && splitPaths[1].equalsIgnoreCase("embed")) {
realVideoId = splitPaths[2];
}

} catch (final MalformedURLException | JsonParserException e) {
e.printStackTrace();
}
return realVideoId;
}

private long getLiveViewCount() throws ParsingException {
final Pattern matchChecksum = Pattern.compile("viewer_id: \"(.*)\"");
final Matcher matcher = matchChecksum.matcher(doc.toString());
Expand Down

0 comments on commit 9de2c95

Please sign in to comment.