To enjoy all our Developer Portal features, please switch to Microsoft Edge, Google Chrome or Mozilla Firefox browsers.

How to launch a commercial break during a live event using dailymotion’s API?

Posted on by Julie Lambert

During a live event, dailymotion’s verified partners can launch a commercial break with up to 24 commercials per hour. When the commercial break is triggered, all viewers will simultaneously receive mid-roll advertising in their Player, composed of one or several ads depending on the input number.

To launch a commercial break, you need to authenticate and request an access token with the manage_videos scope. Then, issue a POST HTTP request to https://api.dailymotion.com/video/<VIDEO_ID> with the live_ad_break_launch=1 field set to the number of advertisments you want to display (only one at the time).

curl --request POST \
   --header "Authorization: Bearer ${ACCESS_TOKEN}" \
   --data "live_ad_break_launch=1" \
   "https://api.dailymotion.com/video/${VIDEO_ID}"

You may also be interested in the live_ad_break_end_time field – to know the estimated time of the end of the commercial break (45 sec between two commercials) and the live_ad_break_remaining field – to know how many ads you can send during the coming hour).

How to run recursive live adbreaks using Python?

Make sure you have Python 2.7.9 or more recent version on your server.

Install requests:

$ pip install requests

Install JSON:

$ pip install json

Install crontab:

$ pip install crontab

Add your credentials and live video id you want to trigger adbreak on, then save as adbreak.py.

import requests
import json
 
data = {
  'grant_type': 'password',
  'client_id': '<Your API Key>',
  'client_secret': '<Your API Secret>',
  'username': '<Your Username>',
  'password': '<Your Password>'
}
 
response = requests.post('https://api.dailymotion.com/oauth/token', data=data)
json_data = json.loads(response.text)
 
 
headers = {
    'Authorization': 'Bearer ' + json_data['access_token'],
}
 
data = {
  'live_ad_break_launch': '1'
}
 
response = requests.post('https://api.dailymotion.com/video/<VIDEO ID>', headers=headers, data=data)
#json_data1= json.loads(response.text)

Run the command line on your server to make it recursive (ie. for 15 minutes, you will need to use */15 * * * *):

crontab */15 * * * *  /path/to/script

Not a partner yet?

Become one of dailymotion’s partners to monetize your content, create a channel and enjoy our analysis, content management, distribution and statistics tools.