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

Code before:
import functools
import math

from .streaks import StreaksBaseIE
from ..networking import HEADRequest
from ..utils import (
    InAdvancePagedList,
    clean_html,
    js_to_json,
    parse_iso8601,
    parse_qs,
    str_or_none,
)
from ..utils.traversal import require, traverse_obj


class LocipoBaseIE(StreaksBaseIE):
    _API_BASE = 'https://web-api.locipo.jp'
    _BASE_URL = 'https://locipo.jp'
    _UUID_RE = r'[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}'

    def _real_initialize(self):
        self.cookiejar.clear(domain='locipo.jp')

    def _call_api(self, path, item_id, note, fatal=True):
        return self._download_json(
            f'{self._API_BASE}/{path}', item_id,
            f'Downloading {note} API JSON',
            f'Unable to download {note} API JSON',
            fatal=fatal)


class LocipoIE(LocipoBaseIE):
    _VALID_URL = [
        fr'https?://locipo\.jp/creative/(?P<id>{LocipoBaseIE._UUID_RE})',
        fr'https?://locipo\.jp/embed/?\?(?:[^#]+&)?id=(?P<id>{LocipoBaseIE._UUID_RE})',
    ]
    _TESTS = [{
        'url': 'https://locipo.jp/creative/fb5ffeaa-398d-45ce-bb49-0e221b5f94f1',
        'info_dict': {
            'id': 'fb5ffeaa-398d-45ce-bb49-0e221b5f94f1',
            'ext': 'mp4',
            'title': 'リアルカレカノ#4 ～伊達さゆりと勉強しよっ？～',
            'description': 'md5:70a40c202f3fb7946b61e55fa015094c',
            'display_id': '5a2947fe596441f5bab88a61b0432d0d',
            'live_status': 'not_live',
            'modified_date': r're:\d{8}',
            'modified_timestamp': int,

Review comment (refactor):
Can you explain why we do this?

It will make it so passing cookies for this site is ineffective.

Also note that both `LocipoPlaylistIE` and `LocipoIE` will clear the cookiejar when they are initialized, so any cookies set during playlist extraction will be cleared again before the first video is extracted

Code after:
import functools
import math

from .streaks import StreaksBaseIE
from ..networking import HEADRequest
from ..utils import (
    InAdvancePagedList,
    clean_html,
    js_to_json,
    parse_iso8601,
    parse_qs,
    str_or_none,
)
from ..utils.traversal import require, traverse_obj


class LocipoBaseIE(StreaksBaseIE):
    _API_BASE = 'https://web-api.locipo.jp'
    _BASE_URL = 'https://locipo.jp'
    _UUID_RE = r'[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}'

    def _call_api(self, path, item_id, note, fatal=True):
        return self._download_json(
            f'{self._API_BASE}/{path}', item_id,
            f'Downloading {note} API JSON',
            f'Unable to download {note} API JSON',
            fatal=fatal)


class LocipoIE(LocipoBaseIE):
    _VALID_URL = [
        fr'https?://locipo\.jp/creative/(?P<id>{LocipoBaseIE._UUID_RE})',
        fr'https?://locipo\.jp/embed/?\?(?:[^#]+&)?id=(?P<id>{LocipoBaseIE._UUID_RE})',
    ]
    _TESTS = [{
        'url': 'https://locipo.jp/creative/fb5ffeaa-398d-45ce-bb49-0e221b5f94f1',
        'info_dict': {
            'id': 'fb5ffeaa-398d-45ce-bb49-0e221b5f94f1',
            'ext': 'mp4',
            'title': 'リアルカレカノ#4 ～伊達さゆりと勉強しよっ？～',
            'description': 'md5:70a40c202f3fb7946b61e55fa015094c',
            'display_id': '5a2947fe596441f5bab88a61b0432d0d',
            'live_status': 'not_live',
            'modified_date': r're:\d{8}',
            'modified_timestamp': int,
            'release_timestamp': 1711789200,
            'release_date': '20240330',
            'series': 'リアルカレカノ',