Skip to content

Commit

Permalink
Merge pull request #5 from PramodJoshi/staging
Browse files Browse the repository at this point in the history
first commit
  • Loading branch information
angrave authored Sep 10, 2021
2 parents 6c9e480 + 57867e7 commit 3340865
Show file tree
Hide file tree
Showing 5 changed files with 940 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .gitignore
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/
6 changes: 6 additions & 0 deletions README.md
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)
64 changes: 64 additions & 0 deletions index.js
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...");
});
Loading

0 comments on commit 3340865

Please sign in to comment.