mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-09-01 09:51:22 +02:00
add gui support for experimental yt caching code
Conflicts: data/locale/deutsch.locale data/locale/english.locale src/gui/moviebrowser.cpp src/system/locals.h src/system/locals_intern.h
This commit is contained in:
@@ -1621,8 +1621,15 @@ typedef enum
|
||||
LOCALE_MOVIEBROWSER_USE_DIR,
|
||||
LOCALE_MOVIEBROWSER_USE_MOVIE_DIR,
|
||||
LOCALE_MOVIEBROWSER_USE_REC_DIR,
|
||||
LOCALE_MOVIEBROWSER_YT_CACHE,
|
||||
LOCALE_MOVIEBROWSER_YT_CACHE_ADD,
|
||||
LOCALE_MOVIEBROWSER_YT_CANCEL,
|
||||
LOCALE_MOVIEBROWSER_YT_CANCEL_TRANSFER,
|
||||
LOCALE_MOVIEBROWSER_YT_CLEAR,
|
||||
LOCALE_MOVIEBROWSER_YT_COMPLETED,
|
||||
LOCALE_MOVIEBROWSER_YT_CONCURRENT_CONNECTIONS,
|
||||
LOCALE_MOVIEBROWSER_YT_ERROR,
|
||||
LOCALE_MOVIEBROWSER_YT_FAILED,
|
||||
LOCALE_MOVIEBROWSER_YT_HISTORY,
|
||||
LOCALE_MOVIEBROWSER_YT_MAX_HISTORY,
|
||||
LOCALE_MOVIEBROWSER_YT_MAX_RESULTS,
|
||||
@@ -1634,6 +1641,7 @@ typedef enum
|
||||
LOCALE_MOVIEBROWSER_YT_ORDERBY_RATING,
|
||||
LOCALE_MOVIEBROWSER_YT_ORDERBY_RELEVANCE,
|
||||
LOCALE_MOVIEBROWSER_YT_ORDERBY_VIEWCOUNT,
|
||||
LOCALE_MOVIEBROWSER_YT_PENDING,
|
||||
LOCALE_MOVIEBROWSER_YT_PREF_QUALITY,
|
||||
LOCALE_MOVIEBROWSER_YT_PREV_RESULTS,
|
||||
LOCALE_MOVIEBROWSER_YT_RECENTLY_FEATURED,
|
||||
|
@@ -810,10 +810,10 @@ const char * locale_real_names[] =
|
||||
"keybindingmenu.subchanneldown",
|
||||
"keybindingmenu.subchannelup",
|
||||
"keybindingmenu.tvradiomode",
|
||||
"keybindingmenu.video",
|
||||
"keybindingmenu.volume",
|
||||
"keybindingmenu.volumedown",
|
||||
"keybindingmenu.volumeup",
|
||||
"keybindingmenu.video",
|
||||
"keybindingmenu.volume",
|
||||
"keybindingmenu.volumedown",
|
||||
"keybindingmenu.volumeup",
|
||||
"keybindingmenu.zaphistory",
|
||||
"keychooser.head",
|
||||
"keychooser.text1",
|
||||
@@ -1075,8 +1075,8 @@ const char * locale_real_names[] =
|
||||
"menu.hint_key_transponder",
|
||||
"menu.hint_key_tvradiomode",
|
||||
"menu.hint_key_unlock",
|
||||
"menu.hint_key_volumedown",
|
||||
"menu.hint_key_volumeup",
|
||||
"menu.hint_key_volumedown",
|
||||
"menu.hint_key_volumeup",
|
||||
"menu.hint_keys",
|
||||
"menu.hint_lang_pref",
|
||||
"menu.hint_language",
|
||||
@@ -1621,8 +1621,15 @@ const char * locale_real_names[] =
|
||||
"moviebrowser.use_dir",
|
||||
"moviebrowser.use_movie_dir",
|
||||
"moviebrowser.use_rec_dir",
|
||||
"moviebrowser.yt_cache",
|
||||
"moviebrowser.yt_cache_add",
|
||||
"moviebrowser.yt_cancel",
|
||||
"moviebrowser.yt_cancel_transfer",
|
||||
"moviebrowser.yt_clear",
|
||||
"moviebrowser.yt_completed",
|
||||
"moviebrowser.yt_concurrent_connections",
|
||||
"moviebrowser.yt_error",
|
||||
"moviebrowser.yt_failed",
|
||||
"moviebrowser.yt_history",
|
||||
"moviebrowser.yt_max_history",
|
||||
"moviebrowser.yt_max_results",
|
||||
@@ -1634,6 +1641,7 @@ const char * locale_real_names[] =
|
||||
"moviebrowser.yt_orderby.rating",
|
||||
"moviebrowser.yt_orderby.relevance",
|
||||
"moviebrowser.yt_orderby.viewcount",
|
||||
"moviebrowser.yt_pending",
|
||||
"moviebrowser.yt_pref_quality",
|
||||
"moviebrowser.yt_prev_results",
|
||||
"moviebrowser.yt_recently_featured",
|
||||
@@ -1859,11 +1867,11 @@ const char * locale_real_names[] =
|
||||
"pinprotection.wrongcode",
|
||||
"plugins.hdd_dir",
|
||||
"plugins.result",
|
||||
"plugintype.disabled",
|
||||
"plugintype.game",
|
||||
"plugintype.lua",
|
||||
"plugintype.script",
|
||||
"plugintype.tool",
|
||||
"plugintype.disabled",
|
||||
"plugintype.game",
|
||||
"plugintype.lua",
|
||||
"plugintype.script",
|
||||
"plugintype.tool",
|
||||
"rclock.lockmsg",
|
||||
"rclock.menueadd",
|
||||
"rclock.title",
|
||||
@@ -2202,9 +2210,9 @@ const char * locale_real_names[] =
|
||||
"usermenu.item_none",
|
||||
"usermenu.item_plugin_types",
|
||||
"usermenu.item_vtxt",
|
||||
"usermenu.items",
|
||||
"usermenu.key",
|
||||
"usermenu.key_select",
|
||||
"usermenu.items",
|
||||
"usermenu.key",
|
||||
"usermenu.key_select",
|
||||
"usermenu.msg_info_is_empty",
|
||||
"usermenu.msg_warning_name",
|
||||
"usermenu.msg_warning_no_items",
|
||||
|
@@ -34,6 +34,7 @@
|
||||
|
||||
#include "helpers.h"
|
||||
#include "settings.h"
|
||||
#include "set_threadname.h"
|
||||
#include <global.h>
|
||||
|
||||
static cYTCache *instance = NULL;
|
||||
@@ -66,11 +67,14 @@ std::string cYTCache::getName(MI_MOVIE_INFO *mi, std::string ext)
|
||||
bool cYTCache::useCachedCopy(MI_MOVIE_INFO *mi)
|
||||
{
|
||||
std::string file = getName(mi);
|
||||
fprintf(stderr, "checking %s\n", file.c_str());
|
||||
if (access(file.c_str(), R_OK))
|
||||
return false;
|
||||
std::string xml = getName(mi, "xml");
|
||||
fprintf(stderr, "checking %s\n", xml.c_str());
|
||||
if (!access(xml.c_str(), R_OK)) {
|
||||
mi->file.Url = file;
|
||||
fprintf(stderr, "using cached copy: %s\n", file.c_str());
|
||||
return true;
|
||||
}
|
||||
{
|
||||
@@ -99,8 +103,10 @@ bool cYTCache::download(MI_MOVIE_INFO *mi)
|
||||
{
|
||||
std::string file = getName(mi);
|
||||
std::string xml = getName(mi, "xml");
|
||||
if (!access(file.c_str(), R_OK) && !access(file.c_str(), R_OK))
|
||||
if (!access(file.c_str(), R_OK) && !access(xml.c_str(), R_OK)) {
|
||||
fprintf(stderr, "%s: %s already present an valid\n", __func__, file.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
FILE * fp = fopen(file.c_str(), "wb");
|
||||
if (!fp) {
|
||||
@@ -132,7 +138,6 @@ bool cYTCache::download(MI_MOVIE_INFO *mi)
|
||||
fclose(fp);
|
||||
|
||||
if (res) {
|
||||
fprintf(stderr, "curl error: %s\n", cerror);
|
||||
unlink(file.c_str());
|
||||
return false;
|
||||
}
|
||||
@@ -147,6 +152,8 @@ bool cYTCache::download(MI_MOVIE_INFO *mi)
|
||||
}
|
||||
|
||||
void *cYTCache::downloadThread(void *arg) {
|
||||
fprintf(stderr, "%s starting\n", __func__);
|
||||
set_threadname("ytdownload");
|
||||
cYTCache *caller = (cYTCache *)arg;
|
||||
|
||||
while (caller->thread) {
|
||||
@@ -161,32 +168,33 @@ void *cYTCache::downloadThread(void *arg) {
|
||||
mi = caller->pending.front();
|
||||
}
|
||||
|
||||
fprintf(stderr, "download start: %s\n", mi.file.Url.c_str());
|
||||
|
||||
bool res = caller->download(&mi);
|
||||
|
||||
fprintf(stderr, "download end: %s %s\n", mi.file.Url.c_str(), res ? "succeeded" : "failed");
|
||||
caller->cancelled = false;
|
||||
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(caller->mutex);
|
||||
if (res)
|
||||
caller->done.push_front(mi);
|
||||
caller->completed.insert(caller->completed.begin(), mi);
|
||||
else
|
||||
caller->failed.push_front(mi);
|
||||
caller->cancelled = false;
|
||||
caller->failed.insert(caller->failed.begin(), mi);
|
||||
if (caller->pending.empty())
|
||||
caller->thread = 0;
|
||||
else
|
||||
caller->pending.pop_front();
|
||||
caller->pending.erase(caller->pending.begin());
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "%s exiting\n", __func__);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
bool cYTCache::addToCache(MI_MOVIE_INFO *mi)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
|
||||
pending.push_back(*mi);
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
|
||||
pending.push_back(*mi);
|
||||
}
|
||||
|
||||
if (!thread) {
|
||||
if (pthread_create(&thread, NULL, downloadThread, this)) {
|
||||
@@ -200,62 +208,111 @@ bool cYTCache::addToCache(MI_MOVIE_INFO *mi)
|
||||
|
||||
void cYTCache::cancel(MI_MOVIE_INFO *mi)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
|
||||
mutex.lock();
|
||||
if (pending.empty())
|
||||
return;
|
||||
|
||||
if (compareMovieInfo(mi, &pending.front())) {
|
||||
cancelled = true;
|
||||
mutex.unlock();
|
||||
while (cancelled)
|
||||
usleep(100000);
|
||||
return;
|
||||
} else {
|
||||
for (std::vector<MI_MOVIE_INFO>::iterator it = pending.begin(); it != pending.end(); ++it)
|
||||
if (compareMovieInfo(&(*it), mi)) {
|
||||
pending.erase(it);
|
||||
failed.push_back(*mi);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (std::list<MI_MOVIE_INFO>::iterator it = pending.begin(); it != pending.end(); ++it)
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void cYTCache::remove(MI_MOVIE_INFO *mi)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
|
||||
if (completed.empty())
|
||||
return;
|
||||
|
||||
for (std::vector<MI_MOVIE_INFO>::iterator it = completed.begin(); it != completed.end(); ++it)
|
||||
if (compareMovieInfo(&(*it), mi)) {
|
||||
pending.erase(it);
|
||||
completed.erase(it);
|
||||
unlink(getName(mi).c_str());
|
||||
unlink(getName(mi, "xml").c_str());
|
||||
unlink(getName(mi, "jpg").c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void cYTCache::cancelAll(void)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
|
||||
if (pending.empty())
|
||||
return;
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
|
||||
if (pending.empty())
|
||||
return;
|
||||
if (pending.size() > 1) {
|
||||
failed.insert(failed.end(), pending.begin() + 1, pending.end());
|
||||
pending.erase(pending.begin() + 1, pending.end());
|
||||
}
|
||||
}
|
||||
|
||||
cancelled = true;
|
||||
while (thread)
|
||||
usleep(100000);
|
||||
cancelled = false;
|
||||
pending.clear();
|
||||
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
|
||||
cancelled = false;
|
||||
pending.clear();
|
||||
}
|
||||
}
|
||||
|
||||
std::list<MI_MOVIE_INFO> cYTCache::getFailed(bool clear)
|
||||
std::vector<MI_MOVIE_INFO> cYTCache::getFailed(void)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
|
||||
std::list<MI_MOVIE_INFO> res = failed;
|
||||
if (clear)
|
||||
std::vector<MI_MOVIE_INFO> res = failed;
|
||||
return res;
|
||||
}
|
||||
|
||||
std::vector<MI_MOVIE_INFO> cYTCache::getCompleted(void)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
|
||||
std::vector<MI_MOVIE_INFO> res = completed;
|
||||
return res;
|
||||
}
|
||||
|
||||
std::vector<MI_MOVIE_INFO> cYTCache::getPending(void)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
|
||||
std::vector<MI_MOVIE_INFO> res = pending;
|
||||
return res;
|
||||
}
|
||||
|
||||
void cYTCache::clearFailed(MI_MOVIE_INFO *mi)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
|
||||
if (mi) {
|
||||
for (std::vector<MI_MOVIE_INFO>::iterator it = failed.begin(); it != failed.end(); ++it)
|
||||
if (compareMovieInfo(&(*it), mi)) {
|
||||
failed.erase(it);
|
||||
break;
|
||||
}
|
||||
} else
|
||||
failed.clear();
|
||||
return res;
|
||||
}
|
||||
|
||||
std::list<MI_MOVIE_INFO> cYTCache::getDone(bool clear)
|
||||
void cYTCache::clearCompleted(MI_MOVIE_INFO *mi)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
|
||||
std::list<MI_MOVIE_INFO> res = done;
|
||||
if (clear)
|
||||
done.clear();
|
||||
return res;
|
||||
}
|
||||
|
||||
void cYTCache::clearFailed(void)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
|
||||
failed.clear();
|
||||
}
|
||||
|
||||
void cYTCache::clearDone(void)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
|
||||
done.clear();
|
||||
if (mi) {
|
||||
for (std::vector<MI_MOVIE_INFO>::iterator it = completed.begin(); it != completed.end(); ++it)
|
||||
if (compareMovieInfo(&(*it), mi)) {
|
||||
completed.erase(it);
|
||||
break;
|
||||
}
|
||||
} else
|
||||
completed.clear();
|
||||
}
|
||||
|
||||
bool cYTCache::compareMovieInfo(MI_MOVIE_INFO *a, MI_MOVIE_INFO *b)
|
||||
|
@@ -25,7 +25,7 @@
|
||||
|
||||
#include <config.h>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
#include <OpenThreads/Thread>
|
||||
#include <OpenThreads/Condition>
|
||||
@@ -37,9 +37,9 @@ class cYTCache
|
||||
private:
|
||||
pthread_t thread;
|
||||
bool cancelled;
|
||||
std::list<MI_MOVIE_INFO> pending;
|
||||
std::list<MI_MOVIE_INFO> done;
|
||||
std::list<MI_MOVIE_INFO> failed;
|
||||
std::vector<MI_MOVIE_INFO> pending;
|
||||
std::vector<MI_MOVIE_INFO> completed;
|
||||
std::vector<MI_MOVIE_INFO> failed;
|
||||
OpenThreads::Mutex mutex;
|
||||
bool download(MI_MOVIE_INFO *mi);
|
||||
std::string getName(MI_MOVIE_INFO *mi, std::string ext = "mp4");
|
||||
@@ -53,10 +53,12 @@ class cYTCache
|
||||
bool useCachedCopy(MI_MOVIE_INFO *mi);
|
||||
bool addToCache(MI_MOVIE_INFO *mi);
|
||||
void cancel(MI_MOVIE_INFO *mi);
|
||||
void remove(MI_MOVIE_INFO *mi);
|
||||
void cancelAll(void);
|
||||
std::list<MI_MOVIE_INFO> getDone(bool clear = false);
|
||||
std::list<MI_MOVIE_INFO> getFailed(bool clear = false);
|
||||
void clearDone(void);
|
||||
void clearFailed(void);
|
||||
std::vector<MI_MOVIE_INFO> getCompleted(void);
|
||||
std::vector<MI_MOVIE_INFO> getFailed(void);
|
||||
std::vector<MI_MOVIE_INFO> getPending(void);
|
||||
void clearCompleted(MI_MOVIE_INFO *mi = NULL);
|
||||
void clearFailed(MI_MOVIE_INFO *mi = NULL);
|
||||
};
|
||||
#endif
|
||||
|
@@ -70,7 +70,7 @@ std::string cYTVideoInfo::GetUrl(int *fmt, bool mandatory)
|
||||
fmt = &default_fmt;
|
||||
|
||||
yt_urlmap_iterator_t it;
|
||||
if (*fmt) {
|
||||
if (fmt) {
|
||||
if ((it = formats.find(*fmt)) != formats.end()) {
|
||||
return it->second.GetUrl();
|
||||
}
|
||||
|
Reference in New Issue
Block a user