182 lines
6.3 KiB
C++
182 lines
6.3 KiB
C++
// This file is part of Motion Watch.
|
|
|
|
// Motion Watch is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Motion Watch is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
#include "web.h"
|
|
|
|
void genHTMLul(const string &outputDir, const string &title, shared_t *share)
|
|
{
|
|
vector<string> logNames;
|
|
vector<string> eveNames;
|
|
vector<string> dirNames;
|
|
|
|
string htmlText = "<!DOCTYPE html>\n";
|
|
|
|
htmlText += "<html>\n";
|
|
htmlText += "<head>\n";
|
|
htmlText += "<meta http-equiv=\"Cache-Control\" content=\"no-cache, no-store, must-revalidate\" />\n";
|
|
htmlText += "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n";
|
|
htmlText += "<meta http-equiv=\"Expires\" content=\"0\" />\n";
|
|
htmlText += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n";
|
|
htmlText += "<link rel='stylesheet' href='/theme.css'>\n";
|
|
htmlText += "</head>\n";
|
|
htmlText += "<body>\n";
|
|
htmlText += "<h3>" + title + "</h3>\n";
|
|
|
|
if (exists(outputDir + "/live"))
|
|
{
|
|
eveNames = lsFilesInDir(outputDir + "/events", ".html");
|
|
logNames = lsFilesInDir(outputDir + "/logs", "_log.html");
|
|
|
|
htmlText += "<h4>Logs</h4>\n";
|
|
htmlText += "<ul>\n";
|
|
|
|
for (auto &&logName : logNames)
|
|
{
|
|
// name.substr(0, name.size() - 9) removes _log.html
|
|
auto name = logName.substr(0, logName.size() - 9);
|
|
|
|
htmlText += " <li><a href='logs/" + logName + "'>" + name + "</a></li>\n";
|
|
}
|
|
|
|
htmlText += "</ul>\n";
|
|
htmlText += "<h4>Live</h4>\n";
|
|
htmlText += "<ul>\n";
|
|
htmlText += " <li><a href='stream.html'>" + share->camName + ":live" + "</a></li>\n";
|
|
htmlText += "</ul>\n";
|
|
htmlText += "<h4>Motion Events</h4>\n";
|
|
|
|
genHTMLstream("stream");
|
|
|
|
for (auto &&eveName : eveNames)
|
|
{
|
|
// regName.substr(0, regName.size() - 5) removes .html
|
|
auto name = eveName.substr(0, eveName.size() - 5);
|
|
|
|
htmlText += "<a href='events/" + eveName + "'><img src='events/" + name + ".jpg" + "' style='width:25%;height:25%;'</a>\n";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dirNames = lsDirsInDir(outputDir);
|
|
|
|
htmlText += "<ul>\n";
|
|
|
|
for (auto &&dirName : dirNames)
|
|
{
|
|
htmlText += " <li><a href='" + dirName + "/index.html'>" + dirName + "</a></li>\n";
|
|
}
|
|
|
|
htmlText += "</ul>\n";
|
|
}
|
|
|
|
htmlText += "</body>\n";
|
|
htmlText += "</html>";
|
|
|
|
ofstream file(string(cleanDir(outputDir) + "/index.html").c_str());
|
|
|
|
file << htmlText << endl;
|
|
|
|
file.close();
|
|
}
|
|
|
|
void genHTMLstream(const string &name)
|
|
{
|
|
string htmlText = "<!DOCTYPE html>\n";
|
|
|
|
htmlText += "<html>\n";
|
|
htmlText += "<head>\n";
|
|
htmlText += "<meta http-equiv=\"Cache-Control\" content=\"no-cache, no-store, must-revalidate\" />\n";
|
|
htmlText += "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n";
|
|
htmlText += "<meta http-equiv=\"Expires\" content=\"0\" />\n";
|
|
htmlText += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n";
|
|
htmlText += "<link rel='stylesheet' href='/theme.css'>\n";
|
|
htmlText += "</head>\n";
|
|
htmlText += "<body>\n";
|
|
htmlText += " <script src=\"https://cdn.jsdelivr.net/npm/hls.js@1\">\n";
|
|
htmlText += " </script>\n";
|
|
htmlText += " <video width=100% height=100% id=\"video\" controls>\n";
|
|
htmlText += " </video>\n";
|
|
htmlText += " <script>\n";
|
|
htmlText += " var video = document.getElementById('video');\n";
|
|
htmlText += " if (Hls.isSupported()) {\n";
|
|
htmlText += " var hls = new Hls({\n";
|
|
htmlText += " debug: true,\n";
|
|
htmlText += " });\n";
|
|
htmlText += " hls.loadSource('" + name + ".m3u8');\n";
|
|
htmlText += " hls.attachMedia(video);\n";
|
|
htmlText += " hls.on(Hls.Events.MEDIA_ATTACHED, function () {\n";
|
|
htmlText += " video.muted = true;\n";
|
|
htmlText += " video.play();\n";
|
|
htmlText += " });\n";
|
|
htmlText += " }\n";
|
|
htmlText += " else if (video.canPlayType('application/vnd.apple.mpegurl')) {\n";
|
|
htmlText += " video.src = '" + name + ".m3u8';\n";
|
|
htmlText += " video.addEventListener('canplay', function () {\n";
|
|
htmlText += " video.play();\n";
|
|
htmlText += " });\n";
|
|
htmlText += " }\n";
|
|
htmlText += " </script>\n";
|
|
htmlText += "</body>\n";
|
|
htmlText += "</html>";
|
|
|
|
ofstream file(string(name + ".html").c_str());
|
|
|
|
file << htmlText << endl;
|
|
|
|
file.close();
|
|
}
|
|
|
|
void genHTMLvod(const string &name)
|
|
{
|
|
string htmlText = "<!DOCTYPE html>\n";
|
|
|
|
htmlText += "<html>\n";
|
|
htmlText += "<head>\n";
|
|
htmlText += "<meta http-equiv=\"Cache-Control\" content=\"no-cache, no-store, must-revalidate\" />\n";
|
|
htmlText += "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n";
|
|
htmlText += "<meta http-equiv=\"Expires\" content=\"0\" />\n";
|
|
htmlText += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n";
|
|
htmlText += "<link rel='stylesheet' href='/theme.css'>\n";
|
|
htmlText += "</head>\n";
|
|
htmlText += "<body>\n";
|
|
htmlText += "<video width=100% height=100% controls autoplay>\n";
|
|
htmlText += " <source src='" + name + ".mp4' type='video/mp4'>\n";
|
|
htmlText += "</video>\n";
|
|
htmlText += "</body>\n";
|
|
htmlText += "</html>";
|
|
|
|
ofstream file(string("events/" + name + ".html").c_str());
|
|
|
|
file << htmlText << endl;
|
|
|
|
file.close();
|
|
}
|
|
|
|
void genCSS(shared_t *share)
|
|
{
|
|
string cssText = "body {\n";
|
|
|
|
cssText += " background-color: " + share->webBg + ";\n";
|
|
cssText += " color: " + share->webTxt + ";\n";
|
|
cssText += " font-family: " + share->webFont + ";\n";
|
|
cssText += "}\n";
|
|
cssText += "a {\n";
|
|
cssText += " color: " + share->webTxt + ";\n";
|
|
cssText += "}\n";
|
|
|
|
ofstream file(string(cleanDir(share->webRoot) + "/theme.css").c_str());
|
|
|
|
file << cssText << endl;
|
|
|
|
file.close();
|
|
}
|