mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-libstb-hal.git
synced 2025-08-26 23:12:44 +02:00
This commit refactors the extraction of HTTP headers in the
cPlayback::Start method to include the 'Referer' header using
the extractParam helper function. It ensures that the 'Referer'
value from URL parameters is properly extracted and appended to
the headers when present.
Using:
<webtv title=ATV url=https://stream.hdtvizlecanli.com/atv.m3u8#Referer=https://www.livestreamde.com />
Origin commit data
------------------
Branch: master
Commit: 34400d702f
Author: GetAway <get-away@t-online.de>
Date: 2024-04-11 (Thu, 11 Apr 2024)
------------------
This commit was generated by Migit
This commit is contained in:
@@ -100,6 +100,26 @@ void cPlayback::Close(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string cPlayback::extractParam(const std::string &hdrs, const std::string ¶mName)
|
||||||
|
{
|
||||||
|
size_t paramPos = hdrs.find(paramName);
|
||||||
|
if (paramPos != std::string::npos) {
|
||||||
|
size_t valuePos = paramPos + paramName.length();
|
||||||
|
size_t valueEndPos = hdrs.find('&', valuePos);
|
||||||
|
if (valueEndPos == std::string::npos) {
|
||||||
|
valueEndPos = hdrs.length();
|
||||||
|
}
|
||||||
|
std::string value = hdrs.substr(valuePos, valueEndPos - valuePos);
|
||||||
|
|
||||||
|
size_t trailingSpacePos = value.find_last_not_of(" \t\r\n");
|
||||||
|
if (trailingSpacePos != std::string::npos) {
|
||||||
|
value.erase(trailingSpacePos + 1);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
bool cPlayback::Start(std::string filename, std::string headers, std::string filename2)
|
bool cPlayback::Start(std::string filename, std::string headers, std::string filename2)
|
||||||
{
|
{
|
||||||
return Start((char *) filename.c_str(), 0, 0, 0, 0, 0, headers, filename2);
|
return Start((char *) filename.c_str(), 0, 0, 0, 0, 0, headers, filename2);
|
||||||
@@ -142,17 +162,27 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, in
|
|||||||
|
|
||||||
if (isHTTP && headers.empty())
|
if (isHTTP && headers.empty())
|
||||||
{
|
{
|
||||||
size_t pos = file.find('#');
|
size_t pos = file.rfind('#');
|
||||||
if (pos != std::string::npos)
|
if (pos != std::string::npos) {
|
||||||
{
|
std::string val;
|
||||||
headers = file.substr(pos + 1);
|
std::string hdrs = file.substr(pos + 1);
|
||||||
pos = headers.find("User-Agent=");
|
|
||||||
if (pos != std::string::npos)
|
val = extractParam(hdrs, "User-Agent=");
|
||||||
headers.replace(pos + 10, 1, ": ");
|
if (!val.empty()) {
|
||||||
|
headers += "User-Agent: " + val + "\n";
|
||||||
|
}
|
||||||
|
val = extractParam(hdrs, "Referer=");
|
||||||
|
if (!val.empty()) {
|
||||||
|
headers += "Referer: " + val + "\n";
|
||||||
|
}
|
||||||
|
if (!headers.empty()) {
|
||||||
|
file = file.substr(0, pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!headers.empty())
|
if (!headers.empty())
|
||||||
{
|
{
|
||||||
|
printf("Headers List\n%s", headers.c_str());
|
||||||
const char hkey[] = "headers";
|
const char hkey[] = "headers";
|
||||||
ffmpeg_av_dict_set(hkey, headers.c_str(), 0);
|
ffmpeg_av_dict_set(hkey, headers.c_str(), 0);
|
||||||
}
|
}
|
||||||
|
@@ -36,6 +36,7 @@ class cPlayback
|
|||||||
off64_t last_size;
|
off64_t last_size;
|
||||||
int init_jump;
|
int init_jump;
|
||||||
AVFormatContext *avft;
|
AVFormatContext *avft;
|
||||||
|
std::string extractParam(const std::string &hdrs, const std::string ¶mName);
|
||||||
public:
|
public:
|
||||||
cPlayback(int num = 0);
|
cPlayback(int num = 0);
|
||||||
~cPlayback();
|
~cPlayback();
|
||||||
|
Reference in New Issue
Block a user