Last active
September 4, 2024 17:31
-
-
Save apsolut/becba83256a304934ff6df4a5fb19d2f to your computer and use it in GitHub Desktop.
hubspot youtube get ID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# Function to extract YouTube video ID #} | |
{% macro extract_youtube_id(url) %} | |
{% set cleaned_url = url|trim %} | |
{% set video_id = cleaned_url | |
| replace("https://www.youtube.com/watch?v=", "") | |
| replace("http://www.youtube.com/watch?v=", "") | |
| replace("https://youtu.be/", "") | |
| replace("http://youtu.be/", "") | |
| split("&") | |
| first | |
| split("?") | |
| first %} | |
{# Validate the extracted ID #} | |
{% if video_id|length == 11 %} | |
{{ video_id }} | |
{% else %} | |
{{ "" }} | |
{% endif %} | |
{% endmacro %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment