Search code examples
chatlive-streamingdailymotion-api

Retrieve Dailymotion Games chat messages


I would like to retrieve Dailymotion Games chat messages using their API, but the official documentation is not very clear on this point => https://faq.dailymotion.com/hc/en-us/articles/203886473-Dailymotion-live-API-for-developers

I tried to use the API to retrieve comments of a video with my live video id (endpoint => https://api.dailymotion.com/video/[LIVE_VIDEO_ID]/comments), but it doesn't return any chat messages...

Do you know if it's possible?


Solution

  • Ok, I've searched a little bit more and I found a more elegant way to do that avoiding the scraping method.

    In fact the embed chat page (returned by the chat_embed_url) use EventSource to get notified when a new message arrived.

    With this good NPM package, I've been able to retrieve chat messages in only 5 lines:

    var EventSource = require('eventsource');
    
    var url = 'http://dmchat.dailymotion.com/rooms/[USERNAME]-[CHANNEL_ID]';
    var es = new EventSource(url);
    es.addEventListener('message', function (e) {
        console.log(e.data);
    });