Skip to content

Commit

Permalink
Merge pull request #7285 from ace20022/subs_arch
Browse files Browse the repository at this point in the history
[subs] Some improvements and a fix for subs in archives
  • Loading branch information
ace20022 committed Jun 15, 2015
2 parents a95ade6 + 8884ba4 commit 3020230
Showing 1 changed file with 51 additions and 51 deletions.
102 changes: 51 additions & 51 deletions xbmc/Util.cpp
Expand Up @@ -614,7 +614,7 @@ void CUtil::ClearTempFonts()
}
}

static const char * sub_exts[] = { ".utf", ".utf8", ".utf-8", ".sub", ".srt", ".smi", ".rt", ".txt", ".ssa", ".aqt", ".jss", ".ass", ".idx", NULL};
static const char * sub_exts[] = { ".srt", ".idx", ".sub", ".ass", ".utf", ".utf8", ".utf-8", ".smi", ".rt", ".txt", ".ssa", ".aqt", ".jss", NULL};

int64_t CUtil::ToInt64(uint32_t high, uint32_t low)
{
Expand Down Expand Up @@ -1854,73 +1854,73 @@ void CUtil::ScanForExternalSubtitles(const std::string& strMovie, std::vector<st
CLog::Log(LOGDEBUG,"%s: END (total time: %i ms)", __FUNCTION__, (int)(XbmcThreads::SystemClockMillis() - startTimer));
}

int CUtil::ScanArchiveForSubtitles( const std::string& strArchivePath, const std::string& strMovieFileNameNoExt, std::vector<std::string>& vecSubtitles )
int CUtil::ScanArchiveForSubtitles(const std::string& strArchivePath, const std::string& strMovieFileNameNoExt, std::vector<std::string>& vecSubtitles)
{
CLog::Log(LOGDEBUG, "ScanArchiveForSubtitles:: Scanning archive %s", strArchivePath.c_str());
int nSubtitlesAdded = 0;
CFileItemList ItemList;

// zip only gets the root dir
if (URIUtils::HasExtension(strArchivePath, ".zip"))
{
CURL pathToUrl(strArchivePath);
CURL zipURL = URIUtils::CreateArchivePath("zip", pathToUrl, "");
if (!CDirectory::GetDirectory(zipURL, ItemList, "", DIR_FLAG_NO_FILE_DIRS))
return false;
CURL pathToUrl(strArchivePath);
CURL zipURL = URIUtils::CreateArchivePath("zip", pathToUrl, "");
if (!CDirectory::GetDirectory(zipURL, ItemList, "", DIR_FLAG_NO_FILE_DIRS))
return false;
}
else
{
#ifdef HAS_FILESYSTEM_RAR
// get _ALL_files in the rar, even those located in subdirectories because we set the bMask to false.
// so now we dont have to find any subdirs anymore, all files in the rar is checked.
if( !g_RarManager.GetFilesInRar(ItemList, strArchivePath, false, "") )
#ifdef HAS_FILESYSTEM_RAR
// get _ALL_files in the rar, even those located in subdirectories because we set the bMask to false.
// so now we dont have to find any subdirs anymore, all files in the rar is checked.
if (!g_RarManager.GetFilesInRar(ItemList, strArchivePath, false, ""))
return false;
#else
return false;
#else
return false;
#endif
#endif
}
for (int it= 0 ; it <ItemList.Size();++it)
for (int it = 0; it < ItemList.Size(); ++it)
{
std::string strPathInRar = ItemList[it]->GetPath();
std::string strExt = URIUtils::GetExtension(strPathInRar);

// always check any embedded rar archives
// checking for embedded rars, I moved this outside the sub_ext[] loop. We only need to check this once for each file.
if (URIUtils::IsRAR(strPathInRar) || URIUtils::IsZIP(strPathInRar))
{
CURL urlRar;
CURL pathToUrl(strArchivePath);
if (strExt == ".rar")
urlRar = URIUtils::CreateArchivePath("rar", pathToUrl, strPathInRar);
else
urlRar = URIUtils::CreateArchivePath("zip", pathToUrl, strPathInRar);
ScanArchiveForSubtitles(urlRar.Get(), strMovieFileNameNoExt, vecSubtitles);
}
// done checking if this is a rar-in-rar
std::string strPathInRar = ItemList[it]->GetPath();
std::string strExt = URIUtils::GetExtension(strPathInRar);

// check that the found filename matches the movie filename
int fnl = strMovieFileNameNoExt.size();
if (fnl && !StringUtils::StartsWithNoCase(URIUtils::GetFileName(strPathInRar), strMovieFileNameNoExt))
continue;
// checking for embedded archives
if (URIUtils::IsArchive(strPathInRar))
{
std::string archInArch(strPathInRar);
if (strExt == ".rar")
{
CURL pathToUrl(strArchivePath);
archInArch = URIUtils::CreateArchivePath("rar", pathToUrl, strPathInRar).Get();
}

int iPos=0;
ScanArchiveForSubtitles(archInArch, strMovieFileNameNoExt, vecSubtitles);
continue;
}
// check that the found filename matches the movie filename
int fnl = strMovieFileNameNoExt.size();
if (fnl && !StringUtils::StartsWithNoCase(URIUtils::GetFileName(strPathInRar), strMovieFileNameNoExt))
continue;

int iPos = 0;
while (sub_exts[iPos])
{
if (StringUtils::EqualsNoCase(strExt, sub_exts[iPos]))
{
CURL pathToURL(strArchivePath);
std::string strSourceUrl;
if (URIUtils::HasExtension(strArchivePath, ".rar"))
strSourceUrl = URIUtils::CreateArchivePath("rar", pathToURL, strPathInRar).Get();
else
strSourceUrl = strPathInRar;

CLog::Log(LOGINFO, "%s: found subtitle file %s\n", __FUNCTION__, strSourceUrl.c_str() );
vecSubtitles.push_back( strSourceUrl );
nSubtitlesAdded++;
}

iPos++;
if (StringUtils::EqualsNoCase(strExt, sub_exts[iPos]))
{
CURL pathToURL(strArchivePath);
std::string strSourceUrl;
if (URIUtils::HasExtension(strArchivePath, ".rar"))
strSourceUrl = URIUtils::CreateArchivePath("rar", pathToURL, strPathInRar).Get();
else
strSourceUrl = strPathInRar;

CLog::Log(LOGINFO, "%s: found subtitle file %s\n", __FUNCTION__, strSourceUrl.c_str());
vecSubtitles.push_back(strSourceUrl);
nSubtitlesAdded++;
break;
}

iPos++;
}
}

Expand Down

0 comments on commit 3020230

Please sign in to comment.