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

Code before:
# coding: utf-8
from __future__ import unicode_literals
from datetime import datetime
import re
import time
from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    url_or_none,
    traverse_obj,
)


class Kanal2IE(InfoExtractor):
    SUBTITLE_DATE_RE = re.compile(r'\((\d{2}\.\d{2}\.\d{4}\s\d{2}:\d{2})\)$')

    _VALID_URL = r'https?://.+\.postimees\.ee/[^?]+\?(.*?&)?id=(?P<id>\d+)'
    _TESTS = [
        {
            'note': 'Test standard url (#5575)',
            'url': 'https://kanal2.postimees.ee/pluss/video/?id=40792',
            'md5': 'baf49cab468cf553bc1cf36909f1a0c7',
            'info_dict': {
                'id': '40792',
                'ext': 'mp4',
                'title': 'Aedniku aabits / Osa 53  (05.08.2016 20:00)',
                'thumbnail': r're:https?://.*\.jpg$',
                'description': 'md5:53cabf3c5d73150d594747f727431248',
                'upload_date': '20160805',
                'timestamp': 1470416400,
            }
        },
    ]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        playlist = self.get_playlist(video_id)

        info = {
            'id': video_id,
            'title': self.get_title(playlist.get('info')),
            'description': traverse_obj(playlist, ('info', 'description')),

Review comment (refactor):
will this extractor work with other postimees.ee sites? if so, then should it still be named Kanal2?
```suggestion
    _VALID_URL = r'https?://kanal2\.postimees\.ee/[^?]+\?(.*?&)?id=(?P<id>\d+)'
```
or if we do want to match any subdomain then we should do it safely:
```suggestion
    _VALID_URL = r'https?://(?:[\w\d-]+\.)?postimees\.ee/[^?]+\?(.*?&)?id=(?P<id>\d+)'
```

Code after:
from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    join_nonempty,
    traverse_obj,
    unified_timestamp,
    update_url_query,
)


class Kanal2IE(InfoExtractor):
    _VALID_URL = r'https?://kanal2\.postimees\.ee/[^?#]+\?([^#]+&)?id=(?P<id>\d+)'
    _TESTS = [{
        'note': 'Test standard url (#5575)',
        'url': 'https://kanal2.postimees.ee/pluss/video/?id=40792',
        'md5': '7ea7b16266ec1798743777df241883dd',
        'info_dict': {
            'id': '40792',
            'ext': 'mp4',
            'title': 'Aedniku aabits / Osa 53  (05.08.2016 20:00)',
            'thumbnail': r're:https?://.*\.jpg$',
            'description': 'md5:53cabf3c5d73150d594747f727431248',
            'upload_date': '20160805',
            'timestamp': 1470420000,
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        playlist = self._download_json(
            f'https://kanal2.postimees.ee/player/playlist/{video_id}',
            video_id, query={'type': 'episodes'},
            headers={'X-Requested-With': 'XMLHttpRequest'})

        return {
            'id': video_id,
            'title': join_nonempty(*traverse_obj(playlist, ('info', ('title', 'subtitle'))), delim=' / '),
            'description': traverse_obj(playlist, ('info', 'description')),
            'thumbnail': traverse_obj(playlist, ('data', 'image')),
            'formats': self.get_formats(playlist, video_id),
            'timestamp': unified_timestamp(self._search_regex(
                r'\((\d{2}\.\d{2}\.\d{4}\s\d{2}:\d{2})\)$',