From 612164bb7ffeb5cdbc58720a6833dfdf929bd697 Mon Sep 17 00:00:00 2001 From: vanhofen Date: Thu, 27 Sep 2018 22:58:53 +0200 Subject: [PATCH] movieplayer: more readability in code to search for livestream script Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/98557481976120460a8a480d7cc026423a834ee5 Author: vanhofen Date: 2018-09-27 (Thu, 27 Sep 2018) Origin message was: ------------------ - movieplayer: more readability in code to search for livestream script ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- src/gui/movieplayer.cpp | 42 ++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/src/gui/movieplayer.cpp b/src/gui/movieplayer.cpp index 008be3538..5d566d4fe 100644 --- a/src/gui/movieplayer.cpp +++ b/src/gui/movieplayer.cpp @@ -1113,22 +1113,42 @@ bool CMoviePlayerGui::getLiveUrl(const std::string &url, const std::string &scri if (_script.find("/") == std::string::npos) { - bool webradio = (m_ThisMode == NeutrinoModes::mode_webradio); - - std::string _s = g_settings.livestreamScriptPath + "/" + _script; - printf("[%s:%s:%d] script: %s\n", __file__, __func__, __LINE__, _s.c_str()); + std::list paths; + // try livestreamScript from user's livestreamScriptPath + paths.push_back(g_settings.livestreamScriptPath); // try livestreamScripts from webradio/webtv autoload directories - if (!file_exists(_s.c_str())) + if (m_ThisMode == NeutrinoModes::mode_webradio) { - _s = std::string(webradio ? WEBRADIODIR_VAR : WEBTVDIR_VAR) + "/" + _script; - printf("[%s:%s:%d] script: %s\n", __file__, __func__, __LINE__, _s.c_str()); + paths.push_back(WEBRADIODIR_VAR); + paths.push_back(WEBRADIODIR); } - if (!file_exists(_s.c_str())) + else { - _s = std::string(webradio ? WEBRADIODIR : WEBTVDIR) + "/" + _script; - printf("[%s:%s:%d] script: %s\n", __file__, __func__, __LINE__, _s.c_str()); + paths.push_back(WEBTVDIR_VAR); + paths.push_back(WEBTVDIR); + } + + std::string _s; + _s.clear(); + + for (std::list::iterator it = paths.begin(); it != paths.end(); ++it) + { + _s = *it + "/" + _script; + if (file_exists(_s.c_str())) + break; + _s.clear(); + } + + if (!_s.empty()) + { + _script = _s; + printf("[%s:%s:%d] script: %s\n", __file__, __func__, __LINE__, _script.c_str()); + } + else + { + printf(">>>>> [%s:%s:%d] script not found: %s\n", __file__, __func__, __LINE__, _script.c_str()); + return false; } - _script = _s; } size_t pos = _script.find(".lua"); if (!file_exists(_script.c_str()) || (pos == std::string::npos) || (_script.length()-pos != 4)) {