std::string CStackDirectory::GetStackedTitlePath(const std::string &strPath) { // Load up our REs VECCREGEXP RegExps; CRegExp tempRE(true, CRegExp::autoUtf8); const std::vector<std::string>& strRegExps = g_advancedSettings.m_videoStackRegExps; std::vector<std::string>::const_iterator itRegExp = strRegExps.begin(); while (itRegExp != strRegExps.end()) { (void)tempRE.RegComp(*itRegExp); if (tempRE.GetCaptureTotal() == 4) RegExps.push_back(tempRE); else CLog::Log(LOGERROR, "Invalid video stack RE (%s). Must have exactly 4 captures.", itRegExp->c_str()); ++itRegExp; } return GetStackedTitlePath(strPath, RegExps); }
CStdString CStackDirectory::GetStackedTitlePath(const CStdString &strPath) { // Load up our REs VECCREGEXP RegExps; CRegExp tempRE(true); const CStdStringArray& strRegExps = g_advancedSettings.m_videoStackRegExps; CStdStringArray::const_iterator itRegExp = strRegExps.begin(); vector<pair<int, CStdString> > badStacks; while (itRegExp != strRegExps.end()) { tempRE.RegComp(*itRegExp); if (tempRE.GetCaptureTotal() == 4) RegExps.push_back(tempRE); else CLog::Log(LOGERROR, "Invalid video stack RE (%s). Must have exactly 4 captures.", itRegExp->c_str()); itRegExp++; } return GetStackedTitlePath(strPath, RegExps); }
std::string CStackDirectory::GetStackedTitlePath(const std::string &strPath, VECCREGEXP& RegExps) { CStackDirectory stack; CFileItemList files; std::string strStackTitlePath, strCommonDir = URIUtils::GetParentPath(strPath); const CURL pathToUrl(strPath); stack.GetDirectory(pathToUrl, files); if (files.Size() > 1) { std::string strStackTitle; std::string File1 = URIUtils::GetFileName(files[0]->GetPath()); std::string File2 = URIUtils::GetFileName(files[1]->GetPath()); // Check if source path uses URL encoding if (URIUtils::HasEncodedFilename(CURL(strCommonDir))) { File1 = CURL::Decode(File1); File2 = CURL::Decode(File2); } std::vector<CRegExp>::iterator itRegExp = RegExps.begin(); int offset = 0; while (itRegExp != RegExps.end()) { if (itRegExp->RegFind(File1, offset) != -1) { std::string Title1 = itRegExp->GetMatch(1), Volume1 = itRegExp->GetMatch(2), Ignore1 = itRegExp->GetMatch(3), Extension1 = itRegExp->GetMatch(4); if (offset) Title1 = File1.substr(0, itRegExp->GetSubStart(2)); if (itRegExp->RegFind(File2, offset) != -1) { std::string Title2 = itRegExp->GetMatch(1), Volume2 = itRegExp->GetMatch(2), Ignore2 = itRegExp->GetMatch(3), Extension2 = itRegExp->GetMatch(4); if (offset) Title2 = File2.substr(0, itRegExp->GetSubStart(2)); if (StringUtils::EqualsNoCase(Title1, Title2)) { if (!StringUtils::EqualsNoCase(Volume1, Volume2)) { if (StringUtils::EqualsNoCase(Ignore1, Ignore2) && StringUtils::EqualsNoCase(Extension1, Extension2)) { // got it strStackTitle = Title1 + Ignore1 + Extension1; // Check if source path uses URL encoding if (URIUtils::HasEncodedFilename(CURL(strCommonDir))) strStackTitle = CURL::Encode(strStackTitle); itRegExp = RegExps.end(); break; } else // Invalid stack break; } else // Early match, retry with offset { offset = itRegExp->GetSubStart(3); continue; } } } } offset = 0; itRegExp++; } if (!strCommonDir.empty() && !strStackTitle.empty()) strStackTitlePath = strCommonDir + strStackTitle; } return strStackTitlePath; }
CStdString CStackDirectory::GetStackedTitlePath(const CStdString &strPath, VECCREGEXP& RegExps) { CStackDirectory stack; CFileItemList files; CStdString strStackTitlePath, strCommonDir = URIUtils::GetParentPath(strPath); stack.GetDirectory(strPath, files); if (files.Size() > 1) { CStdString strStackTitle; CStdString File1 = URIUtils::GetFileName(files[0]->m_strPath); CStdString File2 = URIUtils::GetFileName(files[1]->m_strPath); std::vector<CRegExp>::iterator itRegExp = RegExps.begin(); int offset = 0; while (itRegExp != RegExps.end()) { if (itRegExp->RegFind(File1, offset) != -1) { CStdString Title1 = itRegExp->GetMatch(1), Volume1 = itRegExp->GetMatch(2), Ignore1 = itRegExp->GetMatch(3), Extension1 = itRegExp->GetMatch(4); if (offset) Title1 = File1.substr(0, itRegExp->GetSubStart(2)); if (itRegExp->RegFind(File2, offset) != -1) { CStdString Title2 = itRegExp->GetMatch(1), Volume2 = itRegExp->GetMatch(2), Ignore2 = itRegExp->GetMatch(3), Extension2 = itRegExp->GetMatch(4); if (offset) Title2 = File2.substr(0, itRegExp->GetSubStart(2)); if (Title1.Equals(Title2)) { if (!Volume1.Equals(Volume2)) { if (Ignore1.Equals(Ignore2) && Extension1.Equals(Extension2)) { // got it strStackTitle = Title1 + Ignore1 + Extension1; itRegExp = RegExps.end(); break; } else // Invalid stack break; } else // Early match, retry with offset { offset = itRegExp->GetSubStart(3); continue; } } } } offset = 0; itRegExp++; } if (!strCommonDir.empty() && !strStackTitle.empty()) strStackTitlePath = strCommonDir + strStackTitle; } return strStackTitlePath; }