How to launch a commercial break during a Live event using Dailymotion’s API?

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 advertisements 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.