[patreon] fix campaign_id extraction from Next.js 13 creator pages (#7773)
This commit is contained in:
@@ -315,7 +315,7 @@ class PatreonCreatorExtractor(PatreonExtractor):
|
||||
pattern = (r"(?:https?://)?(?:www\.)?patreon\.com"
|
||||
r"/(?!(?:home|create|login|signup|search|posts|messages)"
|
||||
r"(?:$|[/?#]))"
|
||||
r"(?:profile/creators|(?:c/)?([^/?#]+)(?:/posts)?)"
|
||||
r"(?:profile/creators|(?:cw?/)?([^/?#]+)(?:/posts)?)"
|
||||
r"/?(?:\?([^#]+))?")
|
||||
example = "https://www.patreon.com/c/USER"
|
||||
|
||||
@@ -354,6 +354,8 @@ class PatreonCreatorExtractor(PatreonExtractor):
|
||||
data = None
|
||||
data = self._extract_bootstrap(page)
|
||||
return data["campaign"]["data"]["id"]
|
||||
except exception.StopExtraction:
|
||||
pass
|
||||
except Exception as exc:
|
||||
if data:
|
||||
self.log.debug(data)
|
||||
@@ -361,6 +363,13 @@ class PatreonCreatorExtractor(PatreonExtractor):
|
||||
"Unable to extract campaign ID (%s: %s)",
|
||||
exc.__class__.__name__, exc)
|
||||
|
||||
# Next.js 13
|
||||
if cid := text.extr(
|
||||
page, r'{\"value\":{\"campaign\":{\"data\":{\"id\":\"', '\\"'):
|
||||
return cid
|
||||
|
||||
raise exception.StopExtraction("Failed to extract campaign ID")
|
||||
|
||||
def _get_filters(self, query):
|
||||
return "".join(
|
||||
f"&filter[{key[8:]}={text.escape(value)}"
|
||||
|
||||
@@ -44,6 +44,12 @@ __tests__ = (
|
||||
"#exception": exception.NotFoundError,
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://www.patreon.com/cw/anythingelse",
|
||||
"#comment" : "Next.js 13 - /cw/ URL",
|
||||
"#class" : patreon.PatreonCreatorExtractor,
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://www.patreon.com/c/koveliana",
|
||||
"#class" : patreon.PatreonCreatorExtractor,
|
||||
@@ -149,7 +155,7 @@ __tests__ = (
|
||||
"offers_free_membership": True,
|
||||
"offers_paid_membership": True,
|
||||
"pay_per_name": "month",
|
||||
"pledge_url": "/checkout/Reedandweep",
|
||||
"pledge_url": "https://www.patreon.com/checkout/Reedandweep",
|
||||
"primary_theme_color": None,
|
||||
"show_audio_post_download_links": True,
|
||||
"show_free_membership_cta": False,
|
||||
|
||||
Reference in New Issue
Block a user