Scrape Podcast

Hi there,

I am quite new to NR and I try to replicate one flow, but I do not succeed, so maybe you could help me in order to get int working:

Create an HTTP request node that performs a GET request to the URL you found in step one. This puts the response into msg.payload

Extract the episode URL from the response using a function node. I used this code which puts the value into msg.source:

const regex = /<meta property="og:url" content="([^"]+)"/
const found = msg.payload.match(regex);
msg.source = found[1]
return msg;

Now you just have to play the episode through the Sonos speaker which I did using a call service node configured like this:

Domain: media_player
Service: play_media
Entity: <Choose the right media player entity>
Data: {"media_content_id":"{{{source}}}","media_content_type":"episode"}

Export:

[
    {
        "id": "f37348c616f8ae69",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "253c135159705a13",
        "type": "http request",
        "z": "f37348c616f8ae69",
        "name": "",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "https://open.spotify.com/embed/show/4ymTKvZm5SGMtk4NlmRyKv",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 850,
        "y": 560,
        "wires": [
            [
                "5491733223e8bc10"
            ]
        ]
    },
    {
        "id": "974256a0b079e3f8",
        "type": "debug",
        "z": "f37348c616f8ae69",
        "name": "msg",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "source",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1330,
        "y": 580,
        "wires": []
    },
    {
        "id": "5491733223e8bc10",
        "type": "function",
        "z": "f37348c616f8ae69",
        "name": "function 1",
        "func": "const regex = /<meta property=\"og:url\" content=\"([^\"]+)\"/\nconst found = msg.payload.match(regex);\nmsg.source = found[1]\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1080,
        "y": 580,
        "wires": [
            [
                "974256a0b079e3f8"
            ]
        ]
    },
    {
        "id": "c99909cdb2c79307",
        "type": "inject",
        "z": "f37348c616f8ae69",
        "name": "",
        "props": [
            {
                "p": "topic",
                "vt": "str"
            },
            {
                "p": "payload"
            },
            {
                "p": "source",
                "v": "",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "str",
        "x": 630,
        "y": 560,
        "wires": [
            [
                "253c135159705a13"
            ]
        ]
    },
    {
        "id": "e15a3ede88483dca",
        "type": "server-events",
        "z": "f37348c616f8ae69",
        "name": "",
        "server": "30f4e831bda5708b",
        "version": 3,
        "exposeAsEntityConfig": "",
        "eventType": "",
        "eventData": "",
        "waitForRunning": true,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "eventData"
            },
            {
                "property": "topic",
                "propertyType": "msg",
                "value": "$outputData(\"eventData\").event_type",
                "valueType": "jsonata"
            }
        ],
        "event_type": "",
        "x": 460,
        "y": 440,
        "wires": [
            []
        ]
    },
    {
        "id": "30f4e831bda5708b",
        "type": "server",
        "name": "Home Assistant",
        "version": 5,
        "addon": false,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true,
        "heartbeat": false,
        "heartbeatInterval": "30",
        "areaSelector": "friendlyName",
        "deviceSelector": "friendlyName",
        "entitySelector": "friendlyName",
        "statusSeparator": ": ",
        "statusYear": "hidden",
        "statusMonth": "short",
        "statusDay": "numeric",
        "statusHourCycle": "default",
        "statusTimeFormat": "h:m",
        "enableGlobalContextStore": false
    }
]

I always get this result:

2.7.2024, 11:51:45node: function 1
function : (error)
"TypeError: Cannot read properties of null (reading '1')"

And one question: how to I get access to the msg from home assistant?

There error is because match is not finding any results.