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

Code before:
        result = self._call_api_proxy(
            'claim_search', claim_ids, page_params, 'page %d' % page)
        for item in (result.get('items') or []):
            stream_claim_name = item.get('name')
            stream_claim_id = item.get('claim_id')
            if not (stream_claim_name and stream_claim_id):
                continue

            yield {
                **self._parse_stream(item, url),
                '_type': 'url',
                'id': stream_claim_id,
                'url': self._permanent_url(url, stream_claim_name, stream_claim_id),
            }

    def _fetch_playlist_items(self, claim_id):
        page_params = {
            'claim_ids': [claim_id],
            'no_totals': True,
            'page': 1,
            'page_size': self._PAGE_SIZE,
        }
        return self._call_api_proxy('claim_search', claim_id, page_params, 'playlist')

    def _real_extract(self, url):
        if playlist_id := self._match_valid_url(url).group('id2'):
            is_playlist = True
            r = self._fetch_playlist_items(playlist_id)
            result = r.get('items', [])[0]
            claim_ids = result.get('value', {}).get('claims', [])
        else:
            is_playlist = False
            display_id = self._match_id(url).replace(':', '#')
            result = self._resolve_url(
                'lbry://' + display_id, display_id, 'channel')
            claim_ids = [result['claim_id']]
        qs = parse_qs(url)
        content = qs.get('content', [None])[0]
        params = {
            'fee_amount': qs.get('fee_amount', ['>=0'])[0],
            'order_by': {
                'new': ['release_time'],
                'top': ['effective_amount'],
                'trending': ['trending_group', 'trending_mixed'],
            }[qs.get('order', ['new'])[0]],
            'claim_type': 'stream',
            'claim_ids' if is_playlist else 'channel_ids': claim_ids,
            'stream_types': [content] if content in ['audio', 'video'] else self._SUPPORTED_STREAM_TYPES,
        }
        duration = qs.get('duration', [None])[0]
        if duration:

Review comment (suggestion):
```suggestion
        playlist_id = self._match_valid_url(url).group('id2')
        if playlist_id:
```

Code after:
                'https://api.odysee.live/livestream/is_live', claim_id,
                query={'channel_claim_id': claim_id},
                note='Downloading livestream JSON metadata')['data']
            final_url = live_data.get('VideoURL')
            # Upcoming videos may still give VideoURL
            if not live_data.get('Live'):
                final_url = None
                self.raise_no_formats('This stream is not live', True, claim_id)

        else:
            raise UnsupportedError(url)

        if determine_ext(final_url) == 'm3u8':
            formats.extend(self._extract_m3u8_formats(
                final_url, display_id, 'mp4', m3u8_id='hls', live=is_live, headers=headers))

        return {
            **self._parse_stream(result, url),
            'id': claim_id,
            'formats': formats,
            'is_live': is_live,
            'http_headers': headers,
        }


class LBRYChannelIE(LBRYBaseIE):
    IE_NAME = 'lbry:channel'
    _VALID_URL = LBRYBaseIE._BASE_URL_REGEX + rf'(?P<id>@{LBRYBaseIE._OPT_CLAIM_ID})/?(?:[?&]|$)'
    _TESTS = [{
        'url': 'https://lbry.tv/@LBRYFoundation:0',
        'info_dict': {
            'id': '0ed629d2b9c601300cacf7eabe9da0be79010212',
            'title': 'The LBRY Foundation',
            'description': 'Channel for the LBRY Foundation. Follow for updates and news.',
        },
        'playlist_mincount': 29,
    }, {
        'url': 'https://lbry.tv/@LBRYFoundation',
        'only_matching': True,
    }, {
        'url': 'lbry://@lbry#3f',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        display_id = self._match_id(url).replace(':', '#')
        result = self._resolve_url(f'lbry://{display_id}', display_id, 'channel')
        claim_id = result['claim_id']

        return self._playlist_entries(url, claim_id, {'channel_ids': [claim_id]}, result)