Skip to content

Commit

Permalink
Merge pull request xbmc#6325 from arnova/ext_sub_url_encode_fix
Browse files Browse the repository at this point in the history
fixed: External subtitles in custom folder did not work with url encoded files
  • Loading branch information
mkortstiege committed Feb 6, 2015
2 parents 9b727df + a10def9 commit 3583714
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
29 changes: 18 additions & 11 deletions xbmc/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1865,11 +1865,11 @@ void CUtil::ScanForExternalSubtitles(const std::string& strMovie, std::vector<st
vector<std::string> strLookInPaths;

std::string strMovieFileName;
std::string strPath;
std::string strMoviePath;

URIUtils::Split(strMovie, strPath, strMovieFileName);
URIUtils::Split(strMovie, strMoviePath, strMovieFileName);
std::string strMovieFileNameNoExt(URIUtils::ReplaceExtension(strMovieFileName, ""));
strLookInPaths.push_back(strPath);
strLookInPaths.push_back(strMoviePath);

CURL url(strMovie);
std::string isoFileNameNoExt;
Expand Down Expand Up @@ -1911,8 +1911,8 @@ void CUtil::ScanForExternalSubtitles(const std::string& strMovie, std::vector<st
{
CURL url(strMovie);
std::string strArchive = url.GetHostName();
URIUtils::Split(strArchive, strPath, strMovieFileName);
strLookInPaths.push_back(strPath);
URIUtils::Split(strArchive, strMoviePath, strMovieFileName);
strLookInPaths.push_back(strMoviePath);
}

int iSize = strLookInPaths.size();
Expand Down Expand Up @@ -1970,9 +1970,9 @@ void CUtil::ScanForExternalSubtitles(const std::string& strMovie, std::vector<st
// this is last because we dont want to check any common subdirs or cd-dirs in the alternate <subtitles> dir.
if (CMediaSettings::Get().GetAdditionalSubtitleDirectoryChecked() == 1)
{
strPath = CSettings::Get().GetString("subtitles.custompath");
URIUtils::AddSlashAtEnd(strPath);
strLookInPaths.push_back(strPath);
std::string strPath2 = CSettings::Get().GetString("subtitles.custompath");
URIUtils::AddSlashAtEnd(strPath2);
strLookInPaths.push_back(strPath2);
}

std::string strDest;
Expand All @@ -1990,9 +1990,13 @@ void CUtil::ScanForExternalSubtitles(const std::string& strMovie, std::vector<st

for (int j = 0; j < items.Size(); j++)
{
URIUtils::Split(items[j]->GetPath(), strPath, strItem);
std::string strSubtitlePath;
URIUtils::Split(items[j]->GetPath(), strSubtitlePath, strItem);

// Make sure filename uses the correct encoding
std::string strMovieFileNameNoExt2 = URIUtils::ChangeBasePath(strMoviePath, strMovieFileNameNoExt, strSubtitlePath, false);

if (StringUtils::StartsWithNoCase(strItem, strMovieFileNameNoExt)
if (StringUtils::StartsWithNoCase(strItem, strMovieFileNameNoExt2)
|| (!isoFileNameNoExt.empty() && StringUtils::StartsWithNoCase(strItem, isoFileNameNoExt)))
{
// is this a rar or zip-file
Expand All @@ -2019,8 +2023,11 @@ void CUtil::ScanForExternalSubtitles(const std::string& strMovie, std::vector<st
// is this a rar or zip-file
if (URIUtils::IsRAR(strItem) || URIUtils::IsZIP(strItem))
{
// Make sure filename uses the correct encoding
std::string strMovieFileNameNoExt2 = URIUtils::ChangeBasePath(strMoviePath, strMovieFileNameNoExt, "", false);

// check strMovieFileNameNoExt in zip-file
ScanArchiveForSubtitles( items[j]->GetPath(), strMovieFileNameNoExt, vecSubtitles );
ScanArchiveForSubtitles(items[j]->GetPath(), strMovieFileNameNoExt2, vecSubtitles );
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions xbmc/utils/URIUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ std::string URLDecodePath(const std::string& strPath)
return StringUtils::Join(segments, "/");
}

std::string URIUtils::ChangeBasePath(const std::string &fromPath, const std::string &fromFile, const std::string &toPath)
std::string URIUtils::ChangeBasePath(const std::string &fromPath, const std::string &fromFile, const std::string &toPath, const bool &bAddPath /* = true */)
{
std::string toFile = fromFile;

Expand All @@ -444,7 +444,10 @@ std::string URIUtils::ChangeBasePath(const std::string &fromPath, const std::str
if (!IsDOSPath(fromPath) && IsDOSPath(toPath))
StringUtils::Replace(toFile, "/", "\\");

return AddFileToFolder(toPath, toFile);
if (bAddPath)
return AddFileToFolder(toPath, toFile);

return toFile;
}

CURL URIUtils::SubstitutePath(const CURL& url, bool reverse /* = false */)
Expand Down
2 changes: 1 addition & 1 deletion xbmc/utils/URIUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class URIUtils
\param toPath the base path of the resulting URL
\return the full path.
*/
static std::string ChangeBasePath(const std::string &fromPath, const std::string &fromFile, const std::string &toPath);
static std::string ChangeBasePath(const std::string &fromPath, const std::string &fromFile, const std::string &toPath, const bool &bAddPath = true);

static CURL SubstitutePath(const CURL& url, bool reverse = false);
static std::string SubstitutePath(const std::string& strPath, bool reverse = false);
Expand Down

0 comments on commit 3583714

Please sign in to comment.