[FileInfo/Thumbs] Add language retrival from external subs while extracting thumbs.
authorace20022 <ace20022@ymail.com>
Fri, 18 Jan 2013 20:14:25 +0000 (21:14 +0100)
committerace20022 <ace20022@ymail.com>
Tue, 1 Oct 2013 21:46:25 +0000 (23:46 +0200)
xbmc/cores/dvdplayer/DVDFileInfo.cpp
xbmc/cores/dvdplayer/DVDFileInfo.h

index 827c9ed..331872d 100644 (file)
 #include "DVDCodecs/DVDFactoryCodec.h"
 #include "DVDCodecs/Video/DVDVideoCodec.h"
 #include "DVDCodecs/Video/DVDVideoCodecFFmpeg.h"
+#include "DVDDemuxers/DVDDemuxVobsub.h"
 
 #include "DllAvCodec.h"
 #include "DllSwScale.h"
 #include "filesystem/File.h"
 #include "TextureCache.h"
+#include "Util.h"
+#include "utils/LangCodeExpander.h"
 
 
 bool CDVDFileInfo::GetFileDuration(const CStdString &path, int& duration)
@@ -136,8 +139,38 @@ bool CDVDFileInfo::ExtractThumb(const CStdString &strPath, CTextureDetails &deta
   }
 
   if (pStreamDetails)
+  {
     DemuxerToStreamDetails(pInputStream, pDemuxer, *pStreamDetails, strPath);
 
+    //extern subtitles
+    std::vector<CStdString> filenames;
+    CStdString video_path;
+    if (strPath.empty())
+      video_path = pInputStream->GetFileName();
+    else
+      video_path = strPath;
+
+    CUtil::ScanForExternalSubtitles(video_path, filenames);
+
+    for(unsigned int i=0;i<filenames.size();i++)
+    {
+      // if vobsub subtitle:
+      if (URIUtils::GetExtension(filenames[i]) == ".idx")
+      {
+        CStdString strSubFile;
+        if ( CUtil::FindVobSubPair(filenames, filenames[i], strSubFile) )
+          AddExternalSubtitleToDetails(video_path, *pStreamDetails, filenames[i], strSubFile);
+      }
+      else
+      {
+        if ( !CUtil::IsVobSub(filenames, filenames[i]) )
+        {
+          AddExternalSubtitleToDetails(video_path, *pStreamDetails, filenames[i]);
+        }
+      }
+    }
+  }
+
   int nVideoStream = -1;
   for (int i = 0; i < pDemuxer->GetNrOfStreams(); i++)
   {
@@ -403,3 +436,51 @@ bool CDVDFileInfo::DemuxerToStreamDetails(CDVDInputStream *pInputStream, CDVDDem
   return retVal;
 }
 
+bool CDVDFileInfo::AddExternalSubtitleToDetails(const CStdString &path, CStreamDetails &details, const std::string& filename, const std::string& subfilename)
+{
+  std::string ext = URIUtils::GetExtension(filename);
+  std::string vobsubfile = subfilename;
+  if(ext == ".idx")
+  {
+    if (vobsubfile.empty())
+      vobsubfile = URIUtils::ReplaceExtension(filename, ".sub");
+
+    CDVDDemuxVobsub v;
+    if(!v.Open(filename, vobsubfile))
+      return false;
+
+    int count = v.GetNrOfStreams();
+
+    for(int i = 0; i < count; i++)
+    {
+      CStreamDetailSubtitle *dsub = new CStreamDetailSubtitle();
+      CDemuxStream* stream = v.GetStream(i);
+      std::string lang = stream->language;
+      if (lang.length() == 2)
+      {
+        CStdString lang3;
+        g_LangCodeExpander.ConvertToThreeCharCode(lang3, lang);
+        dsub->m_strLanguage = lang3;
+      }
+      else
+        dsub->m_strLanguage = lang;
+
+      return true;
+    }
+  }
+  if(ext == ".sub")
+  {
+    CStdString strReplace(URIUtils::ReplaceExtension(filename,".idx"));
+    if (XFILE::CFile::Exists(strReplace))
+      return false;
+  }
+
+  CStreamDetailSubtitle *dsub = new CStreamDetailSubtitle();
+  ExternalStreamInfo info;
+  CUtil::GetExternalStreamDetailsFromFilename(path, filename, info);
+  dsub->m_strLanguage = info.language;
+  details.AddStream(dsub);
+
+  return true;
+}
+
index 1bb2030..b3a6065 100644 (file)
@@ -39,4 +39,9 @@ public:
   static bool DemuxerToStreamDetails(CDVDInputStream* pInputStream, CDVDDemux *pDemux, CStreamDetails &details, const CStdString &path = "");
 
   static bool GetFileDuration(const CStdString &path, int &duration);
+
+  /** \brief Probe the streams of an external subtitle file and store the info in the StreamDetails parameter.
+  *   \param[out] details The external subtitle file's StreamDetails.
+  */
+  static bool AddExternalSubtitleToDetails(const CStdString &path, CStreamDetails &details, const std::string& filename, const std::string& subfilename = "");
 };