void CUrlBufferModule::CheckLineForLink(const CString& sMessage, const CString& sOrigin) { if(sOrigin != m_pUser->GetUserName() && GetNV("enable").ToBool() ) { VCString words; CString output; sMessage.Split(" ", words, false, "", "", true, true); for (size_t a = 0; a < words.size(); a++) { CString& word = words[a]; if(word.Left(4) == "http" || word.Left(4) == "www.") { //if you find an image download it, save it in the www directory and keep the new link in buffer VCString tokens; word.Split("/", tokens, false, "", "", true, true); CString name = tokens[tokens.size()-1]; word.Split(".", tokens, false, "", "", true, true); //if it's an image link download/upload it else just keep the link time_t curtime; time(&curtime); CString dir = GetNV("directory") + CUtils::FormatTime(curtime,"%Y-%m-%d", m_pUser->GetTimezone()) + "/"; CString nickname = (sOrigin.empty())? m_pUser->GetUserName() : sOrigin; if(!CFile::Exists(dir) && !CFile::IsDir(dir, false)) { CDir::MakeDir(dir, 0775); } if(isValidExtension( tokens[tokens.size()-1] )) { std::stringstream ss; if( GetNV("enablelocal").ToBool()) { ss << "wget -b -O " << dir.c_str() << name <<" -q " << word.c_str() << " 2>&1"; getStdoutFromCommand(ss.str()); } ss.str(""); if (!word.WildCmp("*imgur*") && GetNV("reupload").ToBool()) { ss << "curl -d \"image=" << word.c_str() << "\" -d \"key=5ce86e7f95d8e58b18931bf290f387be\" http://api.imgur.com/2/upload.xml | sed -n 's/.*<original>\\(.*\\)<\\/original>.*/\\1/p' 2>&1"; output = getStdoutFromCommand(ss.str()); lastUrls.push_back(output); } else { lastUrls.push_back(word); } } else if(GetNV("bufferalllinks").ToBool()){ lastUrls.push_back(word); //append nick:link to file CString filename = dir + "links.txt"; std::ofstream log(filename.c_str() , std::ios_base::app | std::ios_base::out); log << nickname << ": " << word << "\n"; } nicks.push_back( nickname ); } } } }
int videoSegmenter(std::string inputFile, int segmentLength, std::string outputFolder) { std::string ffcmd = "ffmpeg -i " + inputFile; std::string ffout = getStdoutFromCommand(ffcmd); int ffDoffset = (int) ffout.find("Duration: ", 0); if (ffDoffset > 0) { outputFolder = outputFolder[outputFolder.length() - 1] == '/' ? outputFolder : outputFolder + "/"; struct stat st; if (stat(outputFolder.c_str(), &st) != -1) { std::string ssi = std::string(itoa(segmentLength)); std::string ts = ffout.substr(ffDoffset + 10, 11); int ei = inputFile.rfind(".", -1); std::string ifwoe = inputFile.substr(0, ei); std::string ife = inputFile.substr(ei); float its = timeToSec(ts); int sc = 1; std::string ifn = ifwoe.substr(ifwoe.rfind("/", -1) + 1); std::string ifm3u8 = outputFolder + ifn + ".m3u8"; std::string m3u = "#EXTM3U" "\n#EXT-X-TARGETDURATION:" + ssi; std::string cmd; std::string sn; spawn segmenter; while (its > 0) { sn = outputFolder + ifn + "-" + std::string(itoa(sc)) + ife; cmd = "ffmpeg -i " + inputFile + " -y -codec copy -ss " + std::string(itoa((sc - 1) * segmentLength)) + " -t " + ssi + sn; segmenter = spawn(cmd, false, NULL, true); waitpid(segmenter.cpid, NULL, WUNTRACED); m3u += "\n#EXTINF:" + (its < segmentLength ? std::string(itoa(its)) : ssi) + "," + "\n" + ifn + "-" + std::string(itoa(sc)) + ife; its -= segmentLength; sc++; } m3u += "\n#EXT-X-ENDLIST"; iconv_t cd = iconv_open("UTF-8", ""); int fd = open(ifm3u8.c_str(), O_WRONLY | O_TRUNC | O_CREAT); char * src = (char *) m3u.c_str(); char * inbuf = src; size_t inbytesleft = m3u.length(); char dst[inbytesleft]; char * outbuf = dst; size_t outbytesleft = inbytesleft; size_t s = iconv(cd, &inbuf, &inbytesleft, (char **) &outbuf, &outbytesleft); dst[m3u.length()] = '\0'; write(fd, dst, strlen(dst)); close(fd); } else { return -1; } } else { return -1; } return 0; }