From: ronag Date: Tue, 25 Oct 2011 14:14:52 +0000 (+0000) Subject: 2.0.2: Fixed CINF command. X-Git-Tag: 2.0.0.2~16 X-Git-Url: https://git.sesse.net/?p=casparcg;a=commitdiff_plain;h=0629f3b9b79c8a5dcab3c6b082cd9ac95c119b68 2.0.2: Fixed CINF command. git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@1466 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d --- diff --git a/protocol/amcp/AMCPCommandsImpl.cpp b/protocol/amcp/AMCPCommandsImpl.cpp index 9cee8d6cf..aec863e88 100644 --- a/protocol/amcp/AMCPCommandsImpl.cpp +++ b/protocol/amcp/AMCPCommandsImpl.cpp @@ -83,52 +83,57 @@ namespace caspar { namespace protocol { using namespace core; +std::wstring MediaInfo(const boost::filesystem::wpath& path) +{ + if(boost::filesystem::is_regular_file(path)) + { + std::wstring clipttype = TEXT(" N/A "); + std::wstring extension = boost::to_upper_copy(path.extension()); + if(extension == TEXT(".TGA") || extension == TEXT(".COL") || extension == L".PNG" || extension == L".JPEG" || extension == L".JPG" || + extension == L"GIF" || extension == L"BMP") + clipttype = TEXT(" STILL "); + else if(extension == TEXT(".SWF") || extension == TEXT(".DV") || extension == TEXT(".MOV") || extension == TEXT(".MPG") || + extension == TEXT(".AVI") || extension == TEXT(".FLV") || extension == TEXT(".F4V") || extension == TEXT(".MP4") || + extension == L".M2V" || extension == L".H264" || extension == L".MKV" || extension == L".WMV" || extension == L".DIVX" || + extension == L".XVID" || extension == L".OGG") + clipttype = TEXT(" MOVIE "); + else if(extension == TEXT(".WAV") || extension == TEXT(".MP3")) + clipttype = TEXT(" STILL "); + + if(clipttype != TEXT(" N/A ")) + { + auto is_not_digit = [](char c){ return std::isdigit(c) == 0; }; + + auto relativePath = boost::filesystem::wpath(path.file_string().substr(env::media_folder().size()-1, path.file_string().size())); + + auto writeTimeStr = boost::posix_time::to_iso_string(boost::posix_time::from_time_t(boost::filesystem::last_write_time(path))); + writeTimeStr.erase(std::remove_if(writeTimeStr.begin(), writeTimeStr.end(), is_not_digit), writeTimeStr.end()); + auto writeTimeWStr = std::wstring(writeTimeStr.begin(), writeTimeStr.end()); + + auto sizeStr = boost::lexical_cast(boost::filesystem::file_size(path)); + sizeStr.erase(std::remove_if(sizeStr.begin(), sizeStr.end(), is_not_digit), sizeStr.end()); + auto sizeWStr = std::wstring(sizeStr.begin(), sizeStr.end()); + + auto str = relativePath.replace_extension(TEXT("")).external_file_string(); + if(str[0] == '\\' || str[0] == '/') + str = std::wstring(str.begin() + 1, str.end()); + + return std::wstring() + TEXT("\"") + str + + + TEXT("\" ") + clipttype + + + TEXT(" ") + sizeStr + + + TEXT(" ") + writeTimeWStr + + + TEXT("\r\n"); + } + } + return L""; +} + std::wstring ListMedia() { std::wstringstream replyString; - for (boost::filesystem::wrecursive_directory_iterator itr(env::media_folder()), end; itr != end; ++itr) - { - if(boost::filesystem::is_regular_file(itr->path())) - { - std::wstring clipttype = TEXT(" N/A "); - std::wstring extension = boost::to_upper_copy(itr->path().extension()); - if(extension == TEXT(".TGA") || extension == TEXT(".COL") || extension == L".PNG" || extension == L".JPEG" || extension == L".JPG" || - extension == L"GIF" || extension == L"BMP") - clipttype = TEXT(" STILL "); - else if(extension == TEXT(".SWF") || extension == TEXT(".DV") || extension == TEXT(".MOV") || extension == TEXT(".MPG") || - extension == TEXT(".AVI") || extension == TEXT(".FLV") || extension == TEXT(".F4V") || extension == TEXT(".MP4") || - extension == L".M2V" || extension == L".H264" || extension == L".MKV" || extension == L".WMV" || extension == L".DIVX" || - extension == L".XVID" || extension == L".OGG") - clipttype = TEXT(" MOVIE "); - else if(extension == TEXT(".WAV") || extension == TEXT(".MP3")) - clipttype = TEXT(" STILL "); - - if(clipttype != TEXT(" N/A ")) - { - auto is_not_digit = [](char c){ return std::isdigit(c) == 0; }; - - auto relativePath = boost::filesystem::wpath(itr->path().file_string().substr(env::media_folder().size()-1, itr->path().file_string().size())); - - auto writeTimeStr = boost::posix_time::to_iso_string(boost::posix_time::from_time_t(boost::filesystem::last_write_time(itr->path()))); - writeTimeStr.erase(std::remove_if(writeTimeStr.begin(), writeTimeStr.end(), is_not_digit), writeTimeStr.end()); - auto writeTimeWStr = std::wstring(writeTimeStr.begin(), writeTimeStr.end()); - - auto sizeStr = boost::lexical_cast(boost::filesystem::file_size(itr->path())); - sizeStr.erase(std::remove_if(sizeStr.begin(), sizeStr.end(), is_not_digit), sizeStr.end()); - auto sizeWStr = std::wstring(sizeStr.begin(), sizeStr.end()); - - auto str = relativePath.replace_extension(TEXT("")).external_file_string(); - if(str[0] == '\\' || str[0] == '/') - str = std::wstring(str.begin() + 1, str.end()); - - replyString << TEXT("\"") << str - << TEXT("\" ") << clipttype - << TEXT(" ") << sizeStr - << TEXT(" ") << writeTimeWStr - << TEXT("\r\n"); - } - } - } + for (boost::filesystem::wrecursive_directory_iterator itr(env::media_folder()), end; itr != end; ++itr) + replyString << MediaInfo(itr->path()); + return boost::to_upper_copy(replyString.str()); } @@ -196,11 +201,16 @@ bool ParamCommand::DoExecute() //Perform loading of the clip try { - auto what = _parameters.at(2); + auto what = _parameters.at(0); + + std::wstring param = _parameters2.at(1); + for(auto it = std::begin(_parameters2)+2; it != std::end(_parameters2); ++it) + param += L" " + *it; + if(what == L"B") - GetChannel()->stage()->background(GetLayerIndex()).get()->param(_parameters.at(3)); + GetChannel()->stage()->background(GetLayerIndex()).get()->param(param); else if(what == L"F") - GetChannel()->stage()->foreground(GetLayerIndex()).get()->param(_parameters.at(3)); + GetChannel()->stage()->foreground(GetLayerIndex()).get()->param(param); CASPAR_LOG(info) << "Executed param: " << _parameters[0] << TEXT(" successfully"); @@ -765,7 +775,7 @@ bool StatusCommand::DoExecute() auto status = GetChannel()->stage()->get_status(GetLayerIndex()); std::wstringstream status_text; status_text - << L"202 STATUS OK\r\n" + << L"200 STATUS OK\r\n" << L"FOREGROUND:" << status.foreground << L"\r\n" << L"BACKGROUND:" << status.background << L"\r\n" << L"STATUS:" << (status.is_paused ? L"PAUSED" : L"PLAYING") << L"\r\n" @@ -1208,30 +1218,34 @@ bool DataCommand::DoExecuteList() bool CinfCommand::DoExecute() { std::wstringstream replyString; + + try + { + std::wstring info; + for (boost::filesystem::wrecursive_directory_iterator itr(env::media_folder()), end; itr != end; ++itr) + { + auto path = itr->path(); + auto file = path.replace_extension(L"").filename(); + if(boost::iequals(file, _parameters.at(0))) + info += MediaInfo(itr->path()) + L"\r\n"; + } - std::wstring filename = _parameters[0]; - - // TODO: - - //FileInfo fileInfo; - - //MediaManagerPtr pMediaManager = GetApplication()->FindMediaFile(filename, &fileInfo); - //if(pMediaManager != 0 && fileInfo.filetype.length() >0) //File was found - //{ - // if(pMediaManager->getFileInfo(&fileInfo)) - // { - // TCHAR numBuffer[32]; - // _ui64tot_s(fileInfo.size, numBuffer, 32, 10); - - // replyString << TEXT("201 CINF OK\r\n\"") << fileInfo.filename << TEXT("\" ") << fileInfo.type << TEXT("/") << fileInfo.filetype << TEXT("/") << fileInfo.encoding << TEXT(" ") << numBuffer << TEXT("\r\n"); - - // SetReplyString(replyString.str()); - // return true; - // } - //} - - SetReplyString(TEXT("404 CINF ERROR\r\n")); - return false; + if(info.empty()) + { + SetReplyString(TEXT("404 CINF ERROR\r\n")); + return false; + } + replyString << TEXT("200 INFO OK\r\n"); + replyString << info << "\r\n"; + } + catch(...) + { + SetReplyString(TEXT("404 CINF ERROR\r\n")); + return false; + } + + SetReplyString(replyString.str()); + return true; } void GenerateChannelInfo(int index, const safe_ptr& pChannel, std::wstringstream& replyString) @@ -1241,32 +1255,30 @@ void GenerateChannelInfo(int index, const safe_ptr& pChanne bool InfoCommand::DoExecute() { - std::wstringstream replyString; - - if(_parameters.size() >= 1) + try { - int channelIndex = _ttoi(_parameters[0].c_str())-1; - - if(channelIndex < channels_.size()) + std::wstringstream replyString; + if(_parameters.size() >= 1) { + int channelIndex = _ttoi(_parameters.at(0).c_str())-1; replyString << TEXT("201 INFO OK\r\n"); - GenerateChannelInfo(channelIndex, channels_[channelIndex], replyString); + GenerateChannelInfo(channelIndex, channels_.at(channelIndex), replyString); } else { - SetReplyString(TEXT("401 INFO ERROR\r\n")); - return false; + replyString << TEXT("200 INFO OK\r\n"); + for(size_t n = 0; n < channels_.size(); ++n) + GenerateChannelInfo(n, channels_[n], replyString); + replyString << TEXT("\r\n"); } + SetReplyString(replyString.str()); } - else + catch(...) { - replyString << TEXT("200 INFO OK\r\n"); - for(size_t n = 0; n < channels_.size(); ++n) - GenerateChannelInfo(n, channels_[n], replyString); - replyString << TEXT("\r\n"); + SetReplyString(TEXT("401 INFO ERROR\r\n")); + return false; } - SetReplyString(replyString.str()); return true; }