void CFileItem::FillInMimeType(bool lookup /*= true*/)
{
+ // TODO: adapt this to use CMime::GetMimeType()
if (m_mimetype.empty())
{
if( m_bIsFolder )
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"))
{
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:
#include "imagefactory.h"
#include "guilib/JpegIO.h"
#include "guilib/cximage.h"
+#include "utils/Mime.h"
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)
#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;
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;
+}
#include <string>
#include <map>
+class CURL;
+
class CFileItem;
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;