ScraperUrl: use charset reported by http server
authorKarlson2k <k2k@narod.ru>
Mon, 28 Oct 2013 18:35:03 +0000 (22:35 +0400)
committerKarlson2k <k2k@narod.ru>
Tue, 5 Nov 2013 11:54:42 +0000 (15:54 +0400)
xbmc/utils/ScraperUrl.cpp

index 20742bf..5f95039 100644 (file)
@@ -121,7 +121,6 @@ bool CScraperUrl::ParseString(CStdString strUrl)
   if (strUrl.IsEmpty())
     return false;
 
-  // ok, now parse the xml file
   CXBMCTinyXML doc;
   doc.Parse(strUrl, TIXML_ENCODING_UNKNOWN);
 
@@ -209,13 +208,10 @@ bool CScraperUrl::Get(const SUrlEntry& scrURL, std::string& strHTML, XFILE::CCur
     if (XFILE::CFile::Exists(strCachePath))
     {
       XFILE::CFile file;
-      if (file.Open(strCachePath))
+      XFILE::auto_buffer buffer;
+      if (file.LoadFile(strCachePath, buffer))
       {
-        size_t flen = file.GetLength();
-        char* temp = new char[flen];
-        strHTML.assign(temp, file.Read(temp, flen));
-        file.Close();
-        delete[] temp;
+        strHTML.assign(buffer.get(), buffer.length());
         return true;
       }
     }
@@ -237,6 +233,7 @@ bool CScraperUrl::Get(const SUrlEntry& scrURL, std::string& strHTML, XFILE::CCur
       return false;
 
   strHTML = strHTML1;
+  std::string fileCharset(http.GetServerReportedCharset());
 
   if (scrURL.m_url.Find(".zip") > -1 )
   {
@@ -245,11 +242,19 @@ bool CScraperUrl::Get(const SUrlEntry& scrURL, std::string& strHTML, XFILE::CCur
     int iSize = file.UnpackFromMemory(strBuffer,strHTML,scrURL.m_isgz);
     if (iSize)
     {
+      fileCharset.clear();
       strHTML.clear();
       strHTML.append(strBuffer.c_str(),strBuffer.data()+iSize);
     }
   }
 
+  if (!fileCharset.empty() && fileCharset != "UTF-8")
+  {
+    std::string converted;
+    if (g_charsetConverter.ToUtf8(fileCharset, strHTML, converted) && !converted.empty())
+      strHTML = converted;
+  }
+
   if (!scrURL.m_cache.IsEmpty())
   {
     CStdString strCachePath = URIUtils::AddFileToFolder(g_advancedSettings.m_cachePath,