Skip to content

Reference for youtube_dl_scraper/core/scraper_manager.py

youtube_dl_scraper.core.scraper_manager.ScraperManager

ScraperManager()

Manages the collection of video and caption scrapers, allowing retrieval and listing of scrapers.

Attributes:

Name Type Description
video_scrapers dict

A dictionary of video scrapers.

caption_scrapers dict

A dictionary of caption scrapers.

Source code in youtube_dl_scraper/core/scraper_manager.py
def __init__(self):
    """
    Initialize the ScraperManager with video and caption scrapers.

    Attributes:
        video_scrapers (dict): A dictionary of video scrapers.
        caption_scrapers (dict): A dictionary of caption scrapers.
    """
    self.video_scrapers = video_scrapers
    self.caption_scrapers = caption_scrapers
get_scraper_class
get_scraper_class(scraper_type: str, name: str) -> BaseScraper

Retrieve a specific scraper class by its type and name.

Parameters:

Name Type Description Default
scraper_type str

The type of scraper, either 'video' or 'caption'.

required
name str

The name of the specific scraper to retrieve.

required

Returns:

Name Type Description
BaseScraper BaseScraper

The scraper class corresponding to the given type and name.

Raises:

Type Description
ValueError

If no scraper is found with the provided name and type.

Source code in youtube_dl_scraper/core/scraper_manager.py
def get_scraper_class(self, scraper_type: str, name: str) -> BaseScraper:
    """
    Retrieve a specific scraper class by its type and name.

    Args:
        scraper_type (str): The type of scraper, either 'video' or 'caption'.
        name (str): The name of the specific scraper to retrieve.

    Returns:
        BaseScraper: The scraper class corresponding to the given type and name.

    Raises:
        ValueError: If no scraper is found with the provided name and type.
    """
    scrapers = getattr(self, f"{scraper_type.lower()}_scrapers", {})
    scraper = scrapers.get(name)
    if not scraper:
        raise ValueError(f"No {scraper_type} scraper found with name '{name}'")
    return scraper
list_scrapers
list_scrapers() -> dict

List all available scrapers by type.

Returns:

Name Type Description
dict dict

A dictionary containing lists of available video and caption scrapers under the keys "video_scrapers" and "caption_scrapers".

Source code in youtube_dl_scraper/core/scraper_manager.py
def list_scrapers(self) -> dict:
    """
    List all available scrapers by type.

    Returns:
        dict: A dictionary containing lists of available video and caption scrapers under
              the keys "video_scrapers" and "caption_scrapers".
    """
    return {
        "video_scrapers": list(self.video_scrapers.keys()),
        "caption_scrapers": list(self.caption_scrapers.keys()),
    }