a/src/ohradio.cxx b/src/ohradio.cxx
...
...
51
static const string sTpProduct("urn:av-openhome-org:service:Radio:1");
51
static const string sTpProduct("urn:av-openhome-org:service:Radio:1");
52
static const string sIdProduct("urn:av-openhome-org:serviceId:Radio");
52
static const string sIdProduct("urn:av-openhome-org:serviceId:Radio");
53
53
54
struct RadioMeta {
54
struct RadioMeta {
55
    RadioMeta(const string& t, const string& u, const string& au,
55
    RadioMeta(const string& t, const string& u, const string& au,
56
              const string& as, const string& ms)
56
              const string& as, const string& ms, const string& ps)
57
        : title(t), uri(u), artUri(au), dynArtUri(au) {
57
        : title(t), uri(u), artUri(au), dynArtUri(au) {
58
        if (!as.empty()) {
58
        if (!as.empty()) {
59
            stringToStrings(as, artScript);
59
            stringToStrings(as, artScript);
60
        }
60
        }
61
        if (!ms.empty()) {
61
        if (!ms.empty()) {
62
            stringToStrings(ms, metaScript);
62
            stringToStrings(ms, metaScript);
63
        }
63
        }
64
        preferScript = stringToBool(ps);
64
    }
65
    }
65
    string title;
66
    string title;
66
    string uri;
67
    string uri;
67
    string artUri;
68
    string artUri;
68
    // Script to retrieve current art
69
    // Script to retrieve current art
69
    vector<string> artScript; 
70
    vector<string> artScript; 
70
    // Script to retrieve all metadata
71
    // Script to retrieve all metadata
71
    vector<string> metaScript; 
72
    vector<string> metaScript;
73
    // Keep values from script over mpd's (from icy)
74
    bool preferScript;
72
    // Time after which we should re-fire the metadata script
75
    // Time after which we should re-fire the metadata script
73
    time_t nextMetaScriptExecTime{0}; 
76
    time_t nextMetaScriptExecTime{0}; 
74
    string dynArtUri;
77
    string dynArtUri;
75
    string dynTitle;
78
    string dynTitle;
76
    string dynArtist;
79
    string dynArtist;
...
...
131
static void getRadiosFromConf(ConfSimple* conf)
134
static void getRadiosFromConf(ConfSimple* conf)
132
{
135
{
133
    vector<string> allsubk = conf->getSubKeys_unsorted();
136
    vector<string> allsubk = conf->getSubKeys_unsorted();
134
    for (auto it = allsubk.begin(); it != allsubk.end(); it++) {
137
    for (auto it = allsubk.begin(); it != allsubk.end(); it++) {
135
        if (it->find("radio ") == 0) {
138
        if (it->find("radio ") == 0) {
136
            string uri, artUri, artScript, metaScript;
139
            string uri, artUri, artScript, metaScript, preferScript;
137
            string title = it->substr(6);
140
            string title = it->substr(6);
138
            bool ok = conf->get("url", uri, *it);
141
            bool ok = conf->get("url", uri, *it);
139
            conf->get("artUrl", artUri, *it);
142
            conf->get("artUrl", artUri, *it);
140
            conf->get("artScript", artScript, *it);
143
            conf->get("artScript", artScript, *it);
141
            trimstring(artScript, " \t\n\r");
144
            trimstring(artScript, " \t\n\r");
142
            conf->get("metaScript", metaScript, *it);
145
            conf->get("metaScript", metaScript, *it);
143
            trimstring(metaScript, " \t\n\r");
146
            trimstring(metaScript, " \t\n\r");
147
            conf->get("preferScript", preferScript, *it);
148
            trimstring(preferScript, " \t\n\r");
144
            if (ok && !uri.empty()) {
149
            if (ok && !uri.empty()) {
145
                o_radios.push_back(RadioMeta(title, uri, artUri, artScript,
150
                o_radios.push_back(RadioMeta(title, uri, artUri, artScript,
146
                                             metaScript));
151
                                             metaScript, preferScript));
147
                LOGDEB0("OHRadio::readRadios:RADIO: [" << title << "] uri ["
152
                LOGDEB0("OHRadio::readRadios:RADIO: [" << title << "] uri ["
148
                        << uri << "] artUri [" << artUri << "]\n");
153
                        << uri << "] artUri [" << artUri << "]\n");
149
            }
154
            }
150
        }
155
        }
151
    }
156
    }
152
}
157
}
153
158
154
bool OHRadio::readRadios()
159
bool OHRadio::readRadios()
155
{
160
{
156
    // Id 0 means no selection
161
    // Id 0 means no selection
157
    o_radios.push_back(RadioMeta("Unknown radio", "", "", "", ""));
162
    o_radios.push_back(RadioMeta("Unknown radio", "", "", "", "", ""));
158
    
163
    
159
    std::unique_lock<std::mutex>(g_configlock);
164
    std::unique_lock<std::mutex>(g_configlock);
160
    getRadiosFromConf(g_config);
165
    getRadiosFromConf(g_config);
161
    // Also if radiolist is defined, get from there
166
    // Also if radiolist is defined, get from there
162
    string radiolistfn;
167
    string radiolistfn;
...
...
223
228
224
        RadioMeta& radio = o_radios[m_id];
229
        RadioMeta& radio = o_radios[m_id];
225
230
226
        // Some radios do not insert icy metadata in the stream, but rather
231
        // Some radios do not insert icy metadata in the stream, but rather
227
        // provide a script to retrieve it.
232
        // provide a script to retrieve it.
228
        if (mpds.currentsong.title.empty() && mpds.currentsong.artist.empty()
233
        bool nompddata = mpds.currentsong.title.empty() &&
229
            && radio.metaScript.size()) {
234
            mpds.currentsong.artist.empty();
235
        if ((radio.preferScript || nompddata) && radio.metaScript.size()) {
230
            if (time(0) > radio.nextMetaScriptExecTime) {
236
            if (time(0) > radio.nextMetaScriptExecTime) {
231
                string data;
237
                string data;
232
                if (ExecCmd::backtick(radio.metaScript, data)) {
238
                if (ExecCmd::backtick(radio.metaScript, data)) {
233
                    LOGDEB0("OHRadio::makestate: metaScript got: [" << data <<
239
                    LOGDEB0("OHRadio::makestate: metaScript got: [" << data <<
234
                            "]\n");
240
                            "]\n");