-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebEx Video and Transcript Downloader.user.js
More file actions
469 lines (398 loc) · 17.2 KB
/
WebEx Video and Transcript Downloader.user.js
File metadata and controls
469 lines (398 loc) · 17.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
// ==UserScript==
// @name WebEx Video and Transcript Downloader
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Download videos and transcripts from WebEx recordings
// @author navaneethsen@gmail.com using claudeai
// @match *://*.webex.com/webappng/site/*
// @match *://*.webex.com/recordingservice/sites/*
// @grant GM_xmlhttpRequest
// @grant GM_download
// @connect *.webex.com
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
// URL pattern matching for WebEx recordings
const REGEX = /^https?:\/\/(.+?)\.webex\.com\/(?:recordingservice|webappng)\/sites\/([^\/]+)\/.*?([a-f0-9]{32})[^\?]*(\?.*)?/;
// Global variables to store recording information
let recordingParams = null;
let downloadPassword = null;
let apiResponse = null;
// Main initialization function
function init() {
// Check if we're on a WebEx recording page
const match = REGEX.exec(window.location.href);
if (!match) {
console.log("Not a WebEx recording page, script not running");
return;
}
// Extract parameters from the URL
const subdomain = match[1];
const sitename = match[2];
const recordingId = match[3];
const authParams = match[4] || '';
recordingParams = { subdomain, sitename, recordingId, authParams };
// Start observing DOM changes to detect when the player loads
observePlayerLoading();
// Try to intercept network requests to get password
interceptPasswordRequests();
// Log successful initialization
console.log("WebEx Downloader initialized for recording:", recordingId);
}
// Create a MutationObserver to detect when the player is loaded
function observePlayerLoading() {
const observer = new MutationObserver((mutations) => {
// Check if player elements are loaded
const playerExists = document.querySelector('.wxp-player') ||
document.querySelector('video') ||
document.querySelector('.ngplayer') ||
document.querySelector('.recordingTitle');
if (playerExists) {
console.log("WebEx player detected, fetching recording info");
fetchRecordingInfo();
observer.disconnect();
}
});
// Start observing the DOM
observer.observe(document.body, { childList: true, subtree: true });
}
// Try to intercept network requests to extract password
function interceptPasswordRequests() {
// Create a wrapper for the native fetch function
const originalFetch = window.fetch;
window.fetch = function(url, options) {
// Check if this is a request to the recordings API
if (url.toString().includes('/api/v1/recordings/')) {
// Try to extract password from headers
if (options && options.headers) {
if (options.headers.accessPwd) {
downloadPassword = options.headers.accessPwd;
console.log("Password intercepted from fetch request");
}
}
}
// Call the original fetch function
return originalFetch.apply(this, arguments);
};
// Also intercept XMLHttpRequest for older WebEx sites
const originalXhrOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url) {
if (url.toString().includes('/api/v1/recordings/')) {
// Listen for setRequestHeader calls to capture the password
const originalSetHeader = this.setRequestHeader;
this.setRequestHeader = function(header, value) {
if (header === 'accessPwd') {
downloadPassword = value;
console.log("Password intercepted from XHR request");
}
return originalSetHeader.apply(this, arguments);
};
}
return originalXhrOpen.apply(this, arguments);
};
}
// Fetch recording information from the WebEx API
function fetchRecordingInfo() {
if (!recordingParams) return;
// Construct the API URL
const apiUrl = `https://${recordingParams.subdomain}.webex.com/webappng/api/v1/recordings/${recordingParams.recordingId}/stream${recordingParams.authParams}`;
// Set up headers for the request
const headers = {
"Accept": "application/json, text/plain, */*"
};
// Add password if we have it
if (downloadPassword) {
headers.accessPwd = downloadPassword;
} else {
headers.appFrom = "pb";
}
// Make the API request
GM_xmlhttpRequest({
method: "GET",
url: apiUrl,
headers: headers,
onload: function(response) {
try {
// Parse the JSON response
apiResponse = JSON.parse(response.responseText);
// Process the response and add buttons
processApiResponse(apiResponse);
} catch (error) {
console.error("Error processing WebEx API response:", error);
}
},
onerror: function(error) {
console.error("Error fetching WebEx recording info:", error);
}
});
}
// Process the API response and add download buttons
function processApiResponse(response) {
if (!response) {
console.error("Empty API response");
return;
}
try {
// Parse necessary parameters from the response
const params = parseParametersFromResponse(response);
// Add download buttons to the page
addDownloadButtons(params);
} catch (error) {
console.error("Error parsing WebEx API response:", error);
}
}
// Parse parameters from the API response
function parseParametersFromResponse(response) {
const params = {};
// Get the record name for the filename
params.recordName = response.recordName || "webex_recording";
// Handle direct download URL if available
if (response.fallbackPlaySrc) {
params.downloadUrl = response.fallbackPlaySrc;
}
// Handle stream options for older recordings
if (response.mp4StreamOption) {
const streamOption = response.mp4StreamOption;
// Copy all properties that might be needed
params.host = streamOption.host;
params.recordingDir = streamOption.recordingDir;
params.timestamp = streamOption.timestamp;
params.token = streamOption.token;
params.xmlName = streamOption.xmlName;
params.playbackOption = streamOption.playbackOption;
// New format parameters (May 2022+)
params.siteid = streamOption.siteid;
params.recordid = streamOption.recordid;
params.islogin = streamOption.islogin;
params.isprevent = streamOption.isprevent;
params.ispwd = streamOption.ispwd;
}
// If we don't have a direct download URL, construct one
if (!params.downloadUrl) {
params.downloadUrl = constructDownloadUrl(params);
}
return params;
}
// Construct download URL from parameters
function constructDownloadUrl(params) {
// 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.toString();
}
// 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.toString();
}
return null;
}
// Add download buttons to the WebEx player interface
function addDownloadButtons(params) {
// Check if buttons already exist
if (document.getElementById('webex-download-container')) {
return;
}
// Create container for buttons
const buttonContainer = document.createElement('div');
buttonContainer.id = 'webex-download-container';
buttonContainer.style.position = 'absolute';
buttonContainer.style.top = '10px';
buttonContainer.style.right = '10px';
buttonContainer.style.zIndex = '9999';
buttonContainer.style.display = 'flex';
buttonContainer.style.flexDirection = 'column';
buttonContainer.style.gap = '8px';
// Create video download button
if (params.downloadUrl) {
const videoButton = createButton('Download Video', 'webex-video-download-btn');
videoButton.addEventListener('click', () => downloadVideo(params));
buttonContainer.appendChild(videoButton);
}
// Create transcript download button if transcript exists
if (document.querySelector('.wxp-transcript-list') ||
document.querySelector('.wxp-panel-list') ||
document.querySelector('[aria-labelledby="wxp-transcript-tab"]')) {
const transcriptButton = createButton('Download Transcript', 'webex-transcript-download-btn');
transcriptButton.addEventListener('click', downloadTranscript);
buttonContainer.appendChild(transcriptButton);
}
// Find appropriate container for the buttons
let container = document.querySelector('.wxp-player-container') ||
document.querySelector('.ngPlayerContainer') ||
document.querySelector('#wrapper') ||
document.querySelector('.recordingHeader') ||
document.querySelector('.video-container');
if (container) {
container.style.position = 'relative';
container.appendChild(buttonContainer);
} else {
// Fallback to body
buttonContainer.style.position = 'fixed';
buttonContainer.style.top = '80px';
buttonContainer.style.right = '20px';
document.body.appendChild(buttonContainer);
}
console.log("WebEx download buttons added successfully");
}
// Helper function to create a styled button
function createButton(text, id) {
const button = document.createElement('button');
button.textContent = text;
button.id = id;
button.style.padding = '8px 16px';
button.style.backgroundColor = '#00ab6c'; // WebEx green
button.style.color = 'white';
button.style.border = 'none';
button.style.borderRadius = '4px';
button.style.cursor = 'pointer';
button.style.fontFamily = 'CiscoSansTT, Arial, sans-serif';
button.style.fontSize = '14px';
button.style.fontWeight = 'bold';
button.style.boxShadow = '0 2px 5px rgba(0,0,0,0.2)';
button.style.width = '100%';
// Add hover effect
button.onmouseover = function() {
this.style.backgroundColor = '#008f5b';
};
button.onmouseout = function() {
this.style.backgroundColor = '#00ab6c';
};
return button;
}
// Function to download the video
function downloadVideo(params) {
// Sanitize the filename
const filename = sanitizeFilename(params.recordName) + '.mp4';
// Attempt to download using GM_download
if (typeof GM_download !== 'undefined') {
try {
GM_download({
url: params.downloadUrl,
name: filename,
onload: () => console.log('Video download started'),
onerror: (e) => {
console.error('GM_download failed:', e);
fallbackDownload(params.downloadUrl, filename);
}
});
return;
} catch (e) {
console.error('Error using GM_download:', e);
}
}
// Use fallback method if GM_download fails or isn't available
fallbackDownload(params.downloadUrl, filename);
}
// Fallback download method
function fallbackDownload(url, filename) {
try {
// Create and trigger a download link
const downloadLink = document.createElement('a');
downloadLink.href = url;
downloadLink.download = filename;
downloadLink.style.display = 'none';
document.body.appendChild(downloadLink);
downloadLink.click();
// Clean up
setTimeout(() => {
document.body.removeChild(downloadLink);
}, 100);
} catch (e) {
console.error('Error creating download link:', e);
// Open in new tab as last resort
alert('Direct download failed. Opening in new tab. Right-click and select "Save as" to download.');
window.open(url, '_blank');
}
}
// Function to download the transcript
function downloadTranscript() {
// Get all transcript cue elements
const cueElements = document.querySelectorAll('.wxp-transcript-item');
if (!cueElements || cueElements.length === 0) {
alert('No transcript found on this page.');
return;
}
let transcriptText = '';
let currentSpeaker = '';
// Extract text from each cue element
cueElements.forEach((cue) => {
try {
// Extract the text content
let cueText = cue.textContent.trim();
// Check if there's speaker info
const speakerMatch = cueText.match(/^(.*?):\s*(.*)/);
let speaker = '';
let text = cueText;
if (speakerMatch && speakerMatch.length > 2) {
speaker = speakerMatch[1].trim();
text = speakerMatch[2].trim();
// Only add speaker name when it changes
if (speaker !== currentSpeaker) {
transcriptText += `\n${speaker}:\n`;
currentSpeaker = speaker;
}
transcriptText += `${text}\n`;
} else {
// No speaker info, just add the text
transcriptText += `${cueText}\n`;
}
} catch (e) {
// Fallback if any error occurs in parsing
transcriptText += `${cue.textContent.trim()}\n`;
}
});
// Clean up any double newlines
transcriptText = transcriptText.replace(/\n\n+/g, '\n\n');
// Get recording name if available
let fileName = 'webex_transcript.txt';
if (apiResponse && apiResponse.recordName) {
fileName = `${sanitizeFilename(apiResponse.recordName)}_transcript.txt`;
} else {
// Try to get name from page title
const titleElement = document.querySelector('.meeting-title') ||
document.querySelector('.recording-title') ||
document.querySelector('title');
if (titleElement && titleElement.textContent) {
fileName = `${sanitizeFilename(titleElement.textContent)}_transcript.txt`;
}
}
// Create blob for download
const blob = new Blob([transcriptText], {type: 'text/plain'});
const url = URL.createObjectURL(blob);
// Create download link
const downloadLink = document.createElement('a');
downloadLink.href = url;
downloadLink.download = fileName;
// Trigger download
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
// Clean up
setTimeout(() => {
URL.revokeObjectURL(url);
}, 100);
}
// Helper function to sanitize filenames
function sanitizeFilename(filename) {
if (!filename) return "webex_recording";
return filename.replace(/[^\w\s\d\-_~,;\[\]\(\).]/g, "_");
}
// Initialize the script
setTimeout(init, 1000);
})();