-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from PramodJoshi/staging
first commit
- Loading branch information
Showing
5 changed files
with
940 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.DS_Store | ||
|
||
# Env | ||
config.js | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
build/ | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Connect-Mediaspace | ||
|
||
NodeJS REST API to extract entryId from mediaspace urls. | ||
|
||
Utilizes [Puppeteer](https://github.com/puppeteer/puppeteer) for extraction. | ||
[Puppeteer setup README](https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#tips) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const puppeteer = require('puppeteer'); | ||
const express = require('express'); | ||
const https = require('https'); | ||
|
||
const server = express(); | ||
server.use(express.urlencoded({ | ||
extended: true | ||
})); | ||
|
||
server.use(express.json()); | ||
|
||
let scrape = async (videosrc) => { | ||
var url = ''; | ||
if (videosrc.toLowerCase() === 'uisbotlive') { | ||
url = 'https://uis.mediaspace.kaltura.com/media/t/1_j82of7xw'; | ||
} else { | ||
url = videosrc; | ||
} | ||
|
||
const browser = await puppeteer.launch({headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox']}); // | ||
const page = await browser.newPage(); | ||
|
||
var result = ''; | ||
|
||
try { | ||
await page.goto(url); | ||
await page.waitForTimeout(200); //Wait for 200 millis to load | ||
|
||
console.log('\nScraping...'); | ||
|
||
// Get entry id | ||
const elementHandle = await page.$('.mwEmbedKalturaIframe') | ||
const frame = await elementHandle.contentFrame(); | ||
const entryId = await frame.$eval('#pid_kplayer', el => | ||
el.getAttribute("kentryid")); | ||
|
||
result = entryId; | ||
} catch (err) { | ||
console.error(err.message); | ||
result = ''; | ||
} | ||
|
||
browser.close(); | ||
return result; // Return the data | ||
}; | ||
|
||
// Create an instance of the http server to handle HTTP requests | ||
server.get('/getEntryId', (req, res) => { | ||
// console.log(req.query.videosrc); | ||
// Set a response type of plain text for the response | ||
res.writeHead(200, {'Content-Type': 'application/json'}); | ||
|
||
scrape(req.query.videosrc).then((value) => { | ||
console.log(value); // Success! | ||
res.end(JSON.stringify(value)); | ||
}); | ||
// Send back a response and end the connection | ||
|
||
}); | ||
|
||
// Listen to the specified port | ||
server.listen((process.env.PORT || 8000), () => { | ||
console.log("Server is up and running..."); | ||
}); |
Oops, something went wrong.