init
This commit is contained in:
11
Dockerfile
Normal file
11
Dockerfile
Normal file
@ -0,0 +1,11 @@
|
||||
FROM ghcr.io/puppeteer/puppeteer:latest
|
||||
|
||||
USER pptruser
|
||||
|
||||
WORKDIR /home/pptruser
|
||||
|
||||
COPY server.js /home/pptruser
|
||||
|
||||
RUN npm install express
|
||||
|
||||
CMD node server.js
|
||||
5
build.sh
Normal file
5
build.sh
Normal file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
docker build -t urmo/pptr:latest .
|
||||
docker tag urmo/pptr:latest rubble.se:5000/urmo/pptr
|
||||
docker push rubble.se:5000/urmo/pptr
|
||||
67
server.js
Normal file
67
server.js
Normal file
@ -0,0 +1,67 @@
|
||||
const express = require('express')
|
||||
const bodyParser = require('body-parser')
|
||||
const app = express()
|
||||
const port = 3000
|
||||
const puppeteer = require('puppeteer');
|
||||
|
||||
app.use(bodyParser.text())
|
||||
//app.use(bodyParser.urlencoded({ extended: false }))
|
||||
|
||||
async function retry(promiseFactory, retryCount) {
|
||||
try {
|
||||
return await promiseFactory();
|
||||
} catch (error) {
|
||||
if (retryCount <= 0) {
|
||||
throw error;
|
||||
}
|
||||
return await retry(promiseFactory, retryCount - 1);
|
||||
}
|
||||
}
|
||||
|
||||
function run (url) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const browser = await puppeteer.launch({headless: 'new'});
|
||||
const page = await browser.newPage();
|
||||
// "https://sxyprn.com/post/6461f5ddbc5c9.html"
|
||||
// await page.goto(url);
|
||||
|
||||
await retry(
|
||||
() => page.goto(url),
|
||||
5 // retry this 5 times
|
||||
);
|
||||
|
||||
let urls = await page.evaluate(() => {
|
||||
//let item = document.querySelector('video#player_el');
|
||||
//return "https://sxyprn.com" + item.getAttribute('src');
|
||||
|
||||
let results = [];
|
||||
let items = document.querySelectorAll('video#player_el');
|
||||
items.forEach((item) => {
|
||||
results.push(document.title);
|
||||
results.push("https://sxyprn.com" + item.getAttribute('src'));
|
||||
});
|
||||
return results;
|
||||
|
||||
})
|
||||
browser.close();
|
||||
return resolve(JSON.stringify(urls));
|
||||
} catch (e) {
|
||||
return reject(e);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// example req. curl -X POST localhost:3000 -H "Content-Type: text/plain" --data 'https://sxyprn.com/post/653e2c6329e1c.html'
|
||||
app.post('/', (req, res) => {
|
||||
console.log(req.body);
|
||||
run(req.body)
|
||||
.then((r) => {
|
||||
res.send(r)
|
||||
});
|
||||
})
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening on port ${port}`)
|
||||
})
|
||||
Reference in New Issue
Block a user