How to Add YouTube Timestamps into JSON-LD VideoObject Clips with Python
Manually creating JSON-LD for each video, especially those with several timestamps or clips, can be a time-consuming task. That’s why I created this simple but effective Python script that can automate this process for you. You only need to copy and paste the info. And you don’t need to copy each timestamp separately. Neither you need to figure out or convert the time into seconds. The code does it for you. You just copy your timestamps all at once and get the clips generated.
This Python script is a straightforward tool that converts YouTube timestamps into the JSON-LD format, generating structured data for SEO enhancement. Please note that it was written by ChatGPT, but I reviewed and tested it accordingly.
Functionality
The script takes as input user-provided details about a YouTube video, such as its name, duration, upload date, thumbnail URL, and regions allowed. It also requires the raw copy-pasted timestamps from the video.
The main feature of this script is its ability to process these raw YouTube timestamps into a structured format. It splits the timestamps and their corresponding descriptions, converting each timestamp into seconds. The script then creates an array of “clips” for the video, where each clip corresponds to a timestamp and includes its start offset, end offset, description, and a URL. This array represents the “hasPart” attribute of the video object in the final JSON-LD structure.
The output of the script is a complete JSON-LD structure for the video, including its details and the “hasPart” array of clips. This JSON-LD can be embedded in the HTML of a webpage to provide structured data to search engines, enhancing the SEO of the page.
For more in-depth discussion and use cases of this script, see Duda webinar here.
Use Cases
I’ve already tried it on many videos, including but not limited to Semantic SEO with Koray and SEO Audits with Alan Bleiweiss.