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:
GetAway
2024-04-11 19:07:37 +02:00
committed by vanhofen
parent 87b2a5dbe3
commit be03534b69
2 changed files with 38 additions and 7 deletions

View File

@@ -100,6 +100,26 @@ void cPlayback::Close(void)
} }
} }
std::string cPlayback::extractParam(const std::string &hdrs, const std::string &paramName)
{
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);
} }

View File

@@ -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 &paramName);
public: public:
cPlayback(int num = 0); cPlayback(int num = 0);
~cPlayback(); ~cPlayback();