JustMotion/src/web.cpp

95 lines
2.7 KiB
C++
Raw Normal View History

// 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)
{
DIR *dir;
struct dirent *ent;
vector<string> regNames;
vector<string> dirNames;
string htmlText = "<!DOCTYPE html>\n";
htmlText += "<html>\n";
htmlText += "<body>\n";
htmlText += "<h2>" + title + "</h2>\n";
htmlText += "<ul>\n";
if ((dir = opendir(outputDir.c_str())) != NULL)
{
while ((ent = readdir(dir)) != NULL)
{
if (ent->d_type & DT_REG)
{
regNames.push_back(string(ent->d_name));
}
else if (ent->d_type & DT_DIR)
{
dirNames.push_back(string(ent->d_name));
}
}
closedir(dir);
}
sort(regNames.begin(), regNames.end());
sort(dirNames.begin(), dirNames.end());
for (auto dirName : dirNames)
{
htmlText += " <li><a href='" + dirName + "'>" + dirName + "</a></li>\n";
}
for (auto regName : regNames)
{
if (regName.ends_with(".html") && !regName.ends_with("index.html"))
{
htmlText += " <li><a href='" + regName + "'> <img src='" + replaceAll(regName, ".html", ".jpg") + "' </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 genHTMLvid(const string &outputVid, shared_t *share)
{
auto filename = path(outputVid).filename().string();
auto filePath = path(outputVid).parent_path().string();
string htmlText = "<!DOCTYPE html>\n";
filename = replaceAll(filename, share->vidExt, "html");
htmlText += "<html>\n";
htmlText += "<body>\n";
htmlText += "<video width='420' height='320' controls autoplay>\n";
htmlText += " <source src='" + filename + "' type='video/" + share->vidExt + "'>\n";
htmlText += "</video>\n";
htmlText += "</body>\n";
htmlText += "</html>";
ofstream file(string(cleanDir(filePath) + "/" + filename + ".html").c_str());
file << htmlText << endl;
file.close();
}