Mass upload from an Excel file using Python SDK
Our REST API allows “Mass Upload” for customers who need to transfer large video catalogs to Dailymotion. One of the easiest ways is to upload files via an Excel file.
Follow this tutorial to know how to use a Python library that will automatically upload your videos.
1. Create the Excel file
First step: create your Excel file. This very simple document must include specific information about your videos:
- Titles
- URLs
- Tags
- Channels (the video category)
- Descriptions
- Is it already published? (true/false)
- Is it created for kids? (true/false)
TemplateUse this Excel template to list the videos you want to mass upload.
2. Upload using Python
Now that your Excel file is created, you need to integrate it in your Python code. For that, we suggest you to use Openpyxl. This open-source Python library can read and write Excel 2010 xlsx, xlsm, xltx and xltm files.
import importlib
from openpyxl import load_workbook
# -----------------------------------------
# Dailymotion SDK import (due to the "-" in module name)
# -----------------------------------------
_DAILYMOTION = importlib.import_module("dailymotion-sdk-python.dailymotion")
# -----------------------------------------
# Dailymotion credentials
# -----------------------------------------
_API_KEY = "YOUR_API_KEY"
_API_SECRET = "YOUR_API_SECRET"
_USERNAME = "YOUR_DAILYMOTION_LOGIN"
_PASSWORD = "YOUR_DAILYMOTION_PASSWORD"
# -----------------------------------------
# Excel loading
# -----------------------------------------
_FILENAME = "Videos.xlsx"
_XLS = load_workbook(_FILENAME)
# Change the sheet name if needed
_SHEET = _XLS["Sheet1"]
# -----------------------------------------
# Adding columns for returned API info
# -----------------------------------------
_DM_XID = _SHEET.cell(
row=1,
column=_SHEET.max_column + 1,
value="Dailymotion xid"
)
_DM_URL = _SHEET.cell(
row=1,
column=_SHEET.max_column + 1,
value="Dailymotion link"
)
# -----------------------------------------
# Instantiate the Dailymotion SDK client
# -----------------------------------------
_DM = _DAILYMOTION.Dailymotion()
try:
# Authentication
_DM.set_grant_type(
"password",
api_key=_API_KEY,
api_secret=_API_SECRET,
scope=["manage_videos"],
info={"username": _USERNAME, "password": _PASSWORD},
)
# -----------------------------------------
# Loop through rows (skip headers)
# -----------------------------------------
for row in _SHEET.iter_rows(min_row=2, max_row=_SHEET.max_row):
# Upload the file to Dailymotion servers
file_path = row[1].value
url = _DM.upload(file_path)
# Prepare video data
parameters = {
"url": url,
"title": row[0].value,
"tags": row[2].value,
"channel": row[3].value,
"description": row[4].value,
"published": row[5].value,
}
# Create the video
result = _DM.post("/me/videos?fields=id,url", parameters)
# Write new values
_SHEET.cell(
row=row[0].row,
column=_DM_XID.column,
value=result["id"]
)
_SHEET.cell(
row=row[0].row,
column=_DM_URL.column,
value=result["url"]
)
print("Upload from Excel file to Dailymotion completed successfully.")
_XLS.save(_FILENAME)
except Exception as e:
print(f"An error occurred: {e}")With this code, our Python SDK will upload your videos to Dailymotion and include all information from your Excel file. The upload time will mostly depend on the size of your files. To help you keep track of the process, you will receive a script every time a new video is uploaded.
Rate limits and larger video catalogs:API rate limits caps the number of videos you can upload per day. To check your current limits at the video level, you can request the
limitsfield on your channel using the API:/user/<CHANNEL_ID>?fields=limits(authentication required).To upload larger video catalogs, please reach out to your Dailymotion Account Manager or to our Support team.
Find more info on other “Mass Upload” options.
Updated 3 days ago
