diff options
| author | 2025-07-31 01:22:01 -0400 | |
|---|---|---|
| committer | 2025-07-31 01:22:01 -0400 | |
| commit | a6e995c093de8aae2e91a0787281bb34c0b871eb (patch) | |
| tree | 2d79821b05300d34d8871eb6c9662b359a2de85d /gallery_dl/extractor/pornhub.py | |
| parent | 7672a750cb74bf31e21d76aad2776367fd476155 (diff) | |
New upstream version 1.30.2.upstream/1.30.2
Diffstat (limited to 'gallery_dl/extractor/pornhub.py')
| -rw-r--r-- | gallery_dl/extractor/pornhub.py | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/gallery_dl/extractor/pornhub.py b/gallery_dl/extractor/pornhub.py index 9800eb2..1211397 100644 --- a/gallery_dl/extractor/pornhub.py +++ b/gallery_dl/extractor/pornhub.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2019-2023 Mike Fährmann +# Copyright 2019-2025 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -8,7 +8,7 @@ """Extractors for https://www.pornhub.com/""" -from .common import Extractor, Message +from .common import Extractor, Message, Dispatch from .. import text, exception BASE_PATTERN = r"(?:https?://)?(?:[\w-]+\.)?pornhub\.com" @@ -27,7 +27,7 @@ class PornhubExtractor(Extractor): if "/" not in path: path += "/public" - url = "{}/{}/{}/ajax".format(self.root, user, path) + url = f"{self.root}/{user}/{path}/ajax" params = {"page": 1} headers = { "Referer": url[:-5], @@ -40,8 +40,7 @@ class PornhubExtractor(Extractor): allow_redirects=False) if 300 <= response.status_code < 400: - url = "{}{}/{}/ajax".format( - self.root, response.headers["location"], path) + url = f"{self.root}{response.headers['location']}/{path}/ajax" continue yield response.text @@ -60,7 +59,7 @@ class PornhubGalleryExtractor(PornhubExtractor): def __init__(self, match): PornhubExtractor.__init__(self, match) - self.gallery_id = match.group(1) + self.gallery_id = match[1] self._first = None def items(self): @@ -82,11 +81,11 @@ class PornhubGalleryExtractor(PornhubExtractor): yield Message.Url, url, text.nameext_from_url(url, image) def metadata(self): - url = "{}/album/{}".format( - self.root, self.gallery_id) + url = f"{self.root}/album/{self.gallery_id}" extr = text.extract_from(self.request(url).text) title = extr("<title>", "</title>") + self._token = extr('name="token" value="', '"') score = extr('<div id="albumGreenBar" style="width:', '"') views = extr('<div id="viewsPhotAlbumCounter">', '<') tags = extr('<div id="photoTagsBox"', '<script') @@ -105,13 +104,12 @@ class PornhubGalleryExtractor(PornhubExtractor): } def images(self): - url = "{}/album/show_album_json?album={}".format( - self.root, self.gallery_id) - response = self.request(url) + url = f"{self.root}/api/v1/album/{self.gallery_id}/show_album_json" + params = {"token": self._token} + data = self.request_json(url, params=params) - if response.content == b"Permission denied": + if not (images := data.get("photos")): raise exception.AuthorizationError() - images = response.json() key = end = self._first results = [] @@ -141,10 +139,10 @@ class PornhubGifExtractor(PornhubExtractor): def __init__(self, match): PornhubExtractor.__init__(self, match) - self.gallery_id = match.group(1) + self.gallery_id = match[1] def items(self): - url = "{}/gif/{}".format(self.root, self.gallery_id) + url = f"{self.root}/gif/{self.gallery_id}" extr = text.extract_from(self.request(url).text) gif = { @@ -164,21 +162,13 @@ class PornhubGifExtractor(PornhubExtractor): yield Message.Url, gif["url"], text.nameext_from_url(gif["url"], gif) -class PornhubUserExtractor(PornhubExtractor): +class PornhubUserExtractor(Dispatch, PornhubExtractor): """Extractor for a pornhub user""" - subcategory = "user" pattern = BASE_PATTERN + r"/((?:users|model|pornstar)/[^/?#]+)/?$" example = "https://www.pornhub.com/model/USER" - def __init__(self, match): - PornhubExtractor.__init__(self, match) - self.user = match.group(1) - - def initialize(self): - pass - def items(self): - base = "{}/{}/".format(self.root, self.user) + base = f"{self.root}/{self.groups[0]}/" return self._dispatch_extractors(( (PornhubPhotosExtractor, base + "photos"), (PornhubGifsExtractor , base + "gifs"), |
