From cf93a425ba5613fb5e7824fb016a6b2e0a80ba9e Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 11 Apr 2017 23:56:16 +0200 Subject: [PATCH] [DEV] add a simple line command to acces on video service --- lutinParseSubFolders.txt | 1 + tools/cli-video/appl/debug.cpp | 12 + tools/cli-video/appl/debug.hpp | 40 ++ .../cli-video/appl/main-tool-client-video.cpp | 422 ++++++++++++++++++ tools/cli-video/lutin_zeus-cli-video.py | 40 ++ 5 files changed, 515 insertions(+) create mode 100644 tools/cli-video/appl/debug.cpp create mode 100644 tools/cli-video/appl/debug.hpp create mode 100644 tools/cli-video/appl/main-tool-client-video.cpp create mode 100644 tools/cli-video/lutin_zeus-cli-video.py diff --git a/lutinParseSubFolders.txt b/lutinParseSubFolders.txt index aba48bd..2b4223e 100644 --- a/lutinParseSubFolders.txt +++ b/lutinParseSubFolders.txt @@ -1,4 +1,5 @@ tools/gateway +tools/cli-video tools/router tools/service-user tools/service-picture diff --git a/tools/cli-video/appl/debug.cpp b/tools/cli-video/appl/debug.cpp new file mode 100644 index 0000000..061b84e --- /dev/null +++ b/tools/cli-video/appl/debug.cpp @@ -0,0 +1,12 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ + +#include + +int32_t appl::getLogId() { + static int32_t g_val = elog::registerInstance("zeus-client-video"); + return g_val; +} diff --git a/tools/cli-video/appl/debug.hpp b/tools/cli-video/appl/debug.hpp new file mode 100644 index 0000000..70b9c0b --- /dev/null +++ b/tools/cli-video/appl/debug.hpp @@ -0,0 +1,40 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#pragma once + +#include + +namespace appl { + int32_t getLogId(); +}; + +#define APPL_BASE(info,data) ELOG_BASE(appl::getLogId(),info,data) + +#define APPL_PRINT(data) APPL_BASE(-1, data) +#define APPL_CRITICAL(data) APPL_BASE(1, data) +#define APPL_ERROR(data) APPL_BASE(2, data) +#define APPL_WARNING(data) APPL_BASE(3, data) +#ifdef DEBUG + #define APPL_INFO(data) APPL_BASE(4, data) + #define APPL_DEBUG(data) APPL_BASE(5, data) + #define APPL_VERBOSE(data) APPL_BASE(6, data) + #define APPL_TODO(data) APPL_BASE(4, "TODO : " << data) +#else + #define APPL_INFO(data) do { } while(false) + #define APPL_DEBUG(data) do { } while(false) + #define APPL_VERBOSE(data) do { } while(false) + #define APPL_TODO(data) do { } while(false) +#endif + +#define APPL_ASSERT(cond,data) \ + do { \ + if (!(cond)) { \ + APPL_CRITICAL(data); \ + assert(!#cond); \ + } \ + } while (0) + + diff --git a/tools/cli-video/appl/main-tool-client-video.cpp b/tools/cli-video/appl/main-tool-client-video.cpp new file mode 100644 index 0000000..221cb85 --- /dev/null +++ b/tools/cli-video/appl/main-tool-client-video.cpp @@ -0,0 +1,422 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2014, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +static std::string extractAndRemove(const std::string& _inputValue, const char _startMark, const char _stopMark, std::vector& _values) { + _values.clear(); + std::string out; + bool inside=false; + std::string insideData; + for (auto &it : _inputValue) { + if ( inside == false + && it == _startMark) { + inside = true; + } else if ( inside == true + && it == _stopMark) { + inside = false; + _values.push_back(insideData); + insideData.clear(); + } else if (inside == true) { + insideData += it; + } else { + out += it; + } + } + return out; +} + +bool pushVideoFile(zeus::service::ProxyVideo& _srv, std::string _path, std::map _basicKey = std::map()) { + APPL_INFO("Add media : '" << _path << "'"); + std::string extention = etk::tolower(std::string(_path.begin()+_path.size() -3, _path.end())); + if ( extention != "avi" + && extention != "mkv" + && extention != "mov" + && extention != "mp4") { + APPL_ERROR("Sot send file : " << _path << " Not manage extention..."); + return false; + } + + uint32_t mediaId = _srv.mediaAdd(zeus::File::create(_path)).waitFor(echrono::seconds(20000)).get(); + if (mediaId == 0) { + APPL_ERROR("Get media ID = 0 With no error"); + return false; + } + + // Parse file name: + std::string fileName = etk::split(_path, '/').back(); + APPL_INFO("Find fileName : '" << fileName << "'"); + // Remove Date (XXXX) + std::vector dates; + fileName = extractAndRemove(fileName, '(', ')', dates); + if (dates.size() > 1) { + APPL_INFO(" '" << fileName << "'"); + APPL_ERROR("Parse Date error : () : " << dates); + } else if (dates.size() == 1) { + APPL_INFO(" '" << fileName << "'"); + _basicKey.insert(std::pair("date", dates[0])); + } + // Remove the actors [XXX YYY][EEE TTT]... + std::vector acthors; + fileName = extractAndRemove(fileName, '[', ']', acthors); + if (acthors.size() > 0) { + APPL_INFO(" '" << fileName << "'"); + std::string actorList; + for (auto &itActor : acthors) { + if (actorList != "") { + actorList += ";"; + } + actorList += itActor; + } + _basicKey.insert(std::pair("acthors", actorList)); + } + + // remove extention + fileName = std::string(fileName.begin(), fileName.begin() + fileName.size() - 4); + + std::vector listElementBase = etk::split(fileName, '-'); + + std::vector listElement; + std::string tmpStartString; + for (size_t iii=0; iii("title", etk::to_string(listElement[0]))); + } else { + /* + for (auto &itt : listElement) { + APPL_INFO(" " << itt); + } + */ + if ( listElement.size() > 3 + && listElement[1][0] == 's' + && listElement[2][0] == 'e') { + // internal formalisme ... + int32_t saison = -1; + int32_t episode = -1; + std::string seriesName = listElement[0]; + + _basicKey.insert(std::pair("series-name", etk::to_string(seriesName))); + _basicKey.insert(std::pair("title", etk::to_string(listElement[3]))); + if (std::string(&listElement[1][1]) == "XX") { + // saison unknow ... ==> nothing to do ... + } else { + saison = etk::string_to_int32_t(&listElement[1][1]); + } + if (std::string(&listElement[2][1]) == "XX") { + // episode unknow ... ==> nothing to do ... + } else { + episode = etk::string_to_int32_t(&listElement[2][1]); + + _basicKey.insert(std::pair("episode", etk::to_string(episode))); + } + APPL_INFO("Find a internal mode series: :"); + APPL_INFO(" origin : '" << fileName << "'"); + std::string saisonPrint = "XX"; + std::string episodePrint = "XX"; + if (saison < 0) { + // nothing to do + } else if(saison < 10) { + saisonPrint = "0" + etk::to_string(saison); + _basicKey.insert(std::pair("saison", etk::to_string(saison))); + } else { + saisonPrint = etk::to_string(saison); + _basicKey.insert(std::pair("saison", etk::to_string(saison))); + } + if (episode < 0) { + // nothing to do + } else if(episode < 10) { + episodePrint = "0" + etk::to_string(episode); + _basicKey.insert(std::pair("episode", etk::to_string(episode))); + } else { + episodePrint = etk::to_string(episode); + _basicKey.insert(std::pair("episode", etk::to_string(episode))); + } + APPL_INFO(" recontituated: '" << seriesName << "-s" << saisonPrint << "-e" << episodePrint << "-" << listElement[3] << "'"); + } + } + // send all meta data: + zeus::FutureGroup group; + for (auto &itKey : _basicKey) { + group.add(_srv.mediaMetadataSetKey(mediaId, itKey.first, itKey.second)); + } + group.wait(); + return true; +} + +void installVideoPath(zeus::service::ProxyVideo& _srv, std::string _path, std::map _basicKey = std::map()) { + etk::FSNode node(_path); + APPL_INFO("Parse : '" << _path << "'"); + std::vector listSubPath = node.folderGetSub(true, false, "*"); + for (auto &itPath : listSubPath) { + std::map basicKeyTmp = _basicKey; + APPL_INFO("Add Sub path: '" << itPath << "'"); + std::string lastPathName = etk::split(itPath, '/').back(); + if (basicKeyTmp.size() == 0) { + APPL_INFO("find '" << lastPathName << "' " << basicKeyTmp.size()); + if (lastPathName == "films") { + basicKeyTmp.insert(std::pair("type", "film")); + basicKeyTmp.insert(std::pair("production-methode", "picture")); + } else if (lastPathName == "films-annimation") { + basicKeyTmp.insert(std::pair("type", "film")); + basicKeyTmp.insert(std::pair("production-methode", "draw")); + } else if (lastPathName == "tv-show") { + basicKeyTmp.insert(std::pair("type", "tv-show")); + basicKeyTmp.insert(std::pair("production-methode", "picture")); + } else if (lastPathName == "anim") { + basicKeyTmp.insert(std::pair("type", "tv-show")); + basicKeyTmp.insert(std::pair("production-methode", "draw")); + } else if (lastPathName == "courses") { // short films + basicKeyTmp.insert(std::pair("type", "courses")); + basicKeyTmp.insert(std::pair("production-methode", "picture")); // TODO : Check "draw" + } else if (lastPathName == "theater") { + basicKeyTmp.insert(std::pair("type", "theater")); + basicKeyTmp.insert(std::pair("production-methode", "picture")); + } else if (lastPathName == "one-man-show") { + basicKeyTmp.insert(std::pair("type", "one-man show")); + basicKeyTmp.insert(std::pair("production-methode", "picture")); + } + } else { + APPL_INFO("find '" << lastPathName << "' " << basicKeyTmp.size()); + if (lastPathName == "saison_01") { + basicKeyTmp.insert(std::pair("saison", "1")); + } else if (lastPathName == "saison_02") { + basicKeyTmp.insert(std::pair("saison", "2")); + } else if (lastPathName == "saison_03") { + basicKeyTmp.insert(std::pair("saison", "3")); + } else if (lastPathName == "saison_04") { + basicKeyTmp.insert(std::pair("saison", "4")); + } else if (lastPathName == "saison_05") { + basicKeyTmp.insert(std::pair("saison", "5")); + } else if (lastPathName == "saison_06") { + basicKeyTmp.insert(std::pair("saison", "6")); + } else if (lastPathName == "saison_07") { + basicKeyTmp.insert(std::pair("saison", "7")); + } else if (lastPathName == "saison_08") { + basicKeyTmp.insert(std::pair("saison", "8")); + } else if (lastPathName == "saison_09") { + basicKeyTmp.insert(std::pair("saison", "9")); + } else if (lastPathName == "saison_10") { + basicKeyTmp.insert(std::pair("saison", "10")); + } else if (lastPathName == "saison_11") { + basicKeyTmp.insert(std::pair("saison", "11")); + } else if (lastPathName == "saison_12") { + basicKeyTmp.insert(std::pair("saison", "12")); + } else if (lastPathName == "saison_13") { + basicKeyTmp.insert(std::pair("saison", "13")); + } else if (lastPathName == "saison_14") { + basicKeyTmp.insert(std::pair("saison", "14")); + } else if (lastPathName == "saison_15") { + basicKeyTmp.insert(std::pair("saison", "15")); + } else if (lastPathName == "saison_16") { + basicKeyTmp.insert(std::pair("saison", "16")); + } else if (lastPathName == "saison_17") { + basicKeyTmp.insert(std::pair("saison", "17")); + } else if (lastPathName == "saison_18") { + basicKeyTmp.insert(std::pair("saison", "18")); + } else if (lastPathName == "saison_19") { + basicKeyTmp.insert(std::pair("saison", "19")); + } else if (lastPathName == "saison_20") { + basicKeyTmp.insert(std::pair("saison", "20")); + } else { + basicKeyTmp.insert(std::pair("series-name", lastPathName)); + } + } + installVideoPath(_srv, itPath, basicKeyTmp); + } + // Add files : + std::vector listSubFile = node.folderGetSub(false, true, "*"); + for (auto &itFile : listSubFile) { + + std::map basicKeyTmp = _basicKey; + pushVideoFile(_srv, itFile, _basicKey); + + } +} + +int main(int _argc, const char *_argv[]) { + etk::init(_argc, _argv); + elog::init(_argc, _argv); + zeus::init(_argc, _argv); + zeus::Client client1; + std::string login = "test1"; + std::string pass = "coucou"; + std::string requestAction = ""; + std::vector args; + for (int32_t iii=1; iii<_argc ; ++iii) { + std::string data = _argv[iii]; + if (etk::start_with(data, "--login=") == true) { + login = &data[8]; + } else if (etk::start_with(data, "--pass=") == true) { + pass = &data[7]; + } else if ( data == "-h" + || data == "--help") { + APPL_PRINT(etk::getApplicationName() << " - help : "); + APPL_PRINT(" " << _argv[0] << " [options] ACTION [arguments]"); + APPL_PRINT(" --login=XXX user login"); + APPL_PRINT(" --pass=XXX pass to connect to the user"); + APPL_PRINT(" ACTION action to execute: clear, push, pushPath, list"); + APPL_PRINT(" [arguments] argument depending on the action"); + return -1; + } else { + if (requestAction == "") { + requestAction = data; + } else { + args.push_back(data); + } + } + } + if (requestAction == "" ) { + requestAction = "list"; + } + APPL_INFO("=================================="); + APPL_INFO("== ZEUS test client start =="); + APPL_INFO("=================================="); + + bool ret = client1.connect(login, pass); + if (ret == false) { + APPL_ERROR(" ==> NOT Authentify with '" << login << "'"); + client1.disconnect(); + return -1; + } + std::string serviceName = "video"; + APPL_INFO(" ----------------------------------"); + APPL_INFO(" -- connect service '" << serviceName << "'"); + APPL_INFO(" ----------------------------------"); + if (client1.waitForService(serviceName) == false) { + APPL_ERROR("==> Service not availlable '" << serviceName << "'"); + client1.disconnect(); + return -1; + } + zeus::service::ProxyVideo remoteServiceVideo = client1.getService("video"); + // remove all media (for test) + if (remoteServiceVideo.exist() == false) { + APPL_ERROR("==> can not connect to the service proxy '" << serviceName << "'"); + client1.disconnect(); + return -1; + } + /* **************************************************************************************** + ** Clear All the data base ... + ****************************************************************************************/ + if (requestAction == "clear") { + APPL_PRINT("============================================"); + APPL_PRINT("== Clear data base: "); + APPL_PRINT("============================================"); + // TODO : Do it : + APPL_INFO("NEED to add check in cmd line to execute it ..."); + return -1; + uint32_t count = remoteServiceVideo.mediaIdCount().wait().get(); + APPL_DEBUG("have " << count << " medias"); + for (uint32_t iii=0; iii " << tmpMax); + std::vector list = remoteServiceVideo.mediaIdGet(iii,tmpMax).wait().get(); + zeus::FutureGroup groupWait; + for (auto& it : list) { + APPL_INFO("remove ELEMENT : " << it); + groupWait.add(remoteServiceVideo.mediaRemove(it)); + } + groupWait.waitFor(echrono::seconds(2000)); + } + APPL_PRINT("============================================"); + APPL_PRINT("== DONE =="); + APPL_PRINT("============================================"); + } else if (requestAction == "list") { + APPL_PRINT("============================================"); + APPL_PRINT("== list files: "); + APPL_PRINT("============================================"); + uint32_t count = remoteServiceVideo.mediaIdCount().wait().get(); + APPL_DEBUG("have " << count << " medias"); + for (uint32_t iii=0; iii " << tmpMax); + std::vector list = remoteServiceVideo.mediaIdGet(iii, tmpMax).wait().get(); + for (auto& it : list) { + std::string name = remoteServiceVideo.mediaMetadataGetKey(it, "title").wait().get(); + std::string serie = remoteServiceVideo.mediaMetadataGetKey(it, "series-name").wait().get(); + std::string episode = remoteServiceVideo.mediaMetadataGetKey(it, "episode").wait().get(); + std::string saison = remoteServiceVideo.mediaMetadataGetKey(it, "saison").wait().get(); + std::string outputDesc = ""; + if (serie != "") { + outputDesc += serie + "-"; + } + if (saison != "") { + outputDesc += "s" + saison + "-"; + } + if (episode != "") { + outputDesc += "e" + episode + "-"; + } + outputDesc += name; + APPL_INFO("[" << it << "] " << outputDesc); + } + } + APPL_PRINT("============================================"); + APPL_PRINT("== DONE =="); + APPL_PRINT("============================================"); + } else if (requestAction == "push") { + APPL_PRINT("============================================"); + APPL_PRINT("== push file: "); + APPL_PRINT("============================================"); + if (args.size() == 0) { + APPL_ERROR("Need to specify some file to push ..."); + } + for (auto &it: args) { + // TODO : Check if already exist ... + pushVideoFile(remoteServiceVideo, it); + } + APPL_PRINT("============================================"); + APPL_PRINT("== DONE =="); + APPL_PRINT("============================================"); + } else if (requestAction == "pushPath") { + APPL_PRINT("============================================"); + APPL_PRINT("== push file: "); + APPL_PRINT("============================================"); + // Send a full path: + // installVideoPath(remoteServiceVideo, "testVideo"); + APPL_PRINT("============================================"); + APPL_PRINT("== DONE =="); + APPL_PRINT("============================================"); + } else { + APPL_PRINT("============================================"); + APPL_ERROR("== Unknow action: '" << requestAction << "'"); + APPL_PRINT("============================================"); + } + client1.disconnect(); + return 0; +} diff --git a/tools/cli-video/lutin_zeus-cli-video.py b/tools/cli-video/lutin_zeus-cli-video.py new file mode 100644 index 0000000..c8a18ce --- /dev/null +++ b/tools/cli-video/lutin_zeus-cli-video.py @@ -0,0 +1,40 @@ +#!/usr/bin/python +import lutin.debug as debug +import lutin.tools as tools + + +def get_type(): + return "BINARY" + +def get_sub_type(): + return "TOOLS" + +def get_desc(): + return "ZEUS generic video client (command line interface)" + +def get_licence(): + return "MPL-2" + +def get_compagny_type(): + return "com" + +def get_compagny_name(): + return "atria-soft" + +def get_maintainer(): + return ["Mr DUPIN Edouard "] + +def configure(target, my_module): + my_module.add_path(".") + my_module.add_depend([ + 'zeus', + 'zeus-service-video' + ]) + my_module.add_src_file([ + 'appl/debug.cpp', + 'appl/main-tool-client-video.cpp' + ]) + return True + + +