Skip to content

Commit

Permalink
RUMBLE: fix extraction of live view count in RumbleStreamExtractor
Browse files Browse the repository at this point in the history
  • Loading branch information
evermind-zz committed Sep 6, 2023
1 parent 3ab6a66 commit 1918e3a
Showing 1 changed file with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.schabi.newpipe.extractor.stream.Stream.ID_UNKNOWN;
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
Expand All @@ -68,11 +70,9 @@ public class RumbleStreamExtractor extends StreamExtractor {
private int ageLimit = -1;
private List<VideoStream> videoStreams;
private String hlsUrl = "";
private final String viewerId;

public RumbleStreamExtractor(final StreamingService service, final LinkHandler linkHandler) {
super(service, linkHandler);
viewerId = createRandomViewerId();
}

@Nonnull
Expand Down Expand Up @@ -395,6 +395,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
embedJsonStreamInfoObj = JsonParser.object().from(response2.responseBody());
} catch (final JsonParserException e) {
e.printStackTrace();
throw new ParsingException("Could not read json from: " + queryUrl);
}
}

Expand Down Expand Up @@ -497,22 +498,36 @@ private String extractAndGetRealVideoId() {
return realVideoId;
}

private long getLiveViewCount() {
private long getLiveViewCount() throws ParsingException {
final Pattern matchChecksum = Pattern.compile("viewer_id: \"(.*)\"");
final Matcher matcher = matchChecksum.matcher(doc.toString());
if (!matcher.find()) {
throw new ParsingException("Could not extract viewer_id");
}
final String viewerId = matcher.group(1);

return retrieveLiveStreamViewerCount(getDownloader(),
extractAndGetRealVideoId().substring(1), // the first char is not used here
retrieveNumericVideoId(),
viewerId);
}

private long retrieveLiveStreamViewerCount(final Downloader downloader,
final String video,
final String videoNumericId,
final String theViewerId) {
try {
final Response response =
downloader.get("https://rumble.com/service.php?video="
+ video

// This is the post version of below get version. It does not work but kept here
// for maybe later:)
// final Response response = downloader
// .post("https://wn0.rumble.com/service.php?api=7&name=video.watching-now",
// null,
// ("video_id=" + videoId + "&viewer_id=" + theViewerId).getBytes());
final Response response = downloader
.get("https://wn0.rumble.com/service.php?video_id="
+ videoNumericId
+ "&viewer_id="
+ theViewerId
+ "&name=video.watching_now");
+ "&name=video.watching-now");
final JsonObject jsonObject =
JsonParser.object().from(response.responseBody());
return jsonObject.getObject("data").getLong("viewer_count", -1);
Expand All @@ -523,9 +538,14 @@ private long retrieveLiveStreamViewerCount(final Downloader downloader,
return -1;
}

// as of somewhere in 2023 it is no longer working. Kept for reference
private String createRandomViewerId() {
// the magic 8 comes from: $$.generateRandomID(8));
// from the html page that belongs to the video
return YoutubeParsingHelper.generateTParameter().substring(0, 8);
}

private String retrieveNumericVideoId() {
return embedJsonStreamInfoObj.get("vid").toString();
}
}

0 comments on commit 1918e3a

Please sign in to comment.