update style, add title extractor

Signed-off-by: Christian Richter <crichter@owncloud.com>
This commit is contained in:
Christian Richter
2022-07-15 16:40:30 +02:00
parent c361bc2a52
commit 1a2260ffb8
2 changed files with 60 additions and 11 deletions

View File

@@ -2,8 +2,49 @@
<head> <head>
<script type='text/javascript' src='http://www.youtube.com/player_api'></script> <script type='text/javascript' src='http://www.youtube.com/player_api'></script>
<title>Weirdradio</title></head> <title>Weirdradio</title></head>
<style>
div.body {
width: 1024px;
height: 768px;
border: solid 1px;
padding: 1pc;
}
div.leftcolumn {
width: 30%;
float: left;
}
div.title {
height: 20%;
}
div.playlist {
height: 80%;
}
div.rightcolumn {
width: 60%;
float: left;
}
#playerframe {
height: 100%;
width: 100%;
background-color: purple;
}
</style>
<body onload="connectSocket()"> <body onload="connectSocket()">
<div id="player"></div> <div class="body">
<div class="leftcolumn">
<div class="title">
<h1>Weirdradio</h1>
</div>
<div class="playlist">
{playlist}
</div>
</div>
<div class="rightcolumn">
<div class="playerframe">
<div id="player"></div>
</div>
</div>
</div>
</body> </body>
<script> <script>
// 2. This code loads the IFrame Player API code asynchronously. // 2. This code loads the IFrame Player API code asynchronously.

View File

@@ -82,16 +82,24 @@ client.on("room.message", (roomId, event) => {
var r = new RegExp(/https?:\/\/[^\ ]*youtube.com\/watch\?v=([^\ ]*)/g); var r = new RegExp(/https?:\/\/[^\ ]*youtube.com\/watch\?v=([^\ ]*)/g);
link_matches = r.exec(body); link_matches = r.exec(body);
if (link_matches && link_matches.length > 1) { if (link_matches && link_matches.length > 1) {
// pass to server // get title
var obj = { request(link_matches[0], function (err, _res, body) {
link: link_matches[0], if (err) return console.error(err);
embedLink: title = "unset";
"https://www.youtube.com/embed/" + link_matches[1] + "?autoplay=1", let $ = cheerio.load(body);
videoId: link_matches[1], tmpTitle = $("title").text();
if (tmpTitle != "") {
}; title = tmpTitle.replace(" - YouTube", "");
console.log("Relaying: " + obj.link); }
sockets.forEach((s) => s.send(JSON.stringify(obj))); // pass to server
var obj = {
link: link_matches[0],
videoId: link_matches[1],
title: title,
};
console.log("Relaying: " + obj.link);
sockets.forEach((s) => s.send(JSON.stringify(obj)));
});
} }
} }
}); });