Quantcast
Channel: [EN] OpenPLi Third-Party Development
Viewing all articles
Browse latest Browse all 1689

servicemp3 and custom User-Agent header

$
0
0

Hi,

 

Currently if we want to set custom User-Agent http header, only possibility to do this is to set these config entries:

config.mediaplayer.useAlternateUserAgent.value = True
config.mediaplayer.alternateUserAgent.value = "CustomUserAgent"

From this commit on https://github.com/OpenPLi/enigma2/commit/17d8930111831bb80775b8184fa23f5634537fe0

It should be possible to set User-Agent header for every service also like this:

SERVICE 4097:0:0:0:0:0:0:0:0:0:http%3a//www.path.mp4#User-Agent=CustomUserAgent:sname

Problem with this solution is that it doesn't work and only header which is sent is alternateUserAgent value if set or default "Enigma2 MediaPlayer":

#SERVICE 4097:0:0:0:0:0:0:0:0:0:http%3a//127.0.0.1%3a7777#Cookie1=test3&User-Agent=CustomUserAgent&Cookie=test4:test_headers

localhost.localdomain - - [03/Dec/2015 21:15:52] "GET / HTTP/1.1" 200 -
ERROR:root:Host: 127.0.0.1:7777
Connection: close
icy-metadata: 1
Cookie1: test3
Cookie: test4
User-Agent: Enigma2 Mediaplayer

Note: very simple http server is running on port 7777 for purpose to see which http headers were sent by gstreamer.

 

We can set User-Agent only by source's "user-agent" property, if we set User-Agent in "extra-headers" it doesn't overwrite already set User-Agent header by "user-agent" property.

Even if we don't use "user-agent" property, gstreamer(souphttpsrc) will still provide it's own.

 

I suggest to set use custom User-Agent only from service reference path string:

diff --git a/lib/service/servicemp3.cpp b/lib/service/servicemp3.cpp
index f6729ab..35d8b0f 100644
--- a/lib/service/servicemp3.cpp
+++ b/lib/service/servicemp3.cpp
@@ -420,6 +420,7 @@ eServiceMP3::eServiceMP3(eServiceReference ref):
        m_use_chapter_entries = false; /* TOC chapter support CVR */
        m_last_seek_pos = 0; /* CVR last seek position */
 #endif
+       m_useragent = "Enigma2 Mediaplayer";
        m_extra_headers = "";
        m_download_buffer_path = "";
        m_prev_decoder_time = -1;
@@ -443,6 +444,17 @@ eServiceMP3::eServiceMP3(eServiceReference ref):
                filename_str = m_ref.path.substr(0, pos);
                filename = filename_str.c_str();
                m_extra_headers = m_ref.path.substr(pos + 1);
+
+               pos = m_extra_headers.find("User-Agent=");
+               if (pos != std::string::npos)
+               {
+                       size_t hpos_start = pos + 11;
+                       size_t hpos_end = m_extra_headers.find('&', hpos_start);
+                       if (hpos_end != std::string::npos)
+                               m_useragent = m_extra_headers.substr(hpos_start, hpos_end - hpos_start);
+                       else
+                               m_useragent = m_extra_headers.substr(hpos_start);
+               }
        }
        else
                filename = m_ref.path.c_str();
@@ -517,12 +529,6 @@ eServiceMP3::eServiceMP3(eServiceReference ref):
                CONNECT(m_streamingsrc_timeout->timeout, eServiceMP3::sourceTimeout);
 
                std::string config_str;
-               if (eConfigManager::getConfigBoolValue("config.mediaplayer.useAlternateUserAgent"))
-               {
-                       m_useragent = eConfigManager::getConfigValue("config.mediaplayer.alternateUserAgent");
-               }
-               if (m_useragent.empty())
-                       m_useragent = "Enigma2 Mediaplayer";
                if ( m_ref.getData(7) & BUFFERING_ENABLED )
                {
                        m_use_prefillbuffer = true;

With following patch is this stream now working:

#SERVICE 4097:0:0:0:0:0:0:0:0:0:http%3a//movietrailers.apple.com/movies/sony_pictures/hoteltransylvania2/hoteltransylvania2-tlr2_h480p.mov?#User-Agent=iTunes:trailer

Viewing all articles
Browse latest Browse all 1689

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>