//-------------------------------------------------------------- void handleChapters::readDir(){ printf("reading directory sir\n"); // load content dir.listDir("content/"); dir.sort(); // in linux the file system doesn't return file lists ordered in alphabetical order //allocate the vector to have as many strings as files if( dir.size() ){ chapters.assign(dir.size(), Chapters()); } // you can now iterate through the files and load them into the Chapters vector for(int i = 0; i < (int)dir.size(); i++){ file.open(dir.getPath(i)); if(file.isDirectory()){ dir.sort(); // do this again to alfabetize chapters[i].complete = false; // don't worry kids, we're just not certain yet chapters[i].inOrder = false; // let me get back to that chapters[i].name = dir.getName(i); printf("%s\n",chapters[i].name.c_str()); // getting filename should be a folder // write a new chapter to the XMl object if( XML.pushTag("movies", lastTagNumber) ){ dir.listDir(dir.getPath(i)+"/"); dir.sort(); int lastChapNumber = XML.addTag("chapter"); // writing chapter folder name to XML object XML.setValue("chapter:name", chapters[i].name, lastChapNumber); //printf("tagNum: %i\n",lastChapNumber); //printf("lastTagNumber: %i\n",lastTagNumber); // iterate through directory for(int f = 0; f < (int)dir.size(); f++){ file.open(dir.getPath(f)); printf("iterating through directory %i\n",f); if(file.isFile()){ file.open(dir.getPath(f)); // check if movie is named L, M or R then add to filmInfo object thats inside Chapters // furthermore we check for several aspects of the film files, some info is only gained // when actually loading the video, so thats where the tempMov kicks in. This is a bit // processor heavy though, so do't do it all the time! string baseName = file.getBaseName(); string firstChar = ""; firstChar += baseName[0]; printf("filename: %s\n", dir.getName(f).c_str()); if(firstChar == "L"){ // left screen duh chapters[i].left.file = dir.getPath(f); chapters[i].left.name = dir.getName(f); chapters[i].left.filesize = file.getSize(); ofVideoPlayer vid; videos.push_back(vid); if (videos.back().loadMovie(chapters[i].left.file)) { chapters[i].left.width = videos.back().getWidth(); chapters[i].left.height = videos.back().getHeight(); chapters[i].left.duration = videos.back().getDuration(); chapters[i].left.numFrames = videos.back().getTotalNumFrames(); } chapters[i].left.sameSettings = false; // figure this out later if( XML.pushTag("chapter", lastChapNumber) ){ int tagNum = XML.addTag("left"); // writing film info of this thing to XML XML.setValue("left:file", chapters[i].left.file, tagNum); XML.setValue("left:name", chapters[i].left.name, tagNum); XML.setValue("left:duration", chapters[i].left.duration, tagNum); XML.setValue("left:frames", chapters[i].left.numFrames, tagNum); XML.setValue("left:filesize", chapters[i].left.filesize, tagNum); XML.setValue("left:width", chapters[i].left.width, tagNum); XML.setValue("left:height", chapters[i].left.height, tagNum); XML.popTag(); } } else if(firstChar == "M"){ // middle screen duh chapters[i].middle.file = dir.getPath(f); chapters[i].middle.name = dir.getName(f); chapters[i].middle.filesize = file.getSize(); ofVideoPlayer vid; videos.push_back(vid); if (videos.back().loadMovie(chapters[i].middle.file)) { chapters[i].middle.width = videos.back().getWidth(); chapters[i].middle.height = videos.back().getHeight(); chapters[i].middle.duration = videos.back().getDuration(); chapters[i].middle.numFrames = videos.back().getTotalNumFrames(); } chapters[i].middle.sameSettings = false; // figure this out later if( XML.pushTag("chapter", lastChapNumber) ){ int tagNum = XML.addTag("middle"); // writing film info of this thing to XML XML.setValue("middle:file", chapters[i].middle.file, tagNum); XML.setValue("middle:name", chapters[i].middle.name, tagNum); XML.setValue("middle:duration", chapters[i].middle.duration, tagNum); XML.setValue("middle:frames", chapters[i].left.numFrames, tagNum); XML.setValue("middle:filesize", chapters[i].middle.filesize, tagNum); XML.setValue("middle:width", chapters[i].middle.width, tagNum); XML.setValue("middle:height", chapters[i].middle.height, tagNum); XML.popTag(); } } else if(firstChar == "R"){ // right screen duh chapters[i].right.file = dir.getPath(f); chapters[i].right.name = dir.getName(f); chapters[i].right.filesize = file.getSize(); ofVideoPlayer vid; videos.push_back(vid); if (videos.back().loadMovie(chapters[i].right.file)) { chapters[i].right.width = videos.back().getWidth(); chapters[i].right.height = videos.back().getHeight(); chapters[i].right.duration = videos.back().getDuration(); chapters[i].right.numFrames = videos.back().getTotalNumFrames(); } chapters[i].right.sameSettings = false; // figure this out later if( XML.pushTag("chapter", lastChapNumber) ){ int tagNum = XML.addTag("right"); // writing film info of this thing to XML XML.setValue("right:file", chapters[i].right.file, tagNum); XML.setValue("right:name", chapters[i].right.name, tagNum); XML.setValue("right:duration", chapters[i].right.duration, tagNum); XML.setValue("right:frames", chapters[i].left.numFrames, tagNum); XML.setValue("right:filesize", chapters[i].right.filesize, tagNum); XML.setValue("right:width", chapters[i].right.width, tagNum); XML.setValue("right:height", chapters[i].right.height, tagNum); XML.popTag(); } } } } dir.listDir("content/"); dir.sort(); // pop out of chapter XML.popTag(); } } else { printf("no directory senior! - %s\n", dir.getPath(i).c_str()); } } checkFiles(); // checking to see if all files are in order writeXML(); // write it to an XML file, makes it easy to check whats wrong // chopping up the xml file into 300 char pieces so I can send it over the MPE network for checking XML.copyXmlToString(totalXmlString); totalXmlString.erase(std::remove(totalXmlString.begin(), totalXmlString.end(), '\n'), totalXmlString.end()); totalXmlString.erase(std::remove(totalXmlString.begin(), totalXmlString.end(), ' '), totalXmlString.end()); totalXmlString.erase(std::remove(totalXmlString.begin(), totalXmlString.end(), ','), totalXmlString.end()); int chopLength = 300; float fChops = float(totalXmlString.size())/float(chopLength); float fChopsRoundUP = ceil(fChops); int numChops = int(fChopsRoundUP); partXML.resize(numChops); for (int i = 0; i < numChops; i++) { partXML[i].part = totalXmlString.substr(i*chopLength,chopLength); partXML[i].checked = false; } // deleting the videoplayer instances we just used for (int i = 0; i < videos.size(); i++) { videos[i].close(); } videos.erase(videos.begin(), videos.end()); }
bool ParseCUESheet(CString cueData, CAtlList<Chapters> &ChaptersList, CString& Title, CString& Performer) { BOOL fAudioTrack; int track_no = -1, /*index, */index_cnt = 0; REFERENCE_TIME rt = _I64_MIN; CString TrackTitle; CString title, performer; Title.Empty(); Performer.Empty(); CAtlList<CString> cuelines; Explode(cueData, cuelines, '\n'); if (cuelines.GetCount() <= 1) { return false; } while (cuelines.GetCount()) { CString cueLine = cuelines.RemoveHead().Trim(); CString cmd = GetCUECommand(cueLine); if (cmd == _T("TRACK")) { if (rt != _I64_MIN && track_no != -1 && index_cnt) { MakeCUETitle(TrackTitle, title, performer, track_no); if (!TrackTitle.IsEmpty()) { ChaptersList.AddTail(Chapters(TrackTitle, rt)); } } rt = _I64_MIN; index_cnt = 0; TCHAR type[256]; swscanf_s(cueLine, _T("%d %s"), &track_no, type, _countof(type)-1); fAudioTrack = (wcscmp(type, _T("AUDIO")) == 0); TrackTitle.Format(_T("Track %02d"), track_no); } else if (cmd == _T("TITLE")) { cueLine.Trim(_T(" \"")); title = cueLine; if (track_no == -1) { Title = title; } } else if (cmd == _T("PERFORMER")) { cueLine.Trim(_T(" \"")); performer = cueLine; if (track_no == -1) { Performer = performer; } } else if (cmd == _T("INDEX")) { int idx, mm, ss, ff; swscanf_s(cueLine, _T("%d %d:%d:%d"), &idx, &mm, &ss, &ff); if (fAudioTrack) { index_cnt++; rt = MILLISECONDS_TO_100NS_UNITS((mm * 60 + ss) * 1000); } } } if (rt != _I64_MAX && track_no != -1 && index_cnt) { MakeCUETitle(TrackTitle, title, performer, track_no); if (!TrackTitle.IsEmpty()) { ChaptersList.AddTail(Chapters(TrackTitle, rt)); } } if (ChaptersList.GetCount()) { return true; } else { return false; } }