[Python] How to add custom extractor to yt-dlp?

Discussão em 'Python' iniciado por Stack, Dezembro 18, 2024.

  1. Stack

    Stack Membro Participativo

    I want to make a custom extractor for https://www.buzzsprout.com in order to extract season and episode numbers in addition to what generic extractor already does.

    This is my script saved at: /usr/lib/python3/dist-packages/yt_dlp/extractor/buzz.py

    from yt_dlp.extractor.common import InfoExtractor
    import re

    class BuzzSproutIE(InfoExtractor):
    IE_NAME = 'buzzsprout'
    _VALID_URL = r'https://www.buzzsprout.com/.*/(?P<id>[^/?#&]+)$'

    def _real_extract(self, url):
    video_id = self._match_id(url)
    webpage = self._download_webpage(url, video_id)

    # Extract the season number.
    season = self._search_regex(
    r'<span class="whitespace-nowrap">Season (\d+)</span>',
    webpage,
    'season',
    fatal=False
    )
    # Extract the episode number.
    episode = self._search_regex(
    r'<span class="whitespace-nowrap">Episode (\d+)</span>',
    webpage,
    'episode',
    fatal=False
    )

    return {
    'id': video_id,
    'title': self._html_search_regex(r'<title>([^<]+)</title>', webpage, 'title'),
    'season': season,
    'episode': episode,
    }



    And I have added this line to /usr/lib/python3/dist-packages/yt_dlp/extractor/_extractors.py:

    from .buzz import BuzzSproutIE


    But yt-dlp --list-extractors | grep -i buzz still doesn't show my extractor and https://www.buzzsprout.com urls are still handled by generic extractor.

    What am I missing?

    Continue reading...

Compartilhe esta Página