DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Trending

  • Creating a Web Project: Caching for Performance Optimization
  • The End of “Good Enough Agile”
  • SaaS in an Enterprise - An Implementation Roadmap
  • How to Merge HTML Documents in Java

Uploading, Modifying, and Viewing Video Files with the DailyMotion API

This article explores how through three-component APIs, you can access most, if not all, aspects of Dailymotion.

By 
Gilad David Maayan user avatar
Gilad David Maayan
DZone Core CORE ·
Mar. 29, 22 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
6.2K Views

Join the DZone community and get the full member experience.

Join For Free

Image Source

Dailymotion is a French video-sharing platform owned by Vivendi. In the US it is supported by partners like Vice Media, Bloomberg, and Hearst Digital Media. It is available in 183 languages with 43 localized versions. It is currently estimated to have 300 million users, which is substantial but far below that of its larger competitor, YouTube.

The Dailymotion API is a set of developer tools that you can use to manage and interact with Dailymotion content. Through three-component APIs, you can access most, if not all, aspects of Dailymotion. Public data is freely available while private data is restricted according to the permissions granted to your authentication status and permissions.

  • Data API: This API enables you to access, modify, and publish data. It enables you to work with a variety of Dailymotion objects, including videos, playlists, and users. 

  • Player API: This API enables you to control a player that can be displayed or embedded in websites or applications. Embedding is compatible with most mobile devices as well as HTML-5 compliant smart devices. 

  • Reporting API: This API enables you to build customizable reports that include aggregated performance measurements. It includes a flexible interface and supports multiple data formats. This API is only available to verified Dailymotion partners. 

What Can You Do With Dailymotion's API?

While there are many actions you can perform via the API, below are some of the most common and helpful capabilities. 

Embed a Video on a Website

You can embed Dailymotion videos with their native player via an <iframe> element. To achieve this, you can use one of the following methods: 

  • Via the embed_html field of the data API’s video object

  • Manually copy code from the export tab of the video page on Dailymotion

  • By using the oEmbed protocol

Whichever method you choose, the code for embed should look roughly as follows:

 
<iframe frameborder="0" width="480"

height="270"src="https://www.Dailymotion.com/embed/video/VIDEO_ID?PARAMS"allowfullscreen allow="autoplay"></iframe>


Customize a Video Player

Once a player is included in your site or app, you can customize the settings to match your overall theme and needs. This includes player color, behavior, controls, and logos. One way to set this customization is with params, query-string parameters. You can learn more about these parameters here. 

To modify a player, you can define your params properties via the DM.player() method. This method is included in the JavaScript SDK. Below you can see an example of a customized player:

 
<script src="https://api.dmcdn.net/all.js"></script>

<div id="player"></div>

<script>var player = DM.player(document.getElementById("player"), {video: "VIDEO_ID", width: "100%", height: "100%", params: {autoplay: true, mute: true}});</script>


Add Subtitles to a Video

Dailymotion’s API includes methods that enable you to add or modify subtitles associated with your videos. This is done using subtitle objects that contain subtitle or closed caption information. 

To create a new subtitle object, you can do so with a POST request through the video graph object. Below you can see an example request uploading a subtitle file:

 
curl -X POST -H "Authorization: Bearer ${ACCESS_TOKEN}" \  

     -d 'language=en' \ 

     -d 'url=https://your_site.com/subtitle_file.srt' \   

     -d 'format=SRT' \      

     https://api.dailymotion.com/video/<VIDEO_ID>/subtitles


Protect a Video With a Password

If you have private videos or want to restrict video access to specific users, you can add password protection. You can do this by defining an access token and setting a password. Once a password is added, the visibility of the video changes to “password protected”.

You can see an example of this code below:

 
curl -X POST -H "Authorization: Bearer ${ACCESS_TOKEN}" \ 

     -d 'password=MyPassword' \ 

     https://api.dailymotion.com/video/myvideo


How to Upload and Publish Videos With Dailymotion API

The most basic and perhaps most important functionality of the Dailymotion API is the ability to upload and publish videos. Below you can see a brief walkthrough explaining the steps needed, including sample code. This is summarized from the Dailymotion documentation which you can see here. 

1.  Authenticate the User

Before you can get started with uploading, you need to authenticate users to ensure API access is secure. Determine which account you want the video to be hosted on. In this account, you then need to authenticate your user and request the manage_videos scope. 

2.  Get an Upload URL

Next, you can make a GET request, including your access token, to https://api.dailymotion.com/file/upload. Once this request is sent, you should receive the upload_url and a progress_url.

 
curl -H "Authorization: Bearer ${ACCESS_TOKEN}" \

     "https://api.dailymotion.com/file/upload"


When performing this step, you also have the option to enable end-users to post videos. To do this, you need to configure a callback_url parameter to call your service after the upload is complete. 

3.  Upload the Video

With your upload URL, you can now upload the video of your choice with a POST request. You should do this with the multipart/form-data content type to ensure the video is uploaded successfully. 

 
curl -X POST \ 

     -F 'file=@/path/to/your/video.mp4' \ 

     '<UPLOAD_URL>'


After your request is made you should either receive a JSON object or your callback URL with additional query string parameters. From either, make note of the URL field.

Here is how to upload the file using the PHP API:

 
$url = $api->uploadFile('/path/to/your/video.mp4');

$api->post(
    '/videos',
    array(
        'url'       => $url,
        'title'     => 'Dailymotion PHP SDK upload test',
        'tags'      => 'dailymotion,api,sdk,test',
        'channel'   => 'videogames',
        'published' => true,
        'is_created_for_kids'   => false,
    )
);


4.  Create the Video

Using the noted URL field, you now need to make another POST request to https://api.dailymotion.com/me/videos. This call creates the video and should return an ID number for your new video in the response.id field.

 
curl -X POST -H "Authorization: Bearer ${ACCESS_TOKEN}" \

           "https://api.dailymotion.com/me/videos"


5.  Publish the Video

Assuming you're ready to publish the video, you need to perform one more POST request to https://api.dailymotion.com/video/<VIDEO_ID>. In this request, you should include any fields that you want to modify before posting. You must also include channel, title, and tags fields as well as a published field that is set to true.

 
curl -X POST -H "Authorization: Bearer ${ACCESS_TOKEN}" \

     -d 'published=true' \

     -d 'title=<TITLE>' \

     -d 'channel=<CHANNEL>' \

     -d 'tags=<TAGS>' \

     https://api.dailymotion.com/video/<VIDEO_ID>


Opinions expressed by DZone contributors are their own.

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!