Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Commit

Permalink
cleanup finding source data from html page
Browse files Browse the repository at this point in the history
  • Loading branch information
CT1994 committed Jul 5, 2020
1 parent 8a627be commit 03835e8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/src/background.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
async function getDownloadLink({lessonID, lessonName}, echo360Domain, downloadHD) {
const regex = /(?:\(\")(?:.*)(?:\"\))/;
const classroomAppRegex = new RegExp('(classroomApp)');
const dataRegex = /(?:\(\")(?:.*)(?:\"\))/;
const lessonHTMLPageRequest = new Request(`${echo360Domain}/lesson/${lessonID}/classroom`, { method: 'GET', credentials: 'include' });
const lessonHTMLPageResponse = await fetch(lessonHTMLPageRequest)
const lessonHTMLPageText = await lessonHTMLPageResponse.text();
const dummyEl = document.createElement('html')
dummyEl.innerHTML = lessonHTMLPageText;
const videoDataScript = Array.from(dummyEl.getElementsByTagName('script')).filter((script) => classroomAppRegex.test(script.innerText));

const videoDataString = dummyEl.getElementsByTagName('script')[11].innerText.match(regex)[0]
if (videoDataScript.length === 0)
{
return null;
}

const videoDataString = videoDataScript[0].innerText.match(dataRegex)[0];

const cleanString = videoDataString.substring(1, videoDataString.length - 1);
const videoDataObject = JSON.parse(JSON.parse(cleanString));

Expand Down

0 comments on commit 03835e8

Please sign in to comment.