changed: added another GetMimeType for urls and use it in the imagefactory if no...
authorWiSo <wiso@xbmc.org>
Sat, 4 Jan 2014 12:25:47 +0000 (13:25 +0100)
committerwsoltys <wiso@no.way>
Sat, 4 Jan 2014 22:41:03 +0000 (23:41 +0100)
xbmc/FileItem.cpp
xbmc/guilib/TexturePi.cpp
xbmc/guilib/TexturePi.h
xbmc/guilib/imagefactory.cpp
xbmc/utils/Mime.cpp
xbmc/utils/Mime.h

index d983872..4acb1db 100644 (file)
@@ -1377,6 +1377,7 @@ bool CFileItem::IsParentFolder() const
 
 void CFileItem::FillInMimeType(bool lookup /*= true*/)
 {
+  // TODO: adapt this to use CMime::GetMimeType()
   if (m_mimetype.empty())
   {
     if( m_bIsFolder )
index 4e7430c..3950b3f 100644 (file)
@@ -112,7 +112,7 @@ void CPiTexture::Update(unsigned int width, unsigned int height, unsigned int pi
   CGLTexture::Update(width, height, pitch, format, pixels, loadToGPU);
 }
 
-bool CPiTexture::LoadFromFileInternal(const CStdString& texturePath, unsigned int maxWidth, unsigned int maxHeight, bool autoRotate, bool requirePixels)
+bool CPiTexture::LoadFromFileInternal(const CStdString& texturePath, unsigned int maxWidth, unsigned int maxHeight, bool autoRotate, bool requirePixels, const std::string& strMimeType)
 {
   if (URIUtils::HasExtension(texturePath, ".jpg|.tbn"))
   {
index 47095b9..b0fa8e4 100644 (file)
@@ -38,7 +38,7 @@ public:
   void LoadToGPU();
   void Update(unsigned int width, unsigned int height, unsigned int pitch, unsigned int format, const unsigned char *pixels, bool loadToGPU);
   void Allocate(unsigned int width, unsigned int height, unsigned int format);
-  bool LoadFromFileInternal(const CStdString& texturePath, unsigned int maxWidth, unsigned int maxHeight, bool autoRotate, bool requirePixels);
+  bool LoadFromFileInternal(const CStdString& texturePath, unsigned int maxWidth, unsigned int maxHeight, bool autoRotate, bool requirePixels, const std::string& strMimeType = "");
 
 protected:
 
index 827df86..1033a82 100644 (file)
@@ -21,6 +21,7 @@
 #include "imagefactory.h"
 #include "guilib/JpegIO.h"
 #include "guilib/cximage.h"
+#include "utils/Mime.h"
 
 IImage* ImageFactory::CreateLoader(const std::string& strFileName)
 {
@@ -30,7 +31,10 @@ IImage* ImageFactory::CreateLoader(const std::string& strFileName)
 
 IImage* ImageFactory::CreateLoader(const CURL& url)
 {
-  return CreateLoaderFromMimeType("image/"+url.GetFileType());
+  if(!url.GetFileType().empty())
+    return CreateLoaderFromMimeType("image/"+url.GetFileType());
+
+  return CreateLoaderFromMimeType(CMime::GetMimeType(url));
 }
 
 IImage* ImageFactory::CreateLoaderFromMimeType(const std::string& strMimeType)
index a51b445..7a04b20 100644 (file)
@@ -26,6 +26,9 @@
 #include "URIUtils.h"
 #include "music/tags/MusicInfoTag.h"
 #include "video/VideoInfoTag.h"
+#include "URL.h"
+#include "utils/StringUtils.h"
+#include "filesystem/CurlFile.h"
 
 using namespace std;
 
@@ -535,3 +538,41 @@ string CMime::GetMimeType(const CFileItem &item)
 
   return GetMimeType(URIUtils::GetExtension(path));
 }
+
+string CMime::GetMimeType(const CURL &url, bool lookup)
+{
+  
+  std::string strMimeType;
+
+  if( url.GetProtocol() == "shout" || url.GetProtocol() == "http" || url.GetProtocol() == "https")
+  {
+    // If lookup is false, bail out early to leave mime type empty
+    if (!lookup)
+      return strMimeType;
+
+    CStdString strmime;
+    XFILE::CCurlFile::GetMimeType(url, strmime);
+
+    // try to get mime-type again but with an NSPlayer User-Agent
+    // in order for server to provide correct mime-type.  Allows us
+    // to properly detect an MMS stream
+    if (StringUtils::StartsWithNoCase(strmime, "video/x-ms-"))
+      XFILE::CCurlFile::GetMimeType(url, strmime, "NSPlayer/11.00.6001.7000");
+
+    // make sure there are no options set in mime-type
+    // mime-type can look like "video/x-ms-asf ; charset=utf8"
+    size_t i = strmime.find(';');
+    if(i != std::string::npos)
+      strmime.erase(i, strmime.length() - i);
+    StringUtils::Trim(strmime);
+    strMimeType = strmime;
+  }
+  else
+    strMimeType = GetMimeType(url.GetFileType());
+
+  // if it's still empty set to an unknown type
+  if (strMimeType.empty())
+    strMimeType = "application/octet-stream";
+
+  return strMimeType;
+}
index 112ebbc..d42407e 100644 (file)
@@ -22,6 +22,8 @@
 #include <string>
 #include <map>
 
+class CURL;
+
 class CFileItem;
 
 class CMime
@@ -29,6 +31,7 @@ class CMime
 public:
   static std::string GetMimeType(const std::string &extension);
   static std::string GetMimeType(const CFileItem &item);
+  static std::string GetMimeType(const CURL &url, bool lookup = true);
 
 private:
   static std::map<std::string, std::string> m_mimetypes;