Skip to content

Commit

Permalink
Fixes tiktokUtils.js getRoomId() (#212)
Browse files Browse the repository at this point in the history
Regex wasn't able to find a proper "roomId" text since there is an empty one first and a few broken others. This loop tries to find an usable one until the end of the string.
  • Loading branch information
fmalk authored Jul 10, 2024
1 parent b39c08d commit 1a285c3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/lib/tiktokUtils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
let uu = [];

function getRoomIdFromMainPageHtml(mainPageHtml) {
let idx = 0;
do {
// loop thru many "room" excerpts and look for a match
idx = mainPageHtml.indexOf('roomId', idx+3);
const excerpt = mainPageHtml.substr(idx, 50);
let matchExcerpt = excerpt.match(/roomId":"([0-9]+)"/);
if (matchExcerpt && matchExcerpt[1]) return matchExcerpt[1];
} while (idx >= 0);

let matchMeta = mainPageHtml.match(/room_id=([0-9]*)/);
if (matchMeta && matchMeta[1]) return matchMeta[1];

Expand Down

0 comments on commit 1a285c3

Please sign in to comment.