mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 16:31:11 +02:00
yt: use cached tumbnail, if available
This commit is contained in:
@@ -64,6 +64,17 @@ std::string cYTCache::getName(MI_MOVIE_INFO *mi, std::string ext)
|
|||||||
return g_settings.downloadcache_dir + "/" + mi->ytid + "-" + std::string(ytitag) + "." + ext;
|
return g_settings.downloadcache_dir + "/" + mi->ytid + "-" + std::string(ytitag) + "." + ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cYTCache::getNameIfExists(std::string &fname, const std::string &id, int itag, std::string ext)
|
||||||
|
{
|
||||||
|
char ytitag[10];
|
||||||
|
snprintf(ytitag, sizeof(ytitag), "%d", itag);
|
||||||
|
std::string f = g_settings.downloadcache_dir + "/" + id + "-" + std::string(ytitag) + "." + ext;
|
||||||
|
if (access(f.c_str(), R_OK))
|
||||||
|
return false;
|
||||||
|
fname = f;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool cYTCache::useCachedCopy(MI_MOVIE_INFO *mi)
|
bool cYTCache::useCachedCopy(MI_MOVIE_INFO *mi)
|
||||||
{
|
{
|
||||||
std::string file = getName(mi);
|
std::string file = getName(mi);
|
||||||
@@ -143,8 +154,7 @@ bool cYTCache::download(MI_MOVIE_INFO *mi)
|
|||||||
File.Name = xml;
|
File.Name = xml;
|
||||||
cMovieInfo.saveMovieInfo(*mi, &File);
|
cMovieInfo.saveMovieInfo(*mi, &File);
|
||||||
std::string thumbnail_dst = getName(mi, "jpg");
|
std::string thumbnail_dst = getName(mi, "jpg");
|
||||||
std::string thumbnail_src = "/tmp/ytparser/" + mi->ytid + ".jpg";
|
CFileHelpers::getInstance()->copyFile(mi->tfile.c_str(), thumbnail_dst.c_str(), 0644);
|
||||||
CFileHelpers::getInstance()->copyFile(thumbnail_src.c_str(), thumbnail_dst.c_str(), 0644);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -60,5 +60,6 @@ class cYTCache
|
|||||||
std::vector<MI_MOVIE_INFO> getPending(void);
|
std::vector<MI_MOVIE_INFO> getPending(void);
|
||||||
void clearCompleted(MI_MOVIE_INFO *mi = NULL);
|
void clearCompleted(MI_MOVIE_INFO *mi = NULL);
|
||||||
void clearFailed(MI_MOVIE_INFO *mi = NULL);
|
void clearFailed(MI_MOVIE_INFO *mi = NULL);
|
||||||
|
bool getNameIfExists(std::string &fname, const std::string &id, int itag, std::string ext = ".jpg");
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@@ -34,12 +34,14 @@
|
|||||||
#include "set_threadname.h"
|
#include "set_threadname.h"
|
||||||
|
|
||||||
#include "ytparser.h"
|
#include "ytparser.h"
|
||||||
|
#include "ytcache.h"
|
||||||
|
|
||||||
#if LIBCURL_VERSION_NUM < 0x071507
|
#if LIBCURL_VERSION_NUM < 0x071507
|
||||||
#include <curl/types.h>
|
#include <curl/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define URL_TIMEOUT 60
|
#define URL_TIMEOUT 60
|
||||||
|
static int itags[] = { 37 /* 1080p MP4 */, 22 /* 720p MP4 */, 18 /* 270p/360p MP4 */, 0 };
|
||||||
|
|
||||||
std::string cYTVideoUrl::GetUrl()
|
std::string cYTVideoUrl::GetUrl()
|
||||||
{
|
{
|
||||||
@@ -80,7 +82,6 @@ std::string cYTVideoInfo::GetUrl(int *fmt, bool mandatory)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int itags[] = { 37 /* 1080p MP4*/, 22 /* 720p MP4 */, 18 /* 270p/360p MP4 */, 0 };
|
|
||||||
for (int *fmtp = itags; *fmtp; fmtp++)
|
for (int *fmtp = itags; *fmtp; fmtp++)
|
||||||
if ((it = formats.find(*fmtp)) != formats.end()) {
|
if ((it = formats.find(*fmtp)) != formats.end()) {
|
||||||
*fmt = *fmtp;
|
*fmt = *fmtp;
|
||||||
@@ -395,7 +396,8 @@ bool cYTFeedParser::parseFeedXml(std::string &answer)
|
|||||||
|
|
||||||
bool cYTFeedParser::supportedFormat(int fmt)
|
bool cYTFeedParser::supportedFormat(int fmt)
|
||||||
{
|
{
|
||||||
if((fmt == 37) || (fmt == 22) || (fmt == 18))
|
for (int *fmtp = itags; *fmtp; fmtp++)
|
||||||
|
if (*fmtp == fmt)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -596,6 +598,10 @@ bool cYTFeedParser::DownloadThumbnail(cYTVideoInfo &vinfo, CURL *_curl_handle)
|
|||||||
if (!vinfo.thumbnail.empty()) {
|
if (!vinfo.thumbnail.empty()) {
|
||||||
std::string fname = thumbnail_dir + "/" + vinfo.id + ".jpg";
|
std::string fname = thumbnail_dir + "/" + vinfo.id + ".jpg";
|
||||||
found = !access(fname.c_str(), F_OK);
|
found = !access(fname.c_str(), F_OK);
|
||||||
|
if (!found) {
|
||||||
|
for (int *fmtp = itags; *fmtp && !found; fmtp++)
|
||||||
|
found = cYTCache::getInstance()->getNameIfExists(fname, vinfo.id, *fmtp);
|
||||||
|
}
|
||||||
if (!found)
|
if (!found)
|
||||||
found = DownloadUrl(vinfo.thumbnail, fname, _curl_handle);
|
found = DownloadUrl(vinfo.thumbnail, fname, _curl_handle);
|
||||||
if (found)
|
if (found)
|
||||||
|
Reference in New Issue
Block a user