Skip to content

Reference for youtube_dl_scraper/utils/title_to_slug.py

youtube_dl_scraper.utils.title_to_slug.title_to_slug

title_to_slug(title: str) -> str

Converts a YouTube video title into a URL-friendly slug.

Parameters:

Name Type Description Default
title str

The YouTube video title.

required

Returns:

Name Type Description
str str

A slug suitable for use in URLs.

Source code in youtube_dl_scraper/utils/title_to_slug.py
def title_to_slug(title: str) -> str:
    """
    Converts a YouTube video title into a URL-friendly slug.

    Args:
        title (str): The YouTube video title.

    Returns:
        str: A slug suitable for use in URLs.
    """
    # Remove non-ASCII characters and accents
    title = unidecode(title)
    title = title.lower()
    title = re.sub(r"[^a-z0-9]+", "-", title)
    title = title.strip("-")

    return title