summaryrefslogtreecommitdiff
path: root/api/video.php
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-08-21 17:31:56 +0200
committerMinteck <contact@minteck.org>2022-08-21 17:31:56 +0200
commita2df9a69dcc14cb70118cda2ded499055e7ee358 (patch)
tree6dd283e4e9452d38bce81ddaaae49b5335755842 /api/video.php
parent84dd0735820b16b60f600284d35183d76547a71f (diff)
downloadpluralconnect-a2df9a69dcc14cb70118cda2ded499055e7ee358.tar.gz
pluralconnect-a2df9a69dcc14cb70118cda2ded499055e7ee358.tar.bz2
pluralconnect-a2df9a69dcc14cb70118cda2ded499055e7ee358.zip
m. update
Diffstat (limited to 'api/video.php')
-rw-r--r--api/video.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/api/video.php b/api/video.php
new file mode 100644
index 0000000..7ac32a1
--- /dev/null
+++ b/api/video.php
@@ -0,0 +1,39 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $isLoggedIn;
+if (!$isLoggedIn) header("Location: /login") and die();
+
+if (isset($_GET['id'])) {
+ header("Content-Type: application/json");
+ $data = json_decode(exec("yt-dlp -q -x --no-playlist --skip-download --dump-json \"https://www.youtube.com/watch?v=" . str_replace('"', '\'', $_GET['id']) . "\""), true);
+ $qualities = array_values(array_filter(array_map(function ($i) {
+ return [
+ "quality" => $i["height"],
+ "id" => $i['format_id']
+ ];
+ }, $data["formats"]), function ($i) {
+ return !is_null($i["quality"]);
+ }));
+ $hd = array_values(array_filter($qualities, function ($i) {
+ return $i["quality"] >= 720;
+ }));
+ $selected = count($hd) > 0 ? $hd[0] : $qualities[count($qualities) - 1];
+ $stream = array_values(array_filter($data["formats"], function ($i) use ($selected) {
+ return $i["height"] === $selected["quality"] && $i["acodec"] !== null && $i["acodec"] !== "none";
+ }))[0];
+
+ echo(json_encode([
+ "title" => $data["fulltitle"],
+ "author" => $data["channel"],
+ "count" => [
+ "channel" => $data["channel_follower_count"],
+ "likes" => $data["like_count"],
+ "views" => $data["view_count"]
+ ],
+ "duration" => $data["duration"],
+ "stream" => $selected,
+ "url" => $stream["url"],
+ "duration_pretty" => $stream["duration_string"],
+ "poster" => $data["thumbnail"],
+ ], JSON_PRETTY_PRINT));
+} \ No newline at end of file