From 54d26aed1c7bf0bb234b3a6960a5e7deed928160 Mon Sep 17 00:00:00 2001 From: "[CST] Focus" Date: Fri, 4 Mar 2016 13:03:32 +0300 Subject: [PATCH] gui/movieplayer.cpp: split live url via lua code to be used from other code --- src/gui/movieplayer.cpp | 121 +++++++++++++++++++++------------------- src/gui/movieplayer.h | 3 +- 2 files changed, 66 insertions(+), 58 deletions(-) diff --git a/src/gui/movieplayer.cpp b/src/gui/movieplayer.cpp index da809484a..11e8a8e19 100644 --- a/src/gui/movieplayer.cpp +++ b/src/gui/movieplayer.cpp @@ -202,9 +202,6 @@ void CMoviePlayerGui::Init(void) blockedFromPlugin = false; m_screensaver = false; m_idletime = time(NULL); - liveStreamList.clear(); - livestreamInfo1.clear(); - livestreamInfo2.clear(); } void CMoviePlayerGui::cutNeutrino() @@ -856,6 +853,68 @@ bool CMoviePlayerGui::selectLivestream(std::vector &streamLis return false; } +bool CMoviePlayerGui::getLiveUrl(const t_channel_id chan, const std::string &url, const std::string &script, std::string &realUrl, std::string &_pretty_name, std::string &info1, std::string &info2) +{ + static t_channel_id oldChan = 0; + static std::vector liveStreamList; + livestream_info_t info; + + if (script.empty()) { + realUrl = url; + return true; + } + std::string _script = script; + + if (_script.find("/") == std::string::npos) + _script = g_settings.livestreamScriptPath + "/" + _script; + + size_t pos = _script.find(".lua"); + if (!file_exists(_script.c_str()) || (pos == std::string::npos) || (_script.length()-pos != 4)) { + liveStreamList.clear(); + printf(">>>>> [%s:%s:%d] script error\n", __file__, __func__, __LINE__); + return false; + } + if ((oldChan != chan) || liveStreamList.empty()) { + liveStreamList.clear(); + if (!luaGetUrl(_script, url, liveStreamList)) { + liveStreamList.clear(); + printf(">>>>> [%s:%s:%d] lua script error\n", __file__, __func__, __LINE__); + return false; + } + oldChan = chan; + } + + if (!selectLivestream(liveStreamList, g_settings.livestreamResolution, &info)) { + liveStreamList.clear(); + printf(">>>>> [%s:%s:%d] error selectLivestream\n", __file__, __func__, __LINE__); + return false; + } + + realUrl = info.url; + if (!info.name.empty()) { + info1 = info.name; + _pretty_name = info.name; + } +#if 0 + if (!info.resolution.empty()) + info2 = info.resolution; + if (info.bandwidth > 0) { + char buf[32]; + memset(buf, '\0', sizeof(buf)); + snprintf(buf, sizeof(buf), "%.02f kbps", (float)((float)info.bandwidth/(float)1000)); + info2 += (std::string)", " + (std::string)buf; + } +#else + if (info.bandwidth > 0) { + char buf[32]; + memset(buf, '\0', sizeof(buf)); + snprintf(buf, sizeof(buf), "%.02f kbps", (float)((float)info.bandwidth/(float)1000)); + info2 = (std::string)buf; + } +#endif + return true; +} + bool CMoviePlayerGui::PlayBackgroundStart(const std::string &file, const std::string &name, t_channel_id chan, const std::string &script) { printf("%s: starting...\n", __func__); @@ -888,62 +947,10 @@ bool CMoviePlayerGui::PlayBackgroundStart(const std::string &file, const std::st } } - static t_channel_id oldChan = 0; std::string realUrl = file; - std::string _script = script; std::string _pretty_name = name; - livestream_info_t info; - if (!_script.empty()) { - if (_script.find("/") == std::string::npos) - _script = g_settings.livestreamScriptPath + "/" + _script; - - size_t pos = _script.find(".lua"); - if ((file_exists(_script.c_str())) && (pos != std::string::npos) && (_script.length()-pos == 4)) { - if ((oldChan != chan) || liveStreamList.empty()) { - liveStreamList.clear(); - if (!luaGetUrl(_script, file, liveStreamList)) { - liveStreamList.clear(); - printf(">>>>> [%s:%s:%d] lua script error\n", __file__, __func__, __LINE__); - return false; - } - oldChan = chan; - } - - if (!selectLivestream(liveStreamList, g_settings.livestreamResolution, &info)) { - liveStreamList.clear(); - printf(">>>>> [%s:%s:%d] error selectLivestream\n", __file__, __func__, __LINE__); - return false; - } - - realUrl = info.url; - if (!info.name.empty()) { - livestreamInfo1 = info.name; - _pretty_name = info.name; - } -#if 0 - if (!info.resolution.empty()) - livestreamInfo2 = info.resolution; - if (info.bandwidth > 0) { - char buf[32]; - memset(buf, '\0', sizeof(buf)); - snprintf(buf, sizeof(buf), "%.02f kbps", (float)((float)info.bandwidth/(float)1000)); - livestreamInfo2 += (std::string)", " + (std::string)buf; - } -#else - if (info.bandwidth > 0) { - char buf[32]; - memset(buf, '\0', sizeof(buf)); - snprintf(buf, sizeof(buf), "%.02f kbps", (float)((float)info.bandwidth/(float)1000)); - livestreamInfo2 = (std::string)buf; - } -#endif - } - else { - liveStreamList.clear(); - printf(">>>>> [%s:%s:%d] script error\n", __file__, __func__, __LINE__); - return false; - } - } + if (!getLiveUrl(chan, file, script, realUrl, _pretty_name, livestreamInfo1, livestreamInfo2)) + return false; OpenThreads::ScopedLock m_lock(mutex); diff --git a/src/gui/movieplayer.h b/src/gui/movieplayer.h index 1c9d55f2a..5219d84c2 100644 --- a/src/gui/movieplayer.h +++ b/src/gui/movieplayer.h @@ -171,7 +171,7 @@ class CMoviePlayerGui : public CMenuTarget std::string Path_local; int menu_ret; bool autoshot_done; - std::vector liveStreamList; + //std::vector liveStreamList; /* playback from bookmark */ static CBookmarkManager * bookmarkmanager; @@ -261,6 +261,7 @@ class CMoviePlayerGui : public CMenuTarget bool getBlockedFromPlugin() { return blockedFromPlugin; }; void setLuaInfoFunc(lua_State* L, bool func) { luaState = L; haveLuaInfoFunc = func; }; void getLivestreamInfo(std::string *i1, std::string *i2) { *i1=livestreamInfo1; *i2=livestreamInfo2; }; + bool getLiveUrl(const t_channel_id chan, const std::string &url, const std::string &script, std::string &realUrl, std::string &_pretty_name, std::string &info1, std::string &info2); }; #endif