implement configurable http user-agent (fixes #224)
authorFraxinas <andreas.frisch@multimedia-labs.de>
Tue, 20 Jul 2010 08:06:11 +0000 (10:06 +0200)
committerghost <andreas.monzner@multimedia-labs.de>
Wed, 6 Oct 2010 10:23:23 +0000 (12:23 +0200)
lib/python/Plugins/Extensions/MediaPlayer/settings.py
lib/service/servicemp3.cpp
lib/service/servicemp3.h

index 0b95812..7f42677 100755 (executable)
@@ -12,6 +12,8 @@ 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="")
 
 class DirectoryBrowser(Screen, HelpableScreen):
 
index 154f486..3ab4924 100644 (file)
@@ -287,6 +287,15 @@ eServiceMP3::eServiceMP3(eServiceReference ref)
        if ( sourceinfo.is_streaming )
        {
                uri = g_strdup_printf ("%s", filename);
+
+               std::string config_str;
+               if( ePythonConfigQuery::getConfigValue("config.mediaplayer.useAlternateUserAgent", config_str) == 0 )
+               {
+                       if ( config_str == "True" )
+                               ePythonConfigQuery::getConfigValue("config.mediaplayer.alternateUserAgent", m_useragent);
+               }
+               if ( m_useragent.length() == 0 )
+                       m_useragent = "Dream Multimedia Dreambox Enigma2 Mediaplayer";
        }
        else if ( sourceinfo.containertype == ctCDA )
        {
@@ -347,6 +356,10 @@ eServiceMP3::eServiceMP3(eServiceReference ref)
                        subs.language_code = std::string("und");
                        m_subtitleStreams.push_back(subs);
                }
+               if ( sourceinfo.is_streaming )
+               {
+                       g_signal_connect (G_OBJECT (m_gst_playbin), "notify::source", G_CALLBACK (gstHTTPSourceSetAgent), this);
+               }
        } else
        {
                m_event((iPlayableService*)this, evUser+12);
@@ -1364,6 +1377,15 @@ GstBusSyncReply eServiceMP3::gstBusSyncHandler(GstBus *bus, GstMessage *message,
        return GST_BUS_PASS;
 }
 
+void eServiceMP3::gstHTTPSourceSetAgent(GObject *object, GParamSpec *unused, gpointer user_data)
+{
+       eServiceMP3 *_this = (eServiceMP3*)user_data;
+       GstElement *source;
+       g_object_get(_this->m_gst_playbin, "source", &source, NULL);
+       g_object_set (G_OBJECT (source), "user-agent", _this->m_useragent.c_str(), NULL);
+       gst_object_unref(source);
+}
+
 audiotype_t eServiceMP3::gstCheckAudioPad(GstStructure* structure)
 {
        if (!structure)
index 56a068b..a813957 100644 (file)
@@ -208,6 +208,7 @@ private:
        static void gstCBsubtitleAvail(GstElement *element, gpointer user_data);
        GstPad* gstCreateSubtitleSink(eServiceMP3* _this, subtype_t type);
        void gstPoll(const int&);
+       static void gstHTTPSourceSetAgent(GObject *source, GParamSpec *unused, gpointer user_data);
 
        std::list<ePangoSubtitlePage> m_subtitle_pages;
        ePtr<eTimer> m_subtitle_sync_timer;
@@ -220,6 +221,7 @@ private:
        RESULT seekToImpl(pts_t to);
 
        gint m_aspect, m_width, m_height, m_framerate, m_progressive;
+       std::string m_useragent;
        RESULT trickSeek(gdouble ratio);
 };
 #endif