summaryrefslogtreecommitdiff
path: root/pictureCache.cpp
diff options
context:
space:
mode:
authorchriszero <zerov83@gmail.com>2015-06-07 13:41:22 +0200
committerchriszero <zerov83@gmail.com>2015-06-07 13:41:22 +0200
commit9add990765da65421b24d46123657408453bec36 (patch)
treec2346566e5c9864d263b3bb411ac8f734dc6fe62 /pictureCache.cpp
parent6cf8e6e3f5f442818063d8507b458da4f9e1700d (diff)
downloadvdr-plugin-plex-9add990765da65421b24d46123657408453bec36.tar.gz
vdr-plugin-plex-9add990765da65421b24d46123657408453bec36.tar.bz2
More optimizing picture cache
Diffstat (limited to 'pictureCache.cpp')
-rw-r--r--pictureCache.cpp36
1 files changed, 24 insertions, 12 deletions
diff --git a/pictureCache.cpp b/pictureCache.cpp
index 3473264..299bd8e 100644
--- a/pictureCache.cpp
+++ b/pictureCache.cpp
@@ -37,12 +37,14 @@ void cPictureCache::Action()
std::string transcodeUri = TranscodeUri(info.uri, info.width, info.height);
std::string file = FileName(info.uri, info.width);
+ bool ok = true;
if(!Cached(info.uri, info.width)) {
- if(DownloadFileAndSave(transcodeUri, file)) {
- LOCK_THREAD;
- if (!m_bAllInvalidated && info.onCached && info.calle && info.calle->IsVisible()) {
- info.onCached(info.calle);
- }
+ ok = DownloadFileAndSave(transcodeUri, file);
+ }
+ if(ok) {
+ LOCK_THREAD;
+ if (!m_bAllInvalidated && info.onCached && info.calle && info.calle->IsVisible()) {
+ info.onCached(info.calle);
}
}
cCondWait::SleepMs(5);
@@ -67,14 +69,24 @@ bool cPictureCache::DownloadFileAndSave(std::string Uri, std::string localFile)
std::string type = response.getContentType();
std::string fileName = localFile;
-
- if(type == "image/png" || fileUri.getPathAndQuery().find(".png") != std::string::npos) {
- fileName += ".png";
+
+ // check filetype
+ char buffer[2];
+ rs.read(buffer, 2);
+ bool isPng = false;
+
+ if(buffer[0] == char(0x89) && buffer[1] == char(0x50) ) {
+ isPng = true;
}
- else if(type == "image/jpeg" || fileUri.getPathAndQuery().find(".jpg") != std::string::npos) {
+ rs.putback(buffer[1]);
+ rs.putback(buffer[0]);
+
+ if(isPng) {
+ fileName += ".png";
+ } else if(type == "image/jpeg" || fileUri.getPathAndQuery().find(".jpg") != std::string::npos) {
fileName += ".jpg";
}
-
+
Poco::Path p(fileName);
Poco::File f(p.makeParent().toString());
f.createDirectories();
@@ -113,7 +125,7 @@ std::string cPictureCache::TranscodeUri(std::string uri, int width, int height)
host = plServer->GetIpAdress();
port = plServer->GetPort();
}
-
+
std::string tUri = Poco::format("http://%s:%d/photo/:/transcode?width=%d&height=%d&url=%s", host, port, width, height, escapedUri);
return tUri;
}
@@ -134,7 +146,7 @@ std::string cPictureCache::GetPath(std::string uri, int width, int height, bool&
} else if(Poco::File(FileName(uri, width) + ".png").exists()) {
file += ".png";
}
- std::cout << "Cached file: " << file << std::endl;
+
return file;
} else {
CacheInfo info(uri, width, height, OnCached, calle);