1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 18:53:21 +01:00

[500px] add 'favorite' extractor (closes #1927)

This commit is contained in:
Mike Fährmann 2021-12-25 02:12:55 +01:00
parent 22b0433985
commit 89bebe1bef
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 157 additions and 5 deletions

View File

@ -40,7 +40,7 @@ Consider all sites to be NSFW unless otherwise known.
<tr>
<td>500px</td>
<td>https://500px.com/</td>
<td>Galleries, individual Images, User Profiles</td>
<td>Favorites, Galleries, individual Images, User Profiles</td>
<td></td>
</tr>
<tr>

View File

@ -21,6 +21,7 @@ class _500pxExtractor(Extractor):
filename_fmt = "{id}_{name}.{extension}"
archive_fmt = "{id}"
root = "https://500px.com"
cookiedomain = ".500px.com"
def __init__(self, match):
Extractor.__init__(self, match)
@ -72,24 +73,33 @@ class _500pxExtractor(Extractor):
self.log.warning("Unable to fetch photo %s", pid)
]
def _request_api(self, url, params, csrf_token=None):
headers = {"Origin": self.root, "X-CSRF-Token": csrf_token}
def _request_api(self, url, params):
headers = {
"Origin": self.root,
"x-csrf-token": self.session.cookies.get(
"x-csrf-token", domain=".500px.com"),
}
return self.request(url, headers=headers, params=params).json()
def _request_graphql(self, opname, variables):
url = "https://api.500px.com/graphql"
headers = {
"x-csrf-token": self.session.cookies.get(
"x-csrf-token", domain=".500px.com"),
}
data = {
"operationName": opname,
"variables" : json.dumps(variables),
"query" : QUERIES[opname],
}
return self.request(url, method="POST", json=data).json()["data"]
return self.request(
url, method="POST", headers=headers, json=data).json()["data"]
class _500pxUserExtractor(_500pxExtractor):
"""Extractor for photos from a user's photostream on 500px.com"""
subcategory = "user"
pattern = BASE_PATTERN + r"/(?!photo/)(?:p/)?([^/?#]+)/?(?:$|[?#])"
pattern = BASE_PATTERN + r"/(?!photo/|liked)(?:p/)?([^/?#]+)/?(?:$|[?#])"
test = (
("https://500px.com/p/light_expression_photography", {
"pattern": r"https?://drscdn.500px.org/photo/\d+/m%3D4096/v2",
@ -194,6 +204,30 @@ class _500pxGalleryExtractor(_500pxExtractor):
)["galleryByOwnerIdAndSlugOrToken"]["photos"]
class _500pxFavoriteExtractor(_500pxExtractor):
"""Extractor for favorite 500px photos"""
subcategory = "favorite"
pattern = BASE_PATTERN + r"/liked/?$"
test = ("https://500px.com/liked",)
def photos(self):
variables = {"pageSize": 20}
photos = self._request_graphql(
"LikedPhotosQueryRendererQuery", variables,
)["likedPhotos"]
while True:
yield from self._extend(photos["edges"])
if not photos["pageInfo"]["hasNextPage"]:
return
variables["cursor"] = photos["pageInfo"]["endCursor"]
photos = self._request_graphql(
"LikedPhotosPaginationContainerQuery", variables,
)["likedPhotos"]
class _500pxImageExtractor(_500pxExtractor):
"""Extractor for individual images from 500px.com"""
subcategory = "image"
@ -638,6 +672,124 @@ fragment GalleriesDetailPaginationContainer_gallery_3e6UuE on Gallery {
}
}
}
""",
"LikedPhotosQueryRendererQuery": """\
query LikedPhotosQueryRendererQuery($pageSize: Int) {
...LikedPhotosPaginationContainer_query_RlXb8
}
fragment LikedPhotosPaginationContainer_query_RlXb8 on Query {
likedPhotos(first: $pageSize) {
edges {
node {
id
legacyId
canonicalPath
name
description
category
uploadedAt
location
width
height
isLikedByMe
notSafeForWork
tags
photographer: uploader {
id
legacyId
username
displayName
canonicalPath
avatar {
images {
url
id
}
id
}
followedByUsers {
totalCount
isFollowedByMe
}
}
images(sizes: [33, 35]) {
size
url
jpegUrl
webpUrl
id
}
__typename
}
cursor
}
pageInfo {
endCursor
hasNextPage
}
}
}
""",
"LikedPhotosPaginationContainerQuery": """\
query LikedPhotosPaginationContainerQuery($cursor: String, $pageSize: Int) {
...LikedPhotosPaginationContainer_query_3e6UuE
}
fragment LikedPhotosPaginationContainer_query_3e6UuE on Query {
likedPhotos(first: $pageSize, after: $cursor) {
edges {
node {
id
legacyId
canonicalPath
name
description
category
uploadedAt
location
width
height
isLikedByMe
notSafeForWork
tags
photographer: uploader {
id
legacyId
username
displayName
canonicalPath
avatar {
images {
url
id
}
id
}
followedByUsers {
totalCount
isFollowedByMe
}
}
images(sizes: [33, 35]) {
size
url
jpegUrl
webpUrl
id
}
__typename
}
cursor
}
pageInfo {
endCursor
hasNextPage
}
}
}
""",
}