Merge pull request #112 from mx3L/topic_servicemp3_user_agent
authorlittlesat <littlesat99@yahoo.com>
Fri, 4 Dec 2015 13:25:23 +0000 (14:25 +0100)
committerlittlesat <littlesat99@yahoo.com>
Fri, 4 Dec 2015 13:25:23 +0000 (14:25 +0100)
servicemp3 and custom user agent header

lib/python/Plugins/Extensions/MediaPlayer/settings.py
lib/service/servicemp3.cpp
lib/service/servicemp3record.cpp

index be1f98c..516c9dc 100644 (file)
@@ -12,8 +12,6 @@ config.mediaplayer.repeat = ConfigYesNo(default=False)
 config.mediaplayer.savePlaylistOnExit = ConfigYesNo(default=True)
 config.mediaplayer.saveDirOnExit = ConfigYesNo(default=False)
 config.mediaplayer.defaultDir = ConfigDirectory()
-config.mediaplayer.useAlternateUserAgent = ConfigYesNo(default=False)
-config.mediaplayer.alternateUserAgent = ConfigText(default="")
 config.mediaplayer.sortPlaylists = ConfigYesNo(default=False)
 config.mediaplayer.alwaysHideInfoBar = ConfigYesNo(default=True)
 config.mediaplayer.onMainMenu = ConfigYesNo(default=False)
index 0bdbb62..5000224 100644 (file)
@@ -421,6 +421,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;
@@ -439,11 +440,22 @@ eServiceMP3::eServiceMP3(eServiceReference ref):
        const char *filename;
        std::string filename_str;
        size_t pos = m_ref.path.find('#');
-       if (pos != std::string::npos && m_ref.path.compare(0, 4, "http") == 0)
+       if (pos != std::string::npos && (m_ref.path.compare(0, 4, "http") == 0 || m_ref.path.compare(0, 4, "rtsp") == 0))
        {
                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,13 +529,6 @@ eServiceMP3::eServiceMP3(eServiceReference ref):
                m_streamingsrc_timeout = eTimer::create(eApp);;
                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;
index 1548ed4..3c6d281 100644 (file)
@@ -22,18 +22,11 @@ eServiceMP3Record::eServiceMP3Record(const eServiceReference &ref):
        m_error = 0;
        m_simulate = false;
        m_recording_pipeline = 0;
+       m_useragent = "Enigma2 Mediaplayer";
        m_extra_headers = "";
 
        CONNECT(m_pump.recv_msg, eServiceMP3Record::gstPoll);
        CONNECT(m_streamingsrc_timeout->timeout, eServiceMP3Record::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";
 }
 
 eServiceMP3Record::~eServiceMP3Record()
@@ -138,10 +131,22 @@ int eServiceMP3Record::doPrepare()
                gchar *uri;
                size_t pos = m_ref.path.find('#');
                std::string stream_uri;
-               if (pos != std::string::npos && m_ref.path.compare(0, 4, "http") == 0)
+               if (pos != std::string::npos && (m_ref.path.compare(0, 4, "http") == 0 || m_ref.path.compare(0, 4, "rtsp") == 0))
                {
                        stream_uri = m_ref.path.substr(0, pos);
                        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
                {