Repository: yt-dlp/yt-dlp

Issue:
[Broken] Pornhub playlist only download first 36 videos
<!--

######################################################################
  WARNING!
  IGNORING THE FOLLOWING TEMPLATE WILL RESULT IN ISSUE CLOSED AS INCOMPLETE
######################################################################

-->


## Checklist

- [ ✅] I'm reporting a broken site support
- [ ✅] I've verified that I'm running yt-dlp version **2021.08.10**
- [ ✅] I've checked that all provided URLs are alive and playable in a browser
- [ ✅] I've checked that all URLs and arguments with special characters are properly quoted or escaped
- [ ✅] I've searched the bugtracker for similar issues including closed ones


## Verbose log

<!--

-->

```
yt-dlp -v https://www.pornhub.com/playlist/95816161
[debug] Command-line config: ['-v', 'https://www.pornhub.com/playlist/95816161']
[debug] Encodings: locale cp1252, fs utf-8, out utf-8, pref cp1252
[debug] yt-dlp version 2021.08.10 (exe)
[debug] Python version 3.8.10 (CPython 64bit) - Windows-10-10.0.19042-SP0
[debug] exe versions: ffmpeg N-102564-g2261cc6d8a, ffprobe N-102564-g2261cc6d8a
[debug] Optional libraries: mutagen, pycryptodome, sqlite, websockets
[debug] Proxy map: {}
[debug] [PornHubPagedVideoList] Extracting URL: https://www.pornhub.com/playlist/95816161
[download] Downloading playlist: playlist/95816161
[PornHubPagedVideoList] playlist/95816161: Downloading page 1
[PornHubPagedVideoList] playlist playlist/95816161: Downloading 36 videos
[download] Downloading video 1 of 36
[debug] [PornHub] Extracting URL: http://www.pornhub.com/view_video.php?viewkey=ph5c0a6ab9a71b1&pkey=95816161
[PornHub] ph5c0a6ab9a71b1: Downloading pc webpage
[PornHub] ph5c0a6ab9a71b1: Downloading JSON metadata
[PornHub] ph5c0a6ab9a71b1: Downloading m3u8 information
[PornHub] ph5c0a6ab9a71b1: Downloading m3u8 information
[PornHub] ph5c0a6ab9a71b1: Downloading m3u8 information
[PornHub] ph5c0a6ab9a71b1: Downloading m3u8 information
[PornHub] ph5c0a6ab9a71b1: Downloading m3u8 information
```
<!--
Do not remove the above ```
-->


## Description

yt-dlp scrap only the first 36 videos from pornhub playlists, this issue on the youtube-dl as well, let's hope someone fix it on this fork.

Thanks


Discussion:
1 video isn't enough? haha JK
> 1 video Isn't enough? haha JK

Lots of videos and channels goes down everyday so it's better to backup them for educational purposes 😜

Resolving patch:
diff --git a/yt_dlp/extractor/extractors.py b/yt_dlp/extractor/extractors.py
--- a/yt_dlp/extractor/extractors.py
+++ b/yt_dlp/extractor/extractors.py
@@ -1044,6 +1044,7 @@
 from .pornhub import (
     PornHubIE,
     PornHubUserIE,
+    PornHubPlaylistIE,
     PornHubPagedVideoListIE,
     PornHubUserVideosUploadIE,
 )
diff --git a/yt_dlp/extractor/pornhub.py b/yt_dlp/extractor/pornhub.py
--- a/yt_dlp/extractor/pornhub.py
+++ b/yt_dlp/extractor/pornhub.py
@@ -3,6 +3,7 @@
 
 import functools
 import itertools
+import math
 import operator
 import re
 
@@ -638,7 +639,7 @@ def _real_extract(self, url):
 
 
 class PornHubPagedVideoListIE(PornHubPagedPlaylistBaseIE):
-    _VALID_URL = r'https?://(?:[^/]+\.)?%s/(?P<id>(?:[^/]+/)*[^/?#&]+)' % PornHubBaseIE._PORNHUB_HOST_RE
+    _VALID_URL = r'https?://(?:[^/]+\.)?%s/(?!playlist/)(?P<id>(?:[^/]+/)*[^/?#&]+)' % PornHubBaseIE._PORNHUB_HOST_RE
     _TESTS = [{
         'url': 'https://www.pornhub.com/model/zoe_ph/videos',
         'only_matching': True,
@@ -731,18 +732,6 @@ class PornHubPagedVideoListIE(PornHubPagedPlaylistBaseIE):
     }, {
         'url': 'https://www.pornhub.com/video/incategories/60fps-1/hd-porn',
         'only_matching': True,
-    }, {
-        'url': 'https://www.pornhub.com/playlist/44121572',
-        'info_dict': {
-            'id': 'playlist/44121572',
-        },
-        'playlist_mincount': 132,
-    }, {
-        'url': 'https://www.pornhub.com/playlist/4667351',
-        'only_matching': True,
-    }, {
-        'url': 'https://de.pornhub.com/playlist/4667351',
-        'only_matching': True,
     }, {
         'url': 'https://pornhubthbh7ap3u.onion/model/zoe_ph/videos',
         'only_matching': True,
@@ -770,3 +759,59 @@ class PornHubUserVideosUploadIE(PornHubPagedPlaylistBaseIE):
         'url': 'http://pornhubthbh7ap3u.onion/pornstar/jenny-blighe/videos/upload',
         'only_matching': True,
     }]
+
+
+class PornHubPlaylistIE(PornHubPlaylistBaseIE):
+    _VALID_URL = r'(?P<url>https?://(?:[^/]+\.)?%s/playlist/(?P<id>[^/?#&]+))' % PornHubBaseIE._PORNHUB_HOST_RE
+    _TESTS = [{
+        'url': 'https://www.pornhub.com/playlist/44121572',
+        'info_dict': {
+            'id': '44121572',
+        },
+        'playlist_count': 77,
+    }, {
+        'url': 'https://www.pornhub.com/playlist/4667351',
+        'only_matching': True,
+    }, {
+        'url': 'https://de.pornhub.com/playlist/4667351',
+        'only_matching': True,
+    }, {
+        'url': 'https://de.pornhub.com/playlist/4667351?page=2',
+        'only_matching': True,
+    }]
+
+    def _entries(self, url, host, item_id):
+        webpage = self._download_webpage(url, item_id, 'Downloading page 1')
+        playlist_id = self._search_regex(r'var\s+playlistId\s*=\s*"([^"]+)"', webpage, 'playlist_id')
+        video_count = int_or_none(
+            self._search_regex(r'var\s+itemsCount\s*=\s*([0-9]+)\s*\|\|', webpage, 'video_count'))
+        token = self._search_regex(r'var\s+token\s*=\s*"([^"]+)"', webpage, 'token')
+        page_count = math.ceil((video_count - 36) / 40.) + 1
+        page_entries = self._extract_entries(webpage, host)
+
+        def download_page(page_num):
+            note = 'Downloading page {}'.format(page_num)
+            page_url = 'https://www.{}/playlist/viewChunked'.format(host)
+            return self._download_webpage(page_url, item_id, note, query={
+                'id': playlist_id,
+                'page': page_num,
+                'token': token,
+            })
+
+        for page_num in range(1, page_count + 1):
+            if page_num > 1:
+                webpage = download_page(page_num)
+                page_entries = self._extract_entries(webpage, host)
+            if not page_entries:
+                break
+            for e in page_entries:
+                yield e
+
+    def _real_extract(self, url):
+        mobj = re.match(self._VALID_URL, url)
+        host = mobj.group('host')
+        item_id = mobj.group('id')
+
+        self._login(host)
+
+        return self.playlist_result(self._entries(mobj.group('url'), host, item_id), item_id)


Test patch: