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

Code before:
        },
    ]

    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')),
            'webpage_url': traverse_obj(playlist, ('data', 'url')),
            'thumbnail': traverse_obj(playlist, ('data', 'image')),
            'formats': self.get_formats(playlist, video_id),
            'timestamp': self.get_timestamp(traverse_obj(playlist, ('info', 'subtitle'))),
        }

        return info

    def get_title(self, info):
        title = info['title']

        if info['subtitle']:
            title += ' / ' + info['subtitle']

        return title

    def get_timestamp(self, subtitle):
        if not subtitle:
            return None
        # Extract timestamp from:
        #  "subtitle": "Osa 53  (05.08.2016 20:00)",
        match = self._search_regex(self.SUBTITLE_DATE_RE, subtitle, 'dateandtime', default=None)
        if not match:
            return None

        # https://stackoverflow.com/a/27914405/2314626
        date = datetime.strptime(match, '%d.%m.%Y %H:%M')
        unixtime = time.mktime(date.timetuple())

        try:
            import pytz
            # the time is always in this timezone
            tz = pytz.timezone('Europe/Tallinn')
            unixtime += tz.utcoffset(date).microseconds
        except ImportError:
            pass

        return unixtime

    def get_formats(self, playlist, video_id):

Review comment (refactor):
`info['subtitle']` is fatal and should not be. one-time use function, move into `_real_extract`
```py
        title = traverse_obj(playlist, ('info', 'title'))
        sub = traverse_obj(sub, ('info', 'subtitle'))
        if sub:
            title = f'{title} / {sub}'
```
`sub` var can be used for the `timestamp` too

is subtitle always just the episode number and airdate? if so, wouldn't it be better to only store those values in their own info_dict fields? there is an `episode` int value that can be found the playlist JSON

Code after:
            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})\)$',
                traverse_obj(playlist, ('info', 'subtitle')), 'timestamp', default='') + ' +0200'),
        }

    def get_formats(self, playlist, video_id):
        path = traverse_obj(playlist, ('data', 'path'))
        if not path:
            raise ExtractorError('Path value not found in playlist JSON response')
        session = self._download_json(
            'https://sts.postimees.ee/session/register',
            video_id, note='Creating session', errnote='Error creating session',
            headers={
                'X-Original-URI': path,
                'Accept': 'application/json',
            })
        if session.get('reason') != 'OK' or not session.get('session'):
            reason = session.get('reason', 'unknown error')
            raise ExtractorError(f'Unable to obtain session: {reason}')

        formats = []
        for stream in traverse_obj(playlist, ('data', 'streams', ..., 'file')):
            formats.extend(self._extract_m3u8_formats(
                update_url_query(stream, {'s': session['session']}), video_id, 'mp4'))

        return formats