All pastes #1440561 Raw Edit

Something

public diff v1 · immutable
#1440561 ·published 2009-05-30 03:07 UTC
rendered paste body
Index: xbmc/Util.cpp===================================================================--- xbmc/Util.cpp	(revision 20783)+++ xbmc/Util.cpp	(working copy)@@ -1313,181 +1313,157 @@  void CUtil::CacheSubtitles(const CStdString& strMovie, CStdString& strExtensionCached, XFILE::IFileCallback *pCallback ) {-  DWORD startTimer = timeGetTime();-  CLog::Log(LOGDEBUG,"%s: START", __FUNCTION__);--  // new array for commons sub dirs-  const char * common_sub_dirs[] = {"subs",-                              "Subs",-                              "subtitles",-                              "Subtitles",-                              "vobsubs",-                              "Vobsubs",-                              "sub",-                              "Sub",-                              "vobsub",-                              "Vobsub",-                              "subtitle",-                              "Subtitle",-                              NULL};--  vector<CStdString> vecExtensionsCached;-  strExtensionCached = "";--  ClearSubtitles();-   CFileItem item(strMovie, false);+  if (!item.IsVideo()) return ;   if (item.IsInternetStream()) return ;   if (item.IsHDHomeRun()) return ;   if (item.IsPlayList()) return ;-  if (!item.IsVideo()) return ; -  vector<CStdString> strLookInPaths;+  DWORD startTimer = timeGetTime();+  CLog::Log(LOGDEBUG,"%s: START", __FUNCTION__); +  vector<CStdString> vecExtensionsCached;+  vector<CStdString> strLookInPaths;   CStdString strFileName;   CStdString strFileNameNoExt;   CStdString strPath;+  strExtensionCached = ""; +  ClearSubtitles();++  // Add our current path to loopinpaths   CUtil::Split(strMovie, strPath, strFileName);-  ReplaceExtension(strFileName, "", strFileNameNoExt);+  CUtil::ReplaceExtension(strFileName, "", strFileNameNoExt);   strLookInPaths.push_back(strPath); -  if (!g_stSettings.iAdditionalSubtitleDirectoryChecked && !g_guiSettings.GetString("subtitles.custompath").IsEmpty()) // to avoid checking non-existent directories (network) every time..+  // Check the custom sub path if it exists and we haven't already checked it+  // But don't add it to lookinpaths 'til we've checked for common paths+  if (!g_stSettings.iAdditionalSubtitleDirectoryChecked && !g_guiSettings.GetString("subtitles.custompath").IsEmpty())   {     if (!g_application.getNetwork().IsAvailable() && !IsHD(g_guiSettings.GetString("subtitles.custompath")))     {+      // Disable, not local and the network is down       CLog::Log(LOGINFO,"CUtil::CacheSubtitles: disabling alternate subtitle directory for this session, it's nonaccessible");-      g_stSettings.iAdditionalSubtitleDirectoryChecked = -1; // disabled+      g_stSettings.iAdditionalSubtitleDirectoryChecked = -1;     }     else if (!CDirectory::Exists(g_guiSettings.GetString("subtitles.custompath")))     {+      // Disable, it doesn't exist       CLog::Log(LOGINFO,"CUtil::CacheSubtitles: disabling alternate subtitle directory for this session, it's nonexistant");-      g_stSettings.iAdditionalSubtitleDirectoryChecked = -1; // disabled+      g_stSettings.iAdditionalSubtitleDirectoryChecked = -1;     }--    g_stSettings.iAdditionalSubtitleDirectoryChecked = 1;+    else+    {+      // All good+      g_stSettings.iAdditionalSubtitleDirectoryChecked = 1;+    }   } -  if (strMovie.substr(0,6) == "rar://") // <--- if this is found in main path then ignore it!+  // Add stack/archive parent paths to lookinpaths if applicable+  if (item.IsStack())   {+    CUtil::GetParentPath(strMovie, strPath);+    strLookInPaths.push_back(strPath);+  }+  +  if (CUtil::IsInArchive(strMovie))+  {     CURL url(strMovie);     CStdString strArchive = url.GetHostName();     CUtil::Split(strArchive, strPath, strFileName);     strLookInPaths.push_back(strPath);+    // TODO: Remove this hack once subs are cached before the stack is split+    if (strPath.Right(5).Left(3).Equals("/CD"))+      strLookInPaths.push_back(strPath.substr(0, strPath.length() -4));   } -  // checking if any of the common subdirs exist ..-  CLog::Log(LOGDEBUG,"%s: Checking for common subirs...", __FUNCTION__);+  // Check for common subtitle locations+  CLog::Log(LOGDEBUG,"%s: Checking for common subtitle locations...", __FUNCTION__);   int iSize = strLookInPaths.size();   for (int i=0;i<iSize;++i)   {-    for (int j=0; common_sub_dirs[j]; j++)+    CFileItemList items;+    CDirectory::GetDirectory(strLookInPaths[i], items);+    for (int j = 0; j < items.Size(); j++)     {-      CStdString strPath2;-      CUtil::AddFileToFolder(strLookInPaths[i],common_sub_dirs[j],strPath2);-      if (CDirectory::Exists(strPath2))-        strLookInPaths.push_back(strPath2);+      CStdString strPath2(items[j]->m_strPath);+      CStdString strFileName2;+      // We want the last token in the path regardless it being file or dir+      CUtil::RemoveSlashAtEnd(strPath2);+      strFileName2 = CUtil::GetFileName(strPath2);+      if (strFileName2.Equals("subs") ||+          (strFileName2.length() == 3 && strFileName.Left(2).Equals("cd")) ||+          strFileName2.Equals("vobsubs") ||+          strFileName2.Equals("subtitles") ||+          strFileName2.Equals("sub") ||+          strFileName2.Equals("subtitle"))+      {+        strLookInPaths.push_back(items[j]->m_strPath);+        iSize++;+      }     }   }   // .. done checking for common subdirs -  // check if there any cd-directories in the paths we have added so far-  char temp[6];-  iSize = strLookInPaths.size();-  for (int i=0;i<9;++i) // 9 cd's-  {-    sprintf(temp,"cd%i",i+1);-    for (int i=0;i<iSize;++i)-    {-      CStdString strPath2;-      CUtil::AddFileToFolder(strLookInPaths[i],temp,strPath2);-      if (CDirectory::Exists(strPath2))-        strLookInPaths.push_back(strPath2);-    }-  }-  // .. done checking for cd-dirs+  // TODO: Remove debug code+  cout << " --- Check paths ---" << endl;+  for (unsigned int i = 0; i < strLookInPaths.size(); i++)+    cout << " " << strLookInPaths[i] << endl;+  cout << " -------------------" << endl; -  // this is last because we dont want to check any common subdirs or cd-dirs in the alternate <subtitles> dir.+  // Tack on the custom path if we deemed it necessary earlier   if (g_stSettings.iAdditionalSubtitleDirectoryChecked == 1)   {     strPath = g_guiSettings.GetString("subtitles.custompath");-    if (!HasSlashAtEnd(strPath))-      strPath += "/"; //Should work for both remote and local files+    CUtil::AddSlashAtEnd(strPath);     strLookInPaths.push_back(strPath);   }    DWORD nextTimer = timeGetTime();-  CLog::Log(LOGDEBUG,"%s: Done (time: %i ms)", __FUNCTION__, (int)(nextTimer - startTimer));+  CLog::Log(LOGDEBUG,"%s: Done checking common subtitle locations. (time: %i ms)", __FUNCTION__, (int)(nextTimer - startTimer));    CStdString strLExt;   CStdString strDest;-  CStdString strItem;+  CStdString strFile;    // 2 steps for movie directory and alternate subtitles directory   CLog::Log(LOGDEBUG,"%s: Searching for subtitles...", __FUNCTION__);   for (unsigned int step = 0; step < strLookInPaths.size(); step++)   {-    if (strLookInPaths[step].length() != 0)-    {-      CFileItemList items;+    cout << strLookInPaths[step] << endl;+    CFileItemList items; -      CDirectory::GetDirectory(strLookInPaths[step], items,".utf|.utf8|.utf-8|.sub|.srt|.smi|.rt|.txt|.ssa|.text|.ssa|.aqt|.jss|.ass|.idx|.ifo|.rar|.zip",false);-      int fnl = strFileNameNoExt.size();+    CDirectory::GetDirectory(strLookInPaths[step], items,".utf|.utf8|.utf-8|.sub|.srt|.smi|.rt|.txt|.ssa|.text|.ssa|.aqt|.jss|.ass|.idx|.ifo|.rar|.zip",false);+    int fnl = strFileNameNoExt.size(); -      CStdString strFileNameNoExtNoCase(strFileNameNoExt);-      strFileNameNoExtNoCase.MakeLower();-      for (int j = 0; j < (int)items.Size(); j++)+    for (int j = 0; j < items.Size(); j++)+    {+      cout << " " << items[j]->m_strPath << endl;+      CStdString strCandidateFileNameNoExt;+      Split(items[j]->m_strPath, strPath, strFile);+      CUtil::ReplaceExtension(strFile, "", strCandidateFileNameNoExt);+      if ((items[j]->IsRAR() || items[j]->IsZIP()) && g_guiSettings.GetBool("subtitles.searchrars"))       {-        Split(items[j]->m_strPath, strPath, strItem);--        // is this a rar-file ..-        if ((CUtil::IsRAR(strItem) || CUtil::IsZIP(strItem)) && g_guiSettings.GetBool("subtitles.searchrars"))+        CacheRarSubtitles( vecExtensionsCached, items[j]->m_strPath, strFileNameNoExt.ToLower());+      }+      else+      {+        //Cache subtitle with same name as movie+        if (strFile.Left(fnl).ToLower() == strFileNameNoExt.ToLower())         {-          CStdString strRar, strItemWithPath;-          CUtil::AddFileToFolder(strLookInPaths[step],strFileNameNoExt+CUtil::GetExtension(strItem),strRar);-          CUtil::AddFileToFolder(strLookInPaths[step],strItem,strItemWithPath);--          unsigned int iPos = strMovie.substr(0,6)=="rar://"?1:0;-          iPos = strMovie.substr(0,6)=="zip://"?1:0;-          if ((step != iPos) || (strFileNameNoExtNoCase+".rar").Equals(strItem) || (strFileNameNoExtNoCase+".zip").Equals(strItem))-            CacheRarSubtitles( vecExtensionsCached, items[j]->m_strPath, strFileNameNoExtNoCase);-        }-        else-        {-          for (int i = 0; sub_exts[i]; i++)+          strLExt = strFile.Right(strFile.size() - fnl);+          strDest.Format("special://temp/subtitle%s", strLExt);+          if (find(vecExtensionsCached.begin(),vecExtensionsCached.end(),strLExt) == vecExtensionsCached.end())           {-            int l = strlen(sub_exts[i]);--            //Cache any alternate subtitles.-            if (strItem.Left(9).ToLower() == "subtitle." && strItem.Right(l).ToLower() == sub_exts[i])+            if (CFile::Cache(items[j]->m_strPath, strDest, pCallback, NULL))             {-              strLExt = strItem.Right(strItem.GetLength() - 9);-              strDest.Format("special://temp/subtitle.alt-%s", strLExt);-              if (CFile::Cache(items[j]->m_strPath, strDest, pCallback, NULL))-              {-                CLog::Log(LOGINFO, " cached subtitle %s->%s\n", strItem.c_str(), strDest.c_str());-                strExtensionCached = strLExt;-              }+              cout << "  " << items[j]->m_strPath << endl;+              vecExtensionsCached.push_back(strLExt);+              CLog::Log(LOGINFO, " cached subtitle %s->%s", strFile.c_str(), strDest.c_str());             }--            //Cache subtitle with same name as movie-            if (strItem.Right(l).ToLower() == sub_exts[i] && strItem.Left(fnl).ToLower() == strFileNameNoExt.ToLower())-            {-              strLExt = strItem.Right(strItem.size() - fnl);-              strDest.Format("special://temp/subtitle%s", strLExt);-              if (find(vecExtensionsCached.begin(),vecExtensionsCached.end(),strLExt) == vecExtensionsCached.end())-              {-                if (CFile::Cache(items[j]->m_strPath, strDest, pCallback, NULL))-                {-                  vecExtensionsCached.push_back(strLExt);-                  CLog::Log(LOGINFO, " cached subtitle %s->%s\n", strItem.c_str(), strDest.c_str());-                }-              }-            }           }         }       }-       g_directoryCache.ClearDirectory(strLookInPaths[step]);     }   }