diff --git a/data/locale/deutsch.locale b/data/locale/deutsch.locale index 84dd1a9ac..05bc5f84e 100644 --- a/data/locale/deutsch.locale +++ b/data/locale/deutsch.locale @@ -1594,8 +1594,15 @@ moviebrowser.update_if_dest_empty_only Übernehmen nur wenn Ziel leer moviebrowser.use_dir Verzeichnis verwenden moviebrowser.use_movie_dir Wiedergabeverzeichnis verwenden moviebrowser.use_rec_dir Aufnahmeverzeichnis verwenden +moviebrowser.yt_cache Downloads +moviebrowser.yt_cache_add Download von\n%s\nwird eingeplant. +moviebrowser.yt_cancel Alle abbrechen +moviebrowser.yt_cancel_transfer Download abbrechen? +moviebrowser.yt_clear Liste leeren +moviebrowser.yt_completed Vollständige Downloads moviebrowser.yt_concurrent_connections Gleichzeitige Verbindungen -moviebrowser.yt_error Fehler beim laden des Youtube Feed +moviebrowser.yt_error Fehler beim Laden des Youtube-Feeds +moviebrowser.yt_failed Fehlgeschlagene Downloads moviebrowser.yt_history Frühere Suchen moviebrowser.yt_max_history Max. Anzahl früherer Suchen moviebrowser.yt_max_results Max. Anzahl der zu holenden Feeds @@ -1607,6 +1614,11 @@ moviebrowser.yt_orderby.published Veröffentlichungszeitpunkt moviebrowser.yt_orderby.rating Bewertung moviebrowser.yt_orderby.relevance Relevanz moviebrowser.yt_orderby.viewcount Zahl der Views +moviebrowser.yt_pending Anstehende Downloads +moviebrowser.yt_pref_quality Bevorzugte Qualität +moviebrowser.yt_region Region +moviebrowser.yt_related Passende Videos +moviebrowser.yt_search Suche nach Stichwort moviebrowser.yt_pref_quality Bevorzugte Qualität moviebrowser.yt_prev_results Vorherige Ergebnisse moviebrowser.yt_recently_featured Vor kurzem empfohlen diff --git a/data/locale/english.locale b/data/locale/english.locale index 1bbd51d86..afb0234e7 100644 --- a/data/locale/english.locale +++ b/data/locale/english.locale @@ -1594,8 +1594,15 @@ moviebrowser.update_if_dest_empty_only Copy if destination is empty only moviebrowser.use_dir Use directory moviebrowser.use_movie_dir Use movie directory moviebrowser.use_rec_dir Use record directory +moviebrowser.yt_cache Downloads +moviebrowser.yt_cache_add Download of\n%s\nis scheduled. +moviebrowser.yt_cancel Cancel all +moviebrowser.yt_cancel_transfer Cancel download? +moviebrowser.yt_clear Clear +moviebrowser.yt_completed Completed downloads moviebrowser.yt_concurrent_connections Concurrent connections moviebrowser.yt_error Failed to load youtube feed +moviebrowser.yt_failed Failed downloads moviebrowser.yt_history Search history moviebrowser.yt_max_history Max search history size moviebrowser.yt_max_results Max results to fetch @@ -1607,6 +1614,7 @@ moviebrowser.yt_orderby.published publishing date moviebrowser.yt_orderby.rating rating moviebrowser.yt_orderby.relevance relevance moviebrowser.yt_orderby.viewcount view count +moviebrowser.yt_pending Pending downloads moviebrowser.yt_pref_quality Prefered quality moviebrowser.yt_prev_results Previous results moviebrowser.yt_recently_featured Recently featured diff --git a/src/gui/moviebrowser.cpp b/src/gui/moviebrowser.cpp index fb0b955d7..fd60d0e3e 100644 --- a/src/gui/moviebrowser.cpp +++ b/src/gui/moviebrowser.cpp @@ -1100,7 +1100,15 @@ int CMovieBrowser::exec(const char* path) } else if ((show_mode == MB_SHOW_YT) && (msg == CRCInput::RC_record) && m_movieSelectionHandler) { - cYTCache::getInstance()->addToCache(m_movieSelectionHandler); + if (cYTCache::getInstance()->addToCache(m_movieSelectionHandler)) { + const char *format = g_Locale->getText(LOCALE_MOVIEBROWSER_YT_CACHE_ADD); + char buf[1024]; + snprintf(buf, sizeof(buf), format, m_movieSelectionHandler->file.Name.c_str()); + CHintBox hintBox(LOCALE_MOVIEBROWSER_YT_CACHE, buf); + hintBox.paint(); + sleep(1); + hintBox.hide(); + } } else if (msg == CRCInput::RC_home) { @@ -2251,10 +2259,12 @@ void CMovieBrowser::onDeleteFile(MI_MOVIE_INFO& movieSelectionHandler, bool skip { //TRACE( "[onDeleteFile] "); int test= movieSelectionHandler.file.Name.find(".ts", movieSelectionHandler.file.Name.length()-3); + if (test < 0) + test= movieSelectionHandler.file.Name.find(".mp4", movieSelectionHandler.file.Name.length()-4); if(test == -1) { // not a TS file, return!!!!! - TRACE( "show_ts_info: not a TS file "); + TRACE( "show_ts_info: not a TS or MP4 file "); } else { @@ -3750,6 +3760,99 @@ neutrino_locale_t CMovieBrowser::getFeedLocale(void) return ret; } +int CYTCacheSelectorTarget::exec(CMenuTarget* /*parent*/, const std::string & actionKey) +{ + int selected = movieBrowser->yt_menue->getSelected(); + if (actionKey == "cancel_all") { + cYTCache::getInstance()->cancelAll(); + } else if (actionKey == "completed_clear") { + cYTCache::getInstance()->clearCompleted(); + } else if (actionKey == "failed_clear") { + cYTCache::getInstance()->clearFailed(); + } else if (actionKey == "rc_spkr" && selected >= movieBrowser->yt_pending_offset && selected < movieBrowser->yt_completed_offset) { + cYTCache::getInstance()->cancel(&movieBrowser->yt_pending[selected - movieBrowser->yt_pending_offset]); + } else if (actionKey == "rc_spkr" && selected >= movieBrowser->yt_completed_offset && selected < movieBrowser->yt_failed_offset) { + cYTCache::getInstance()->remove(&movieBrowser->yt_completed[selected - movieBrowser->yt_completed_offset]); + } else if (actionKey == "") { + if (selected >= movieBrowser->yt_pending_offset && selected < movieBrowser->yt_completed_offset) { + if(ShowMsg (LOCALE_MOVIEBROWSER_YT_CACHE, g_Locale->getText(LOCALE_MOVIEBROWSER_YT_CANCEL_TRANSFER), CMessageBox::mbrNo, CMessageBox::mbYes | CMessageBox::mbNo) == CMessageBox::mbrYes) + cYTCache::getInstance()->cancel(&movieBrowser->yt_pending[selected - movieBrowser->yt_pending_offset]); + else + return menu_return::RETURN_NONE; + } else if (selected >= movieBrowser->yt_completed_offset && selected < movieBrowser->yt_failed_offset) { + // FIXME -- anything sensible to do here? + return menu_return::RETURN_NONE; + } else if (selected >= movieBrowser->yt_failed_offset && selected < movieBrowser->yt_menue->getItemsCount()){ + cYTCache::getInstance()->clearFailed(&movieBrowser->yt_failed[selected - movieBrowser->yt_failed_offset]); + cYTCache::getInstance()->addToCache(&movieBrowser->yt_failed[selected - movieBrowser->yt_failed_offset]); + const char *format = g_Locale->getText(LOCALE_MOVIEBROWSER_YT_CACHE_ADD); + char buf[1024]; + snprintf(buf, sizeof(buf), format, movieBrowser->yt_failed[selected - movieBrowser->yt_failed_offset].file.Name.c_str()); + CHintBox hintBox(LOCALE_MOVIEBROWSER_YT_CACHE, buf); + hintBox.paint(); + sleep(1); + hintBox.hide(); + } + } else + return menu_return::RETURN_NONE; + + movieBrowser->refreshYTMenu(); + return menu_return::RETURN_REPAINT; +} + +void CMovieBrowser::refreshYTMenu() +{ + for (u_int item_id = (u_int) yt_menue->getItemsCount() - 1; item_id > yt_menue_end - 1; item_id--) { + CMenuItem* m = yt_menue->getItem(item_id); + if (m && !m->isStatic) { + delete m; + yt_menue->removeItem(item_id); + } + } + yt_pending = cYTCache::getInstance()->getPending(); + yt_completed = cYTCache::getInstance()->getCompleted(); + yt_failed = cYTCache::getInstance()->getFailed(); + + yt_pending_offset = 0; + yt_completed_offset = 0; + yt_failed_offset = 0; + + if (!yt_pending.empty()) { + yt_menue->addItem(new CMenuSeparator(CMenuSeparator::LINE | CMenuSeparator::STRING, LOCALE_MOVIEBROWSER_YT_PENDING)); + yt_menue->addItem(new CMenuForwarder(LOCALE_MOVIEBROWSER_YT_CANCEL, true, NULL, ytcache_selector, "cancel_all")); + yt_menue->addItem(GenericMenuSeparator); + int i = 0; + yt_pending_offset = yt_menue->getItemsCount(); + for (std::vector::iterator it = yt_pending.begin(); it != yt_pending.end(); ++it, ++i) { + yt_menue->addItem(new CMenuForwarder((*it).file.Name.c_str(), true, NULL, ytcache_selector)); + } + } + + if (!yt_completed.empty()) { + yt_menue->addItem(new CMenuSeparator(CMenuSeparator::LINE | CMenuSeparator::STRING, LOCALE_MOVIEBROWSER_YT_COMPLETED)); + yt_menue->addItem(new CMenuForwarder(LOCALE_MOVIEBROWSER_YT_CLEAR, true, NULL, ytcache_selector, "completed_clear")); + yt_menue->addItem(GenericMenuSeparator); + int i = 0; + yt_completed_offset = yt_menue->getItemsCount(); + for (std::vector::iterator it = yt_completed.begin(); it != yt_completed.end(); ++it, ++i) { + yt_menue->addItem(new CMenuForwarder((*it).file.Name.c_str(), true, NULL, ytcache_selector)); + } + } + + if (!yt_failed.empty()) { + yt_menue->addItem(new CMenuSeparator(CMenuSeparator::LINE | CMenuSeparator::STRING, LOCALE_MOVIEBROWSER_YT_FAILED)); + yt_menue->addItem(new CMenuForwarder(LOCALE_MOVIEBROWSER_YT_CLEAR, true, NULL, ytcache_selector, "failed_clear")); + yt_menue->addItem(GenericMenuSeparator); + int i = 0; + yt_failed_offset = yt_menue->getItemsCount(); + for (std::vector::iterator it = yt_failed.begin(); it != yt_failed.end(); ++it, ++i) { + yt_menue->addItem(new CMenuForwarder((*it).file.Name.c_str(), true, NULL, ytcache_selector)); + } + } + + CFrameBuffer::getInstance()->Clear(); // due to possible width change +} + class CYTHistory : public CMenuTarget { private: @@ -3869,7 +3972,16 @@ bool CMovieBrowser::showYTMenu() mainMenu.addItem(new CMenuOptionChooser(LOCALE_MOVIEBROWSER_YT_PREF_QUALITY, &m_settings.ytquality, YT_QUALITY_OPTIONS, YT_QUALITY_OPTION_COUNT, true, NULL, CRCInput::RC_nokey, "", true)); mainMenu.addItem(new CMenuOptionNumberChooser(LOCALE_MOVIEBROWSER_YT_CONCURRENT_CONNECTIONS, &m_settings.ytconcconn, true, 1, 8)); + + yt_menue = &mainMenu; + yt_menue_end = yt_menue->getItemsCount(); + CYTCacheSelectorTarget ytcache_sel(this); + ytcache_selector = &ytcache_sel; + yt_menue->addKey(CRCInput::RC_spkr, ytcache_selector, "rc_spkr"); + refreshYTMenu(); + mainMenu.exec(NULL, ""); + ytparser.SetConcurrentDownloads(m_settings.ytconcconn); delete selector; diff --git a/src/gui/moviebrowser.h b/src/gui/moviebrowser.h index 103fc17e2..67e6b1a6a 100644 --- a/src/gui/moviebrowser.h +++ b/src/gui/moviebrowser.h @@ -241,9 +241,22 @@ typedef struct std::list ytsearch_history; } MB_SETTINGS; +class CMovieBrowser; + +class CYTCacheSelectorTarget : public CMenuTarget +{ + private: + class CMovieBrowser *movieBrowser; + public: + CYTCacheSelectorTarget(CMovieBrowser *mb) { movieBrowser = mb; }; + int exec(CMenuTarget* parent, const std::string & actionKey); +}; + // Priorities for Developmemt: P1: critical feature, P2: important feature, P3: for next release, P4: looks nice, lets see class CMovieBrowser : public CMenuTarget { + friend class CYTCacheSelectorTarget; + public: // Variables ///////////////////////////////////////////////// int Multi_Select; // for FileBrowser compatibility, not used in MovieBrowser int Dirs_Selectable; // for FileBrowser compatibility, not used in MovieBrowser @@ -327,8 +340,18 @@ class CMovieBrowser : public CMenuTarget cYTFeedParser ytparser; int show_mode; + CMenuWidget *yt_menue; + CYTCacheSelectorTarget *ytcache_selector; + u_int yt_menue_end; + int yt_pending_offset; + int yt_completed_offset; + int yt_failed_offset; + std::vector yt_pending; + std::vector yt_completed; + std::vector yt_failed; void loadYTitles(int mode, std::string search = "", std::string id = ""); bool showYTMenu(void); + void refreshYTMenu(); public: // Functions //////////////////////////////////////////////////////////7 CMovieBrowser(const char* path); //P1 @@ -369,7 +392,7 @@ class CMovieBrowser : public CMenuTarget ///// MovieBrowser Main Window////////// int paint(void); //P1 void refresh(void); //P1 - void hide(void); //P1 + void hide(void); //P1 void refreshLastPlayList(void); //P2 void refreshLastRecordList(void); //P2 void refreshBrowserList(void); //P1 diff --git a/src/gui/movieinfo.cpp b/src/gui/movieinfo.cpp index c1291722e..b3b94fc96 100644 --- a/src/gui/movieinfo.cpp +++ b/src/gui/movieinfo.cpp @@ -1019,7 +1019,7 @@ bool CMovieInfo::saveFile_vlc(const CFile & /*file*/, const char */*text*/, cons * * */ -#if 0 +#if 1 MI_MOVIE_INFO& MI_MOVIE_INFO::operator=(const MI_MOVIE_INFO& src) { file.Name = src.file.Name; diff --git a/src/gui/movieinfo.h b/src/gui/movieinfo.h index 09be9e80e..d7d36dceb 100644 --- a/src/gui/movieinfo.h +++ b/src/gui/movieinfo.h @@ -146,7 +146,7 @@ typedef struct class MI_MOVIE_INFO { public: -// MI_MOVIE_INFO &operator=(const MI_MOVIE_INFO& src); + MI_MOVIE_INFO &operator=(const MI_MOVIE_INFO& src); CFile file; // not stored in xml std::string productionCountry; // user defined Country (not from EPG yet, but might be possible) std::string epgTitle; // plain movie name, usually filled by EPG diff --git a/src/system/locals.h b/src/system/locals.h index a4358b5fd..6a89f049b 100644 --- a/src/system/locals.h +++ b/src/system/locals.h @@ -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, diff --git a/src/system/locals_intern.h b/src/system/locals_intern.h index 9310a9131..57dfe4819 100644 --- a/src/system/locals_intern.h +++ b/src/system/locals_intern.h @@ -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", diff --git a/src/system/ytcache.cpp b/src/system/ytcache.cpp index de431dfa3..07d36402e 100644 --- a/src/system/ytcache.cpp +++ b/src/system/ytcache.cpp @@ -34,6 +34,7 @@ #include "helpers.h" #include "settings.h" +#include "set_threadname.h" #include 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 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 m_lock(mutex); - pending.push_back(*mi); + { + OpenThreads::ScopedLock 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 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::iterator it = pending.begin(); it != pending.end(); ++it) + if (compareMovieInfo(&(*it), mi)) { + pending.erase(it); + failed.push_back(*mi); + break; + } } - for (std::list::iterator it = pending.begin(); it != pending.end(); ++it) + mutex.unlock(); +} + +void cYTCache::remove(MI_MOVIE_INFO *mi) +{ + OpenThreads::ScopedLock m_lock(mutex); + if (completed.empty()) + return; + + for (std::vector::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 m_lock(mutex); - if (pending.empty()) - return; + { + OpenThreads::ScopedLock 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 m_lock(mutex); + cancelled = false; + pending.clear(); + } } -std::list cYTCache::getFailed(bool clear) +std::vector cYTCache::getFailed(void) { OpenThreads::ScopedLock m_lock(mutex); - std::list res = failed; - if (clear) + std::vector res = failed; + return res; +} + +std::vector cYTCache::getCompleted(void) +{ + OpenThreads::ScopedLock m_lock(mutex); + std::vector res = completed; + return res; +} + +std::vector cYTCache::getPending(void) +{ + OpenThreads::ScopedLock m_lock(mutex); + std::vector res = pending; + return res; +} + +void cYTCache::clearFailed(MI_MOVIE_INFO *mi) +{ + OpenThreads::ScopedLock m_lock(mutex); + if (mi) { + for (std::vector::iterator it = failed.begin(); it != failed.end(); ++it) + if (compareMovieInfo(&(*it), mi)) { + failed.erase(it); + break; + } + } else failed.clear(); - return res; } -std::list cYTCache::getDone(bool clear) +void cYTCache::clearCompleted(MI_MOVIE_INFO *mi) { OpenThreads::ScopedLock m_lock(mutex); - std::list res = done; - if (clear) - done.clear(); - return res; -} - -void cYTCache::clearFailed(void) -{ - OpenThreads::ScopedLock m_lock(mutex); - failed.clear(); -} - -void cYTCache::clearDone(void) -{ - OpenThreads::ScopedLock m_lock(mutex); - done.clear(); + if (mi) { + for (std::vector::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) diff --git a/src/system/ytcache.h b/src/system/ytcache.h index b11e0ac39..5d564b4e7 100644 --- a/src/system/ytcache.h +++ b/src/system/ytcache.h @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include @@ -37,9 +37,9 @@ class cYTCache private: pthread_t thread; bool cancelled; - std::list pending; - std::list done; - std::list failed; + std::vector pending; + std::vector completed; + std::vector 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 getDone(bool clear = false); - std::list getFailed(bool clear = false); - void clearDone(void); - void clearFailed(void); + std::vector getCompleted(void); + std::vector getFailed(void); + std::vector getPending(void); + void clearCompleted(MI_MOVIE_INFO *mi = NULL); + void clearFailed(MI_MOVIE_INFO *mi = NULL); }; #endif diff --git a/src/system/ytparser.cpp b/src/system/ytparser.cpp index 9f4ae2c78..9363a5168 100644 --- a/src/system/ytparser.cpp +++ b/src/system/ytparser.cpp @@ -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(); }