Repository: yt-dlp/yt-dlp
File: yt_dlp/downloader/soop.py (Python)

Code before:
import threading
import time

from .common import FileDownloader
from . import HlsFD
from ..extractor.afreecatv import _cloudfront_auth_request
from ..networking.exceptions import network_exceptions


class SoopVodFD(FileDownloader):
    """
    Downloads Soop subscription VODs with required cookie refresh requests
    Note, this is not a part of public API, and will be removed without notice.
    DO NOT USE
    """

    def real_download(self, filename, info_dict):
        self.to_screen(f'[{self.FD_NAME}] Downloading Soop subscription VOD HLS')
        fd = HlsFD(self.ydl, self.params)
        refresh_params = info_dict.get('_cookie_refresh_params')

        fd = HlsFD(self.ydl, self.params)

        stop_event = threading.Event()
        referer_url = info_dict['webpage_url']
        refresh_thread = threading.Thread(
            target=self._cookie_refresh_thread,
            args=(stop_event, refresh_params, referer_url),
        )
        refresh_thread.start()

        try:
            return fd.real_download(filename, info_dict)
        finally:
            stop_event.set()

    def _cookie_refresh_thread(self, stop_event, refresh_params, referer_url):
        m3u8_url = refresh_params['m3u8_url']
        strm_id = refresh_params['strm_id']
        video_id = refresh_params['video_id']

        def _get_cloudfront_cookie_expiration(m3u8_url):
            cookies = self.ydl.cookiejar.get_cookies_for_url(m3u8_url)
            return min((cookie.expires for cookie in cookies if 'CloudFront' in cookie.name and cookie.expires), default=0)


Review comment (suggestion):
```suggestion
        refresh_params = info_dict['_cookie_refresh_params']
```

Code after:
import threading
import time

from .common import FileDownloader
from . import HlsFD
from ..extractor.afreecatv import _cloudfront_auth_request
from ..networking.exceptions import network_exceptions


class SoopVodFD(FileDownloader):
    """
    Downloads Soop subscription VODs with required cookie refresh requests
    Note, this is not a part of public API, and will be removed without notice.
    DO NOT USE
    """

    def real_download(self, filename, info_dict):
        self.to_screen(f'[{self.FD_NAME}] Downloading Soop subscription VOD HLS')
        fd = HlsFD(self.ydl, self.params)
        refresh_params = info_dict['_cookie_refresh_params']
        referer_url = info_dict['webpage_url']

        stop_event = threading.Event()
        refresh_thread = threading.Thread(
            target=self._cookie_refresh_thread,
            args=(stop_event, refresh_params, referer_url),
        )
        refresh_thread.start()

        try:
            return fd.real_download(filename, info_dict)
        finally:
            stop_event.set()

    def _cookie_refresh_thread(self, stop_event, refresh_params, referer_url):
        m3u8_url = refresh_params['m3u8_url']
        strm_id = refresh_params['strm_id']
        video_id = refresh_params['video_id']

        def _get_cloudfront_cookie_expiration(m3u8_url):
            cookies = self.ydl.cookiejar.get_cookies_for_url(m3u8_url)
            return min((cookie.expires for cookie in cookies if 'CloudFront' in cookie.name and cookie.expires), default=0)

        while not stop_event.wait(5):
            current_time = time.time()