Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/wasdtv.py (Python)

Code before:
# coding: utf-8
from __future__ import unicode_literals

from yt_dlp.extractor.common import InfoExtractor
from yt_dlp.compat import (
    compat_kwargs,
    compat_str,
)
from yt_dlp.utils import (
    ExtractorError,
    int_or_none,
    parse_iso8601,
    urljoin,
    try_get,
)


class WASDTVBaseIE(InfoExtractor):
    _API_BASE = 'https://wasd.tv/api/'
    _THUMBNAIL_SIZES = ('small', 'medium', 'large')

    def _fetch(self, *args, **kwargs):
        description = kwargs.pop('description')
        response = self._download_json(
            urljoin(self._API_BASE, '/'.join(map(compat_str, args))),
            video_id=kwargs.pop('item_id'),
            note='Downloading {} metadata'.format(description),
            errnote='Unable to download {} metadata'.format(description),
            **compat_kwargs(kwargs))
        error = response.get('error')
        if error:
            raise ExtractorError(f'{self.IE_NAME} returned error: {error}', expected=True)
        return response.get('result')

    def _extract_thumbnails(self, thumbnails_dict):
        if not thumbnails_dict:
            return None
        thumbnails = []
        for index, thumbnail_size in enumerate(self._THUMBNAIL_SIZES):
            thumbnail_url = thumbnails_dict.get(thumbnail_size)
            if not thumbnail_url:
                continue
            thumbnails.append({
                'url': thumbnail_url,
                'preference': index,
            })
        return thumbnails

Review comment (refactor):
why is this needed?
u are not even using fata=false
the code will never show ur ExtractorError message.

Code after:
# coding: utf-8
from __future__ import unicode_literals

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    int_or_none,
    parse_iso8601,
    traverse_obj,
    try_get,
)


class WASDTVBaseIE(InfoExtractor):

    def _fetch(self, path, video_id, description, query={}):
        response = self._download_json(
            f'https://wasd.tv/api/{path}', video_id, query=query,
            note=f'Downloading {description} metadata',
            errnote=f'Unable to download {description} metadata')
        error = response.get('error')
        if error:
            raise ExtractorError(f'{self.IE_NAME} returned error: {error}', expected=True)
        return response.get('result')

    def _extract_thumbnails(self, thumbnails_dict):
        return [{
            'url': url,
            'preference': index,
        } for index, url in enumerate(
            traverse_obj(thumbnails_dict, (('small', 'medium', 'large'),))) if url]

    def _real_extract(self, url):
        container = self._get_container(url)
        stream = traverse_obj(container, ('media_container_streams', 0))
        media = try_get(stream, lambda x: x['stream_media'][0])
        if not media:
            raise ExtractorError('Can not extract media data.', expected=True)
        media_meta = media.get('media_meta')
        media_url, is_live = self._get_media_url(media_meta)
        video_id = media.get('media_id') or container.get('media_container_id')
        formats, subtitles = self._extract_m3u8_formats_and_subtitles(media_url, video_id, 'mp4')
        self._sort_formats(formats)
        return {
            'id': str(video_id),
            'title': container.get('media_container_name') or self._og_search_title(self._download_webpage(url, video_id)),
            'description': container.get('media_container_description'),