Problem with a script

Hello community,

I have a script to select the stream URL for a radio station. It looks like this:

alias: GegevensBron
sequence:
  - variables:
      Zenders:
        Freq: |
          {% macro Welke_Zender() %}   
            {% if Zender|lower == "qmusic belgië" %}                      
                        https://icecast-qmusicbe-cdp.triple-it.nl/qmusic.mp3
                  {% elif Zender|lower == "q-foute radio" %}
                        https://icecast-qmusicbe-cdp.triple-it.nl/q-foute-radio.mp3   
                  {% elif Zender|lower == "q-allstars" %}
                        https://icecast-qmusicbe-cdp.triple-it.nl/q-allstars.mp3
                  {% elif Zender|lower == "vrt radio 1" %}
                        aac://http://vrt.streamabc.net/vrt-radio1-aac-128-4855518?sABC=69495251%230%23o205ppp0qp820196nn59n2350nonrsq0%23gharva&aw_0_1st.playerid=tunein&amsparams=playerid:tunein;skey:1766412881
                  {% elif Zender|lower == "vrt radio 2 limburg" %}                      
                        http://icecast.vrtcdn.be/ra2lim-high.mp3    
                  {% elif Zender|lower == "joe gold" %}       
                        aac://https://icecast-qmusicbe-cdp.triple-it.nl/joe-gold.aac?dist=tunein&gdpr=1&gdpr_consent=&pname=redirect-service 
                  {% elif Zender|lower == "joe easy" %}       
                        https://streams.radio.dpgmedia.cloud/redirect/joe_easy/mp3
                  {% elif Zender|lower == "joe 80s & 90s" %}
                        https://icecast-qmusicbe-cdp.triple-it.nl/joe_80s_90s.mp3      
                  {% elif Zender|lower == "joe - top 2000" %}       
                        https://streams.radio.dpgmedia.cloud/redirect/top2000/mp3   
                  {% elif Zender|lower == "joe easy" %}       
                        https://streams.radio.dpgmedia.cloud/redirect/joe_easy/mp3   
                  {% elif Zender|lower == "joe easy" %}       
                        https://streams.radio.dpgmedia.cloud/redirect/joe_easy/mp3         
                        JOE - Top 2000
                  {% endif %}
                  
  


             
          {% endmacro %}
          {# a macro that removes all newline characters, empty spaces, and
          returns formatted text. Also replaces all Underscores with Spaces  #}

          {%- macro cleanup(data) -%}
            {%- for item in data.split("\n")  if item | trim != "" -%}
              {{ item | trim | replace("_", " ") }} {% endfor -%}
          {%- endmacro -%}

          {# ******************************** #}

          {#  ******** Start the Speech routines ********  #}

          {# ********************************************* #}

          {# a macro to call all macros :)  #}

          {%- macro mother_of_all_macros() -%}


            {% if call_Zender == 1 %}
              {{ Welke_Zender() }}
            {% endif %}

           


            

          {%- endmacro -%}


          {{- cleanup(mother_of_all_macros()) -}}      
  - stop: Haal Gegevens Van Bron 1
    response_variable: Zenders    

I invoke this with the following action:

data:
  call_Zender: 1
  Spelers_Type: Sonos
  Zender: JOE 80s & 90s
response_variable: Zenders
action: script.gegevensbron

The strange thing is that the response is incorrect. I would expect the response to be “https://icecast-qmusicbe-cdp.triple-it.nl/joe_80s_90s.mp3,” but the response is: “https://icecast-qmusicbe-cdp.triple-it.nl/joe 80s 90s.mp3,” so the two underscores in joe_80s_90s are replaced by a space, which is preventing the automation from working. Can someone explain the reason for this?

I’ve been searching for this all afternoon and can’t figure it out.

Thanks for all your responses.

Then, why are you replacing underscores with spaces? Try removing that, as a start. I haven’t read the details other than that, so I don’t know if the other parts work.

Thanks so much for your reply.

Damn, I hadn’t seen this, but it did solve my problem. Thank you.

:rofl: :+1: