adblockradio / webradio-metadata

Collection of scraping recipes to get metadata about what is being streamed on webradios
Mozilla Public License 2.0
35 stars 13 forks source link

FIP changed their API #5

Open saveman71 opened 4 years ago

saveman71 commented 4 years ago

FIP changed their website this week, and with it their API. It's now a graphql endpoint:

https://www.fip.fr/latest/api/graphql?operationName=Now&variables=%7B%22bannerPreset%22%3A%22600x600-noTransform%22%2C%22stationId%22%3A7%2C%22previousTrackLimit%22%3A3%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%228a931c7d177ff69709a79f4c213bd2403f0c11836c560bc22da55628d8100df8%22%7D%7D

The variables param decodes to:

{"bannerPreset":"600x600-noTransform","stationId":69,"previousTrackLimit":3}

And the extensions:

{"persistedQuery":{"version":1,"sha256Hash":"8a931c7d177ff69709a79f4c213bd2403f0c11836c560bc22da55628d8100df8"}}

The extensions param seems to be mandatory, as changing one char in the SHA hash says "persisted query not found".

The main FIP station id is 7.

The repsonse is:

{
    "data": {
        "now": {
            "__typename": "Now",
            "playing_item": {
                "__typename": "TimelineItem",
                "title": null,
                "subtitle": null,
                "cover": null,
                "start_time": 0,
                "end_time": 0
            },
            "program": null,
            "song": null,
            "server_time": 1562752366,
            "next_refresh": 1562752376,
            "mode": "program"
        },
        "previousTracks": {
            "__typename": "HistoryCursor",
            "edges": [
                {
                    "__typename": "TimeLineItemEdge",
                    "node": {
                        "__typename": "TimelineItem",
                        "title": "Camille",
                        "subtitle": "Pâle septembre",
                        "start_time": 1562752070,
                        "cover": "https://cdns-images.dzcdn.net/images/cover/9bfc2800990b096aefce6ee9855702fa/1000x1000-000000-80-0-0.jpg"
                    }
                },
                {
                    "__typename": "TimeLineItemEdge",
                    "node": {
                        "__typename": "TimelineItem",
                        "title": "Nola Is Calling",
                        "subtitle": "Downtown",
                        "start_time": 1562751858,
                        "cover": "https://cdns-images.dzcdn.net/images/cover/e37d01ecbb2f4fc760ff340a2eedb98d/1000x1000-000000-80-0-0.jpg"
                    }
                },
                {
                    "__typename": "TimeLineItemEdge",
                    "node": {
                        "__typename": "TimelineItem",
                        "title": "Quatuor Debussy",
                        "subtitle": "Midi Do Majeur - pour quatuor à cordes et vibraphone",
                        "start_time": 1562751691,
                        "cover": null
                    }
                }
            ]
        },
        "nextTracks": [
            {
                "__typename": "TimelineItem",
                "title": "Rene Aubry",
                "subtitle": "Mémoires du futur",
                "start_time": 1562752284,
                "cover": "https://cdns-images.dzcdn.net/images/cover/6c5a7e023e399e995d79f2c90407203a/1000x1000-000000-80-0-0.jpg"
            }
        ]
    }
}
dest4 commented 4 years ago

Thanks for the nice bug report. This should be fixed in https://github.com/adblockradio/webradio-metadata/commit/cd052849871c274c625c508a13ee1d99a411db08.

dest4 commented 4 years ago

Updated on NPM as well, with version 0.1.38 https://www.npmjs.com/package/webradio-metadata?activeTab=versions

saveman71 commented 4 years ago

Just saw that you didn't change the calls for the other "channels" of fip, but just letting you know it's broken as well! In the end I ended up crafting my own solution to my problem: https://github.com/saveman71/fip-to-spotify

maartenlangeveld commented 3 years ago

@saveman71 Thanks, I wrote a script to retrieve metadata to use with upmpdcli mpd controller. Do you know if there are also new api's available for the other Radio France stations?

For Mouv' the url : https://www.mouv.fr/latest/api/graphql exists but it probably needs a different SHA hash since I cannot connect using the FIP parameters. Do you know?

Would be nice if there's also new api support for France Inter, France Info, France Culturelle and the France Music stations.

saveman71 commented 3 years ago

I had retrieved the SHA by inspecting the fip website requests, I guess you can do the same with moov's website?

maartenlangeveld commented 3 years ago

@saveman71 Thanks for your quick response and advice !How can I inspect those website requests? Is it easy to do?

saveman71 commented 3 years ago

https://developers.google.com/web/tools/chrome-devtools/network :)

maartenlangeveld commented 3 years ago

Thanks again! I will go and read/view.