Skip to content

Commit

Permalink
Merge pull request #18 from bebora/new-player
Browse files Browse the repository at this point in the history
Fix #17
  • Loading branch information
jacopo-j authored May 5, 2022
2 parents 3259c9e + d932f09 commit 0072c8c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Download the `.xpi` file from the [latest release](https://github.com/jacopo-j/W
* Browse to `chrome://extensions`
* Turn on "Developer mode" on the top right
* Click "Load unpacked extension..." on the top left
* Select the folder to which your zip file was extracted.
* Select the folder named `src` from the folder to which your zip file was extracted.

### Safari (experimental)

Expand Down
28 changes: 3 additions & 25 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,6 @@ function parseParametersFromResponse(response) {
}
}

function composeStreamURL(params) {
const url = new URL("apis/html5-pipeline.do", params.host);
url.searchParams.set("recordingDir", params.recordingDir);
url.searchParams.set("timestamp", params.timestamp);
url.searchParams.set("token", params.token);
url.searchParams.set("xmlName", params.xmlName);
url.searchParams.set("isMobileOrTablet", "false");
url.searchParams.set("ext", params.playbackOption);

return url;
}

function sanitizeFilename(filename) {
const allowedChars = /[^\w\s\d\-_~,;\[\]\(\).]/g;
return filename.replaceAll(allowedChars, "_");
Expand Down Expand Up @@ -113,31 +101,21 @@ function mutationCallback(_mutationArray, observer) {
// Get the useful parameters from the received response
const params = parseParametersFromResponse(response);

// Compose the URL from which to get the video stream to download
const streamURL = composeStreamURL(params);

// Add the download button
chrome.runtime.sendMessage({
fetchText: streamURL.toString()
},
(text) => addDownloadButtonToPage(text, params));
addDownloadButtonToPage(params);
}
)
}

/**
* Add the download button to the video viewer bar.
* @param {string} text
* @param {Object} params
*/
function addDownloadButtonToPage(text, params) {
function addDownloadButtonToPage(params) {
// Do not add the button if already present
const downloadButtons = document.getElementsByClassName("icon-download")
if (downloadButtons.length) return;

// Extract the filename of the video
const parser = new window.DOMParser();
const data = parser.parseFromString(text, "text/xml");
const filename = data.getElementsByTagName("Sequence")[0].textContent;

// Set the recording name as the save name
const savename = `${sanitizeFilename(params.recordName)}.mp4`;
Expand Down
64 changes: 51 additions & 13 deletions src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,59 @@ function parseParametersFromResponse(response) {
const token = streamOption["token"];
const xmlName = streamOption["xmlName"];
const playbackOption = streamOption["playbackOption"];
const siteid = streamOption["siteid"];
const recordid = streamOption["recordid"];
const islogin = streamOption["islogin"];
const isprevent = streamOption["isprevent"];
const ispwd = streamOption["ispwd"];

const hlsUrl = response["downloadRecordingInfo"]["downloadInfo"]["hlsURL"];

return {
host,
recordingDir,
timestamp,
token,
xmlName,
playbackOption
playbackOption,
siteid,
recordid,
islogin,
isprevent,
ispwd,
hlsUrl
}
}

function composeStreamURL(params) {
const url = new URL("apis/html5-pipeline.do", params.host);
url.searchParams.set("recordingDir", params.recordingDir);
url.searchParams.set("timestamp", params.timestamp);
url.searchParams.set("token", params.token);
url.searchParams.set("xmlName", params.xmlName);
url.searchParams.set("isMobileOrTablet", "false");
url.searchParams.set("ext", params.playbackOption);

return url;
// Recordings before May 2022
if (params["recordingDir"] !== undefined) {
const url = new URL("apis/html5-pipeline.do", params.host);
url.searchParams.set("recordingDir", params.recordingDir);
url.searchParams.set("timestamp", params.timestamp);
url.searchParams.set("token", params.token);
url.searchParams.set("xmlName", params.xmlName);
url.searchParams.set("isMobileOrTablet", "false");
url.searchParams.set("ext", params.playbackOption);

return url;
}
// Recordings from May 2022
else if (params["siteid"] !== undefined) {
const url = new URL("nbr/MultiThreadDownloadServlet/recording.xml", params.host);
url.searchParams.set("siteid", params.siteid);
url.searchParams.set("recordid", params.recordid);
url.searchParams.set("ticket", params.token);
url.searchParams.set("timestamp", params.timestamp);
url.searchParams.set("islogin", params.islogin);
url.searchParams.set("isprevent", params.isprevent);
url.searchParams.set("ispwd", params.ispwd);
url.searchParams.set("play", "1");

return url;
}

return null;
}

function checkResponseForErrors(response) {
Expand Down Expand Up @@ -182,6 +214,8 @@ function callback(tabs) {
// Compose the URL from which to get the video stream to download
const streamURL = composeStreamURL(params);

if (streamURL === null) renderException({message: "Stream URL is null"});

fetch(streamURL.toString())
.then(response => response.text())
.then(text => (new window.DOMParser()).parseFromString(text, "text/xml"))
Expand All @@ -204,10 +238,14 @@ function callback(tabs) {
};
});

// Compse the captions URL
const filename = data.getElementsByTagName("Sequence")[0].textContent;
// Compose the hls URL if necessary
let hlsUrl = params.hlsUrl;
if (hlsUrl === undefined) {
const filename = data.getElementsByTagName("Sequence")[0].textContent;
hlsUrl = `${params.host}/hls-vod/recordingDir/${params.recordingDir}/timestamp/${params.timestamp}/token/${params.token}/fileName/${filename}.m3u8`;
}

const meetingName = response["recordName"];
const hlsUrl = `${params.host}/hls-vod/recordingDir/${params.recordingDir}/timestamp/${params.timestamp}/token/${params.token}/fileName/${filename}.m3u8`;
renderSuccess(meetingName, hlsUrl, chat);
})
.catch(ex => renderException(ex));
Expand Down

0 comments on commit 0072c8c

Please sign in to comment.