main
commit
6d282d8e2a
@ -0,0 +1,2 @@
|
||||
videolist
|
||||
node_modules/
|
@ -0,0 +1,91 @@
|
||||
import ytsr from 'ytsr'
|
||||
import fs from 'fs'
|
||||
import express from 'express'
|
||||
const app = express()
|
||||
const playerHtml = fs.readFileSync('site.html', 'utf-8')
|
||||
const port = process.env.PORT??3500
|
||||
|
||||
let list = fs.readFileSync('videolist', 'utf-8').split('\n')
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.send(playerHtml.replace('{{VIDEO_ID_HERE}}', list[Math.floor(Math.random()*list.length)]))
|
||||
})
|
||||
|
||||
app.listen(port, () => {console.log(`Listening at http://localhost:${port}`)})
|
||||
|
||||
function random(chars, length = 8) {
|
||||
chars = chars??'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
let str = '';
|
||||
for (let i = 0; i < length; i++) {
|
||||
str += chars.charAt(Math.floor(Math.random() * chars.length));
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
function titleGen(category) {
|
||||
category = category??Math.round(Math.random()*20)
|
||||
let title
|
||||
switch (category) {
|
||||
case 0:
|
||||
// Random GoPro filename generator
|
||||
title = `G${random('HX', 1)}01${random('0123456789', 4)}`
|
||||
break;
|
||||
case 1:
|
||||
// Random DSC filename generator
|
||||
title = `DSC ${random('0123456789', 4)}`
|
||||
break;
|
||||
case 2:
|
||||
// Random IMG filename generator
|
||||
title = `IMG ${random('0123456789', 4)}`
|
||||
break;
|
||||
case 3:
|
||||
// Random keymash generator
|
||||
title = random('abcdefghijklmnopqrstuvwxyz', 2+Math.round(Math.random()*6))
|
||||
break;
|
||||
default:
|
||||
// Random screen recording filename generator
|
||||
let year = 2017+Math.floor(Math.random()*4)
|
||||
let month = Math.round(Math.random()*12).toString().padStart(2, '0')
|
||||
let day = Math.round(Math.random()*25).toString().padStart(2, '0')
|
||||
title = `screen-${year}${month}${day}`
|
||||
}
|
||||
return title
|
||||
}
|
||||
|
||||
function shuffleArray(array) {
|
||||
let curId = array.length;
|
||||
while (0 !== curId) {
|
||||
let randId = Math.floor(Math.random() * curId);
|
||||
curId -= 1;
|
||||
let tmp = array[curId];
|
||||
array[curId] = array[randId];
|
||||
array[randId] = tmp;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
async function writeList(count) {
|
||||
let found = []
|
||||
for (let i = 0; i < count; i++) {
|
||||
let title = titleGen(10)
|
||||
let items = (await ytsr(title, { pages: 1 })).items
|
||||
let fewViews = items.filter(e => {
|
||||
return e.type=='video'&&e.views<10
|
||||
}).map(e => {
|
||||
return e.id
|
||||
})
|
||||
found.push(...fewViews)
|
||||
}
|
||||
found = shuffleArray(found)
|
||||
list.push(...found)
|
||||
let urls = found.join('\n')
|
||||
if (!fs.existsSync('videolist')) fs.writeFileSync('videolist', urls)
|
||||
else {
|
||||
let currentList = fs.readFileSync('videolist', 'utf-8')
|
||||
fs.writeFileSync('videolist', currentList+'\n'+urls)
|
||||
}
|
||||
console.log('Wrote list to file.')
|
||||
}
|
||||
|
||||
setInterval(() => {writeList(100)}, 10*60*1000)
|
||||
writeList(200)
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "surf",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"express": "^4.18.1",
|
||||
"ytsr": "^3.8.0"
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<style>
|
||||
body {
|
||||
background: black;
|
||||
}
|
||||
iframe {
|
||||
margin: 0 auto;
|
||||
display: block;
|
||||
box-shadow: 0 4px 10px rgba(255, 255, 255, 0.5);
|
||||
max-width: 100%;
|
||||
}
|
||||
a {
|
||||
display: block;
|
||||
width: fit-content;
|
||||
margin: 2rem auto;
|
||||
font-size: 2rem;
|
||||
color: white;
|
||||
text-transform: lowercase;
|
||||
text-decoration: none;
|
||||
font-style: italic;
|
||||
text-align: center;
|
||||
text-shadow: 0 0 8px white;
|
||||
}
|
||||
</style>
|
||||
<title>random.</title>
|
||||
</head>
|
||||
<body>
|
||||
<a href="/">Get a new video</a>
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/{{VIDEO_ID_HERE}}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in new issue