Repository: yt-dlp/yt-dlp

Issue:
[Bitchute] Playlist unrecognized
### Checklist

- [X] I'm reporting a broken site
- [X] I've verified that I'm running yt-dlp version **2022.02.04**. ([update instructions](https://github.com/yt-dlp/yt-dlp#update))
- [X] I've checked that all provided URLs are alive and playable in a browser
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/ytdl-org/youtube-dl#video-url-contains-an-ampersand-and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [X] I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues including closed ones. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
- [X] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required

### Region

Norway

### Description

https://www.bitchute.com/playlist/wV9Imujxasw9/

Unsupported url yt-dlp tells me.

(Verbose log shown with both the -v and -vU options below. The instructions here says to use -vU but that output looks less informative than the former.)

I also tried `yt-dlp --write-description --yes-playlist https://www.bitchute.com/video/yvvNqLcWePrk/?list=wV9Imujxasw9&randomize=false` going off the first video on the playlist, but only that one video got downloaded.

### Verbose log

```shell
$ yt-dlp -v --write-description https://www.bitchute.com/playlist/wV9Imujxasw9/
[debug] Command-line config: ['-v', '--write-description', 'https://www.bitchute.com/playlist/wV9Imujxasw9/']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, err utf-8, pref UTF-8
[debug] yt-dlp version 2022.02.04 [c1653e9ef]
[debug] Python version 3.8.10 (CPython 64bit) - Linux-5.4.0-99-generic-x86_64-with-glibc2.29
[debug] exe versions: ffmpeg 4.2.4, ffprobe 4.2.4, rtmpdump 2.4
[debug] Optional libraries: Cryptodome, secretstorage, mutagen, sqlite, websockets
[debug] Proxy map: {}
[debug] [generic] Extracting URL: https://www.bitchute.com/playlist/wV9Imujxasw9/
[generic] wV9Imujxasw9: Requesting header
WARNING: [generic] Falling back on generic information extractor.
[generic] wV9Imujxasw9: Downloading webpage
[generic] wV9Imujxasw9: Extracting information
[debug] Looking for video embeds
ERROR: Unsupported URL: https://www.bitchute.com/playlist/wV9Imujxasw9/
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/yt_dlp/YoutubeDL.py", line 1381, in wrapper
    return func(self, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/yt_dlp/YoutubeDL.py", line 1451, in __extract_info
    ie_result = ie.extract(url)
  File "/usr/lib/python3/dist-packages/yt_dlp/extractor/common.py", line 612, in extract
    ie_result = self._real_extract(url)
  File "/usr/lib/python3/dist-packages/yt_dlp/extractor/generic.py", line 3986, in _real_extract
    raise UnsupportedError(url)
yt_dlp.utils.UnsupportedError: Unsupported URL: https://www.bitchute.com/playlist/wV9Imujxasw9/


yt-dlp -vU --write-description https://www.bitchute.com/playlist/wV9Imujxasw9/
[debug] Command-line config: ['-vU', '--write-description', 'https://www.bitchute.com/playlist/wV9Imujxasw9/']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, err utf-8, pref UTF-8
[debug] yt-dlp version 2022.02.04 [c1653e9ef]
[debug] Python version 3.8.10 (CPython 64bit) - Linux-5.4.0-99-generic-x86_64-with-glibc2.29
[debug] exe versions: ffmpeg 4.2.4, ffprobe 4.2.4, rtmpdump 2.4
[debug] Optional libraries: Cryptodome, secretstorage, mutagen, sqlite, websockets
[debug] Proxy map: {}
Usage: yt-dlp [OPTIONS] URL [URL...]

yt-dlp: error: yt-dlp's self-update mechanism is disabled on Debian.
Please update yt-dlp using apt(8).
See https://packages.debian.org/sid/yt-dlp for the latest packaged version.
```



Discussion:

Resolving patch:
diff --git a/yt_dlp/extractor/bitchute.py b/yt_dlp/extractor/bitchute.py
--- a/yt_dlp/extractor/bitchute.py
+++ b/yt_dlp/extractor/bitchute.py
@@ -1,14 +1,18 @@
-import itertools
+import functools
 import re
 
 from .common import InfoExtractor
 from ..utils import (
     ExtractorError,
     HEADRequest,
+    OnDemandPagedList,
     clean_html,
     get_element_by_class,
+    get_elements_html_by_class,
     int_or_none,
     orderedSet,
+    parse_count,
+    parse_duration,
     traverse_obj,
     unified_strdate,
     urlencode_postdata,
@@ -109,51 +113,103 @@ def _real_extract(self, url):
 
 
 class BitChuteChannelIE(InfoExtractor):
-    _VALID_URL = r'https?://(?:www\.)?bitchute\.com/channel/(?P<id>[^/?#&]+)'
-    _TEST = {
-        'url': 'https://www.bitchute.com/channel/victoriaxrave/',
-        'playlist_mincount': 185,
+    _VALID_URL = r'https?://(?:www\.)?bitchute\.com/(?P<type>channel|playlist)/(?P<id>[^/?#&]+)'
+    _TESTS = [{
+        'url': 'https://www.bitchute.com/channel/bitchute/',
         'info_dict': {
-            'id': 'victoriaxrave',
+            'id': 'bitchute',
+            'title': 'BitChute',
+            'description': 'md5:5329fb3866125afa9446835594a9b138',
         },
-    }
+        'playlist': [
+            {
+                'md5': '7e427d7ed7af5a75b5855705ec750e2b',
+                'info_dict': {
+                    'id': 'UGlrF9o9b-Q',
+                    'ext': 'mp4',
+                    'filesize': None,
+                    'title': 'This is the first video on #BitChute !',
+                    'description': 'md5:a0337e7b1fe39e32336974af8173a034',
+                    'thumbnail': r're:^https?://.*\.jpg$',
+                    'uploader': 'BitChute',
+                    'upload_date': '20170103',
+                    'duration': 16,
+                    'view_count': int,
+                },
+            }
+        ],
+        'params': {
+            'skip_download': True,
+            'playlist_items': '-1',
+        },
+    }, {
+        'url': 'https://www.bitchute.com/playlist/wV9Imujxasw9/',
+        'playlist_mincount': 20,
+        'info_dict': {
+            'id': 'wV9Imujxasw9',
+            'title': 'Bruce MacDonald and "The Light of Darkness"',
+            'description': 'md5:04913227d2714af1d36d804aa2ab6b1e',
+        }
+    }]
 
     _TOKEN = 'zyG6tQcGPE5swyAEFLqKUwMuMMuF6IO2DZ6ZDQjGfsL0e4dcTLwqkTTul05Jdve7'
+    PAGE_SIZE = 25
+    HTML_CLASS_NAMES = {
+        'channel': {
+            'container': 'channel-videos-container',
+            'title': 'channel-videos-title',
+            'description': 'channel-videos-text',
+        },
+        'playlist': {
+            'container': 'playlist-video',
+            'title': 'title',
+            'description': 'description',
+        }
+
+    }
 
-    def _entries(self, channel_id):
-        channel_url = 'https://www.bitchute.com/channel/%s/' % channel_id
-        offset = 0
-        for page_num in itertools.count(1):
-            data = self._download_json(
-                '%sextend/' % channel_url, channel_id,
-                'Downloading channel page %d' % page_num,
-                data=urlencode_postdata({
-                    'csrfmiddlewaretoken': self._TOKEN,
-                    'name': '',
-                    'offset': offset,
-                }), headers={
-                    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
-                    'Referer': channel_url,
-                    'X-Requested-With': 'XMLHttpRequest',
-                    'Cookie': 'csrftoken=%s' % self._TOKEN,
-                })
-            if data.get('success') is False:
-                break
-            html = data.get('html')
-            if not html:
-                break
-            video_ids = re.findall(
-                r'class=["\']channel-videos-image-container[^>]+>\s*<a\b[^>]+\bhref=["\']/video/([^"\'/]+)',
-                html)
-            if not video_ids:
-                break
-            offset += len(video_ids)
-            for video_id in video_ids:
-                yield self.url_result(
-                    'https://www.bitchute.com/video/%s' % video_id,
-                    ie=BitChuteIE.ie_key(), video_id=video_id)
+    @staticmethod
+    def _make_url(playlist_id, playlist_type):
+        return f'https://www.bitchute.com/{playlist_type}/{playlist_id}/'
+
+    def _fetch_page(self, playlist_id, playlist_type, page_num):
+        playlist_url = self._make_url(playlist_id, playlist_type)
+        data = self._download_json(
+            f'{playlist_url}extend/', playlist_id, f'Downloading page {page_num}',
+            data=urlencode_postdata({
+                'csrfmiddlewaretoken': self._TOKEN,
+                'name': '',
+                'offset': page_num * self.PAGE_SIZE,
+            }), headers={
+                'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
+                'Referer': playlist_url,
+                'X-Requested-With': 'XMLHttpRequest',
+                'Cookie': f'csrftoken={self._TOKEN}',
+            })
+        if not data.get('success'):
+            return
+        classes = self.HTML_CLASS_NAMES[playlist_type]
+        for video_html in get_elements_html_by_class(classes['container'], data.get('html')):
+            video_id = self._search_regex(
+                r'<a\s[^>]*\bhref=["\']/video/([^"\'/]+)', video_html, 'video id', default=None)
+            if not video_id:
+                continue
+            yield self.url_result(
+                f'https://www.bitchute.com/video/{video_id}', BitChuteIE, video_id, url_transparent=True,
+                title=clean_html(get_element_by_class(classes['title'], video_html)),
+                description=clean_html(get_element_by_class(classes['description'], video_html)),
+                duration=parse_duration(get_element_by_class('video-duration', video_html)),
+                view_count=parse_count(clean_html(get_element_by_class('video-views', video_html))))
 
     def _real_extract(self, url):
-        channel_id = self._match_id(url)
+        playlist_type, playlist_id = self._match_valid_url(url).group('type', 'id')
+        webpage = self._download_webpage(self._make_url(playlist_id, playlist_type), playlist_id)
+
+        page_func = functools.partial(self._fetch_page, playlist_id, playlist_type)
         return self.playlist_result(
-            self._entries(channel_id), playlist_id=channel_id)
+            OnDemandPagedList(page_func, self.PAGE_SIZE), playlist_id,
+            title=self._html_extract_title(webpage, default=None),
+            description=self._html_search_meta(
+                ('description', 'og:description', 'twitter:description'), webpage, default=None),
+            playlist_count=int_or_none(self._html_search_regex(
+                r'<span>(\d+)\s+videos?</span>', webpage, 'playlist count', default=None)))
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py
--- a/yt_dlp/utils.py
+++ b/yt_dlp/utils.py
@@ -413,6 +413,8 @@ def get_elements_text_and_html_by_attribute(attribute, value, html, *, tag=r'[\w
     Return the text (content) and the html (whole) of the tag with the specified
     attribute in the passed HTML document
     """
+    if not value:
+        return
 
     quote = '' if re.match(r'''[\s"'`=<>]''', value) else '?'
 


Test patch: