add headers ffmpeg option for luascript bg play; use in script 'entry['header'] = 'Cookie: var=name';

Origin commit data
------------------
Commit: a61b8de691
Author: Jacek Jendrzej <overx300@gmail.com>
Date: 2016-03-25 (Fri, 25 Mar 2016)
This commit is contained in:
Jacek Jendrzej
2016-03-25 17:16:54 +01:00
parent 9403e63831
commit c91dd80565
4 changed files with 36 additions and 11 deletions

View File

@@ -2065,8 +2065,8 @@ bool CStreamRec::Open(CZapitChannel * channel)
if (url.empty()) if (url.empty())
return false; return false;
std::string pretty_name; std::string pretty_name,headers;
if (!CMoviePlayerGui::getInstance(true).getLiveUrl(channel->getChannelID(), channel->getUrl(), channel->getScriptName(), url, pretty_name, recMovieInfo->epgInfo1, recMovieInfo->epgInfo2)) { if (!CMoviePlayerGui::getInstance(true).getLiveUrl(channel->getChannelID(), channel->getUrl(), channel->getScriptName(), url, pretty_name, recMovieInfo->epgInfo1, recMovieInfo->epgInfo2,headers)) {
printf("%s: getLiveUrl() [%s] failed!\n", __FUNCTION__, url.c_str()); printf("%s: getLiveUrl() [%s] failed!\n", __FUNCTION__, url.c_str());
return false; return false;
} }
@@ -2078,6 +2078,8 @@ bool CStreamRec::Open(CZapitChannel * channel)
printf("%s: Open input [%s]....\n", __FUNCTION__, url.c_str()); printf("%s: Open input [%s]....\n", __FUNCTION__, url.c_str());
AVDictionary *options = NULL; AVDictionary *options = NULL;
if (!headers.empty())//add cookies
av_dict_set(&options, "headers", headers.c_str(), 0);
if (avformat_open_input(&ifcx, url.c_str(), NULL, &options) != 0) { if (avformat_open_input(&ifcx, url.c_str(), NULL, &options) != 0) {
printf("%s: Cannot open input [%s]!\n", __FUNCTION__, url.c_str()); printf("%s: Cannot open input [%s]!\n", __FUNCTION__, url.c_str());

View File

@@ -770,8 +770,8 @@ bool CStreamStream::Open()
if (url.empty()) if (url.empty())
return false; return false;
std::string pretty_name, livestreamInfo1, livestreamInfo2; std::string pretty_name, livestreamInfo1, livestreamInfo2, headers;
if (!CMoviePlayerGui::getInstance(true).getLiveUrl(channel->getChannelID(), channel->getUrl(), channel->getScriptName(), url, pretty_name, livestreamInfo1, livestreamInfo2)) { if (!CMoviePlayerGui::getInstance(true).getLiveUrl(channel->getChannelID(), channel->getUrl(), channel->getScriptName(), url, pretty_name, livestreamInfo1, livestreamInfo2,headers)) {
printf("%s: getLiveUrl() [%s] failed!\n", __FUNCTION__, url.c_str()); printf("%s: getLiveUrl() [%s] failed!\n", __FUNCTION__, url.c_str());
return false; return false;
} }
@@ -784,6 +784,8 @@ bool CStreamStream::Open()
printf("%s: Open input [%s]....\n", __FUNCTION__, url.c_str()); printf("%s: Open input [%s]....\n", __FUNCTION__, url.c_str());
AVDictionary *options = NULL; AVDictionary *options = NULL;
if (!headers.empty())
av_dict_set(&options, "headers", headers.c_str(), 0);
if (avformat_open_input(&ifcx, url.c_str(), NULL, &options) != 0) { if (avformat_open_input(&ifcx, url.c_str(), NULL, &options) != 0) {
printf("%s: Cannot open input [%s]!\n", __FUNCTION__, channel->getUrl().c_str()); printf("%s: Cannot open input [%s]!\n", __FUNCTION__, channel->getUrl().c_str());
return false; return false;

View File

@@ -532,6 +532,7 @@ bool CMoviePlayerGui::SelectFile()
info_2 = ""; info_2 = "";
pretty_name.clear(); pretty_name.clear();
file_name.clear(); file_name.clear();
cookie_header.clear();
//reinit Path_local for webif reloadsetup //reinit Path_local for webif reloadsetup
if (g_settings.network_nfs_moviedir.empty()) if (g_settings.network_nfs_moviedir.empty())
Path_local = "/"; Path_local = "/";
@@ -735,7 +736,7 @@ bool CMoviePlayerGui::luaGetUrl(const std::string &script, const std::string &fi
bool haveurl = false; bool haveurl = false;
if ( !root.isObject() ) { if ( !root.isObject() ) {
for (Json::Value::iterator it = root.begin(); it != root.end(); ++it) { for (Json::Value::iterator it = root.begin(); it != root.end(); ++it) {
info.url=""; info.name=""; info.bandwidth = 1; info.resolution=""; info.res1 = 1; info.url=""; info.name=""; info.header=""; info.bandwidth = 1; info.resolution=""; info.res1 = 1;
tmp = "0"; tmp = "0";
Json::Value object_it = *it; Json::Value object_it = *it;
for (Json::Value::iterator iti = object_it.begin(); iti != object_it.end(); iti++) { for (Json::Value::iterator iti = object_it.begin(); iti != object_it.end(); iti++) {
@@ -745,7 +746,11 @@ bool CMoviePlayerGui::luaGetUrl(const std::string &script, const std::string &fi
haveurl = true; haveurl = true;
} else if (name=="name") { } else if (name=="name") {
info.name = (*iti).asString(); info.name = (*iti).asString();
} else if (name=="band") { }
else if (name=="header") {
info.header = (*iti).asString();
}
else if (name=="band") {
info.bandwidth = atoi((*iti).asString().c_str()); info.bandwidth = atoi((*iti).asString().c_str());
} else if (name=="res1") { } else if (name=="res1") {
tmp = (*iti).asString(); tmp = (*iti).asString();
@@ -762,7 +767,7 @@ bool CMoviePlayerGui::luaGetUrl(const std::string &script, const std::string &fi
} }
if (root.isObject()) { if (root.isObject()) {
for (Json::Value::iterator it = root.begin(); it != root.end(); ++it) { for (Json::Value::iterator it = root.begin(); it != root.end(); ++it) {
info.url=""; info.name=""; info.bandwidth = 1; info.resolution=""; info.res1 = 1; info.url=""; info.name=""; info.header=""; info.bandwidth = 1; info.resolution=""; info.res1 = 1;
tmp = "0"; tmp = "0";
std::string name = it.name(); std::string name = it.name();
if (name=="url") { if (name=="url") {
@@ -770,6 +775,8 @@ bool CMoviePlayerGui::luaGetUrl(const std::string &script, const std::string &fi
haveurl = true; haveurl = true;
} else if (name=="name") { } else if (name=="name") {
info.name = (*it).asString(); info.name = (*it).asString();
} else if (name=="header") {
info.header = (*it).asString();
} else if (name=="band") { } else if (name=="band") {
info.bandwidth = atoi((*it).asString().c_str()); info.bandwidth = atoi((*it).asString().c_str());
} else if (name=="res1") { } else if (name=="res1") {
@@ -827,6 +834,7 @@ bool CMoviePlayerGui::selectLivestream(std::vector<livestream_info_t> &streamLis
if (_info->res1 == _res) { if (_info->res1 == _res) {
info->url = _info->url; info->url = _info->url;
info->name = _info->name; info->name = _info->name;
info->header = _info->header;
info->resolution = _info->resolution; info->resolution = _info->resolution;
info->res1 = _info->res1; info->res1 = _info->res1;
info->bandwidth = _info->bandwidth; info->bandwidth = _info->bandwidth;
@@ -856,7 +864,7 @@ bool CMoviePlayerGui::selectLivestream(std::vector<livestream_info_t> &streamLis
return false; 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) 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, std::string &header)
{ {
static t_channel_id oldChan = 0; static t_channel_id oldChan = 0;
static std::vector<livestream_info_t> liveStreamList; static std::vector<livestream_info_t> liveStreamList;
@@ -898,6 +906,10 @@ bool CMoviePlayerGui::getLiveUrl(const t_channel_id chan, const std::string &url
info1 = info.name; info1 = info.name;
_pretty_name = info.name; _pretty_name = info.name;
} }
if (!info.header.empty()) {
header = info.header;
}
#if 0 #if 0
if (!info.resolution.empty()) if (!info.resolution.empty())
info2 = info.resolution; info2 = info.resolution;
@@ -952,7 +964,7 @@ bool CMoviePlayerGui::PlayBackgroundStart(const std::string &file, const std::st
std::string realUrl = file; std::string realUrl = file;
std::string _pretty_name = name; std::string _pretty_name = name;
if (!getLiveUrl(chan, file, script, realUrl, _pretty_name, livestreamInfo1, livestreamInfo2)) { if (!getLiveUrl(chan, file, script, realUrl, _pretty_name, livestreamInfo1, livestreamInfo2, cookie_header)) {
/* FIXME: lua->runScript calling channelRezap, which makes neutrino to loop at start, /* FIXME: lua->runScript calling channelRezap, which makes neutrino to loop at start,
let playback start -> drop messages in ShowStartHint */ let playback start -> drop messages in ShowStartHint */
//return false; //return false;
@@ -969,6 +981,7 @@ bool CMoviePlayerGui::PlayBackgroundStart(const std::string &file, const std::st
instance_bg->isHTTP = true; instance_bg->isHTTP = true;
instance_bg->file_name = realUrl; instance_bg->file_name = realUrl;
instance_bg->pretty_name = _pretty_name; instance_bg->pretty_name = _pretty_name;
instance_bg->cookie_header = cookie_header;
instance_bg->movie_info.epgTitle = name; instance_bg->movie_info.epgTitle = name;
instance_bg->movie_info.epgChannel = realUrl; instance_bg->movie_info.epgChannel = realUrl;
@@ -1070,7 +1083,13 @@ bool CMoviePlayerGui::PlayFileStart(void)
showStartingHint = true; showStartingHint = true;
pthread_create(&thrStartHint, NULL, CMoviePlayerGui::ShowStartHint, this); pthread_create(&thrStartHint, NULL, CMoviePlayerGui::ShowStartHint, this);
} }
bool res = playback->Start((char *) file_name.c_str(), vpid, vtype, currentapid, currentac3, duration); bool res = false;
if(cookie_header.empty()){
res = playback->Start((char *) file_name.c_str(), vpid, vtype, currentapid, currentac3, duration);
}else{
res = playback->Start((char *) file_name.c_str(), cookie_header);//url with cookies
}
if (thrStartHint) { if (thrStartHint) {
showStartingHint = false; showStartingHint = false;
pthread_join(thrStartHint, NULL); pthread_join(thrStartHint, NULL);

View File

@@ -90,6 +90,7 @@ class CMoviePlayerGui : public CMenuTarget
std::string url; std::string url;
std::string name; std::string name;
std::string resolution; std::string resolution;
std::string header;//cookie
int res1; int res1;
int bandwidth; int bandwidth;
} livestream_info_struct_t; } livestream_info_struct_t;
@@ -102,6 +103,7 @@ class CMoviePlayerGui : public CMenuTarget
std::string file_name; std::string file_name;
std::string pretty_name; std::string pretty_name;
std::string cookie_header;
std::string info_1, info_2; std::string info_1, info_2;
std::string currentaudioname; std::string currentaudioname;
bool playing; bool playing;
@@ -261,7 +263,7 @@ class CMoviePlayerGui : public CMenuTarget
bool getBlockedFromPlugin() { return blockedFromPlugin; }; bool getBlockedFromPlugin() { return blockedFromPlugin; };
void setLuaInfoFunc(lua_State* L, bool func) { luaState = L; haveLuaInfoFunc = func; }; void setLuaInfoFunc(lua_State* L, bool func) { luaState = L; haveLuaInfoFunc = func; };
void getLivestreamInfo(std::string *i1, std::string *i2) { *i1=livestreamInfo1; *i2=livestreamInfo2; }; 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); 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, std::string &header);
}; };
#endif #endif