[deviantart] adjust API endpoints

Start all endpoints with a forward slash '/'
to be consistent with other API interfaces.
This commit is contained in:
Mike Fährmann
2021-12-21 00:18:06 +01:00
parent 8f0cf0bf71
commit d441888bfb

View File

@@ -1037,21 +1037,21 @@ class DeviantartOAuthAPI():
def browse_deviantsyouwatch(self, offset=0): def browse_deviantsyouwatch(self, offset=0):
"""Yield deviations from users you watch""" """Yield deviations from users you watch"""
endpoint = "browse/deviantsyouwatch" endpoint = "/browse/deviantsyouwatch"
params = {"limit": "50", "offset": offset, params = {"limit": "50", "offset": offset,
"mature_content": self.mature} "mature_content": self.mature}
return self._pagination(endpoint, params, public=False) return self._pagination(endpoint, params, public=False)
def browse_posts_deviantsyouwatch(self, offset=0): def browse_posts_deviantsyouwatch(self, offset=0):
"""Yield posts from users you watch""" """Yield posts from users you watch"""
endpoint = "browse/posts/deviantsyouwatch" endpoint = "/browse/posts/deviantsyouwatch"
params = {"limit": "50", "offset": offset, params = {"limit": "50", "offset": offset,
"mature_content": self.mature} "mature_content": self.mature}
return self._pagination(endpoint, params, public=False, unpack=True) return self._pagination(endpoint, params, public=False, unpack=True)
def browse_newest(self, query=None, offset=0): def browse_newest(self, query=None, offset=0):
"""Browse newest deviations""" """Browse newest deviations"""
endpoint = "browse/newest" endpoint = "/browse/newest"
params = { params = {
"q" : query, "q" : query,
"limit" : 50 if self.metadata else 120, "limit" : 50 if self.metadata else 120,
@@ -1062,7 +1062,7 @@ class DeviantartOAuthAPI():
def browse_popular(self, query=None, timerange=None, offset=0): def browse_popular(self, query=None, timerange=None, offset=0):
"""Yield popular deviations""" """Yield popular deviations"""
endpoint = "browse/popular" endpoint = "/browse/popular"
params = { params = {
"q" : query, "q" : query,
"limit" : 50 if self.metadata else 120, "limit" : 50 if self.metadata else 120,
@@ -1074,7 +1074,7 @@ class DeviantartOAuthAPI():
def browse_tags(self, tag, offset=0): def browse_tags(self, tag, offset=0):
""" Browse a tag """ """ Browse a tag """
endpoint = "browse/tags" endpoint = "/browse/tags"
params = { params = {
"tag" : tag, "tag" : tag,
"offset" : offset, "offset" : offset,
@@ -1085,14 +1085,14 @@ class DeviantartOAuthAPI():
def browse_user_journals(self, username, offset=0): def browse_user_journals(self, username, offset=0):
"""Yield all journal entries of a specific user""" """Yield all journal entries of a specific user"""
endpoint = "browse/user/journals" endpoint = "/browse/user/journals"
params = {"username": username, "offset": offset, "limit": 50, params = {"username": username, "offset": offset, "limit": 50,
"mature_content": self.mature, "featured": "false"} "mature_content": self.mature, "featured": "false"}
return self._pagination(endpoint, params) return self._pagination(endpoint, params)
def collections(self, username, folder_id, offset=0): def collections(self, username, folder_id, offset=0):
"""Yield all Deviation-objects contained in a collection folder""" """Yield all Deviation-objects contained in a collection folder"""
endpoint = "collections/" + folder_id endpoint = "/collections/" + folder_id
params = {"username": username, "offset": offset, "limit": 24, params = {"username": username, "offset": offset, "limit": 24,
"mature_content": self.mature} "mature_content": self.mature}
return self._pagination(endpoint, params) return self._pagination(endpoint, params)
@@ -1100,21 +1100,21 @@ class DeviantartOAuthAPI():
@memcache(keyarg=1) @memcache(keyarg=1)
def collections_folders(self, username, offset=0): def collections_folders(self, username, offset=0):
"""Yield all collection folders of a specific user""" """Yield all collection folders of a specific user"""
endpoint = "collections/folders" endpoint = "/collections/folders"
params = {"username": username, "offset": offset, "limit": 50, params = {"username": username, "offset": offset, "limit": 50,
"mature_content": self.mature} "mature_content": self.mature}
return self._pagination_list(endpoint, params) return self._pagination_list(endpoint, params)
def comments_deviation(self, deviation_id, offset=0): def comments_deviation(self, deviation_id, offset=0):
"""Fetch comments posted on a deviation""" """Fetch comments posted on a deviation"""
endpoint = "comments/deviation/" + deviation_id endpoint = "/comments/deviation/" + deviation_id
params = {"maxdepth": "5", "offset": offset, "limit": 50, params = {"maxdepth": "5", "offset": offset, "limit": 50,
"mature_content": self.mature} "mature_content": self.mature}
return self._pagination_list(endpoint, params=params, key="thread") return self._pagination_list(endpoint, params=params, key="thread")
def deviation(self, deviation_id, public=True): def deviation(self, deviation_id, public=True):
"""Query and return info about a single Deviation""" """Query and return info about a single Deviation"""
endpoint = "deviation/" + deviation_id endpoint = "/deviation/" + deviation_id
deviation = self._call(endpoint, public=public) deviation = self._call(endpoint, public=public)
if self.metadata: if self.metadata:
self._metadata((deviation,)) self._metadata((deviation,))
@@ -1124,13 +1124,13 @@ class DeviantartOAuthAPI():
def deviation_content(self, deviation_id, public=False): def deviation_content(self, deviation_id, public=False):
"""Get extended content of a single Deviation""" """Get extended content of a single Deviation"""
endpoint = "deviation/content" endpoint = "/deviation/content"
params = {"deviationid": deviation_id} params = {"deviationid": deviation_id}
return self._call(endpoint, params=params, public=public) return self._call(endpoint, params=params, public=public)
def deviation_download(self, deviation_id, public=True): def deviation_download(self, deviation_id, public=True):
"""Get the original file download (if allowed)""" """Get the original file download (if allowed)"""
endpoint = "deviation/download/" + deviation_id endpoint = "/deviation/download/" + deviation_id
params = {"mature_content": self.mature} params = {"mature_content": self.mature}
return self._call(endpoint, params=params, public=public) return self._call(endpoint, params=params, public=public)
@@ -1138,7 +1138,7 @@ class DeviantartOAuthAPI():
""" Fetch deviation metadata for a set of deviations""" """ Fetch deviation metadata for a set of deviations"""
if not deviations: if not deviations:
return [] return []
endpoint = "deviation/metadata?" + "&".join( endpoint = "/deviation/metadata?" + "&".join(
"deviationids[{}]={}".format(num, deviation["deviationid"]) "deviationids[{}]={}".format(num, deviation["deviationid"])
for num, deviation in enumerate(deviations) for num, deviation in enumerate(deviations)
) )
@@ -1147,14 +1147,14 @@ class DeviantartOAuthAPI():
def gallery(self, username, folder_id, offset=0, extend=True, public=True): def gallery(self, username, folder_id, offset=0, extend=True, public=True):
"""Yield all Deviation-objects contained in a gallery folder""" """Yield all Deviation-objects contained in a gallery folder"""
endpoint = "gallery/" + folder_id endpoint = "/gallery/" + folder_id
params = {"username": username, "offset": offset, "limit": 24, params = {"username": username, "offset": offset, "limit": 24,
"mature_content": self.mature, "mode": "newest"} "mature_content": self.mature, "mode": "newest"}
return self._pagination(endpoint, params, extend, public) return self._pagination(endpoint, params, extend, public)
def gallery_all(self, username, offset=0): def gallery_all(self, username, offset=0):
"""Yield all Deviation-objects of a specific user""" """Yield all Deviation-objects of a specific user"""
endpoint = "gallery/all" endpoint = "/gallery/all"
params = {"username": username, "offset": offset, "limit": 24, params = {"username": username, "offset": offset, "limit": 24,
"mature_content": self.mature} "mature_content": self.mature}
return self._pagination(endpoint, params) return self._pagination(endpoint, params)
@@ -1162,7 +1162,7 @@ class DeviantartOAuthAPI():
@memcache(keyarg=1) @memcache(keyarg=1)
def gallery_folders(self, username, offset=0): def gallery_folders(self, username, offset=0):
"""Yield all gallery folders of a specific user""" """Yield all gallery folders of a specific user"""
endpoint = "gallery/folders" endpoint = "/gallery/folders"
params = {"username": username, "offset": offset, "limit": 50, params = {"username": username, "offset": offset, "limit": 50,
"mature_content": self.mature} "mature_content": self.mature}
return self._pagination_list(endpoint, params) return self._pagination_list(endpoint, params)
@@ -1170,12 +1170,12 @@ class DeviantartOAuthAPI():
@memcache(keyarg=1) @memcache(keyarg=1)
def user_profile(self, username): def user_profile(self, username):
"""Get user profile information""" """Get user profile information"""
endpoint = "user/profile/" + username endpoint = "/user/profile/" + username
return self._call(endpoint, fatal=False) return self._call(endpoint, fatal=False)
def user_friends_watch(self, username): def user_friends_watch(self, username):
"""Watch a user""" """Watch a user"""
endpoint = "user/friends/watch/" + username endpoint = "/user/friends/watch/" + username
data = { data = {
"watch[friend]" : "0", "watch[friend]" : "0",
"watch[deviations]" : "0", "watch[deviations]" : "0",
@@ -1193,7 +1193,7 @@ class DeviantartOAuthAPI():
def user_friends_unwatch(self, username): def user_friends_unwatch(self, username):
"""Unwatch a user""" """Unwatch a user"""
endpoint = "user/friends/unwatch/" + username endpoint = "/user/friends/unwatch/" + username
return self._call( return self._call(
endpoint, method="POST", public=False, fatal=False, endpoint, method="POST", public=False, fatal=False,
).get("success") ).get("success")
@@ -1231,7 +1231,7 @@ class DeviantartOAuthAPI():
def _call(self, endpoint, fatal=True, public=True, **kwargs): def _call(self, endpoint, fatal=True, public=True, **kwargs):
"""Call an API endpoint""" """Call an API endpoint"""
url = "https://www.deviantart.com/api/v1/oauth2/" + endpoint url = "https://www.deviantart.com/api/v1/oauth2" + endpoint
kwargs["fatal"] = None kwargs["fatal"] = None
while True: while True:
@@ -1371,7 +1371,7 @@ class DeviantartEclipseAPI():
self.log = extractor.log self.log = extractor.log
def deviation_extended_fetch(self, deviation_id, user=None, kind=None): def deviation_extended_fetch(self, deviation_id, user=None, kind=None):
endpoint = "da-browse/shared_api/deviation/extended_fetch" endpoint = "/da-browse/shared_api/deviation/extended_fetch"
params = { params = {
"deviationid" : deviation_id, "deviationid" : deviation_id,
"username" : user, "username" : user,
@@ -1381,7 +1381,7 @@ class DeviantartEclipseAPI():
return self._call(endpoint, params) return self._call(endpoint, params)
def gallery_scraps(self, user, offset=None): def gallery_scraps(self, user, offset=None):
endpoint = "da-user-profile/api/gallery/contents" endpoint = "/da-user-profile/api/gallery/contents"
params = { params = {
"username" : user, "username" : user,
"offset" : offset, "offset" : offset,
@@ -1391,7 +1391,7 @@ class DeviantartEclipseAPI():
return self._pagination(endpoint, params) return self._pagination(endpoint, params)
def user_watching(self, user, offset=None): def user_watching(self, user, offset=None):
endpoint = "da-user-profile/api/module/watching" endpoint = "/da-user-profile/api/module/watching"
params = { params = {
"username": user, "username": user,
"moduleid": self._module_id_watching(user), "moduleid": self._module_id_watching(user),
@@ -1401,7 +1401,7 @@ class DeviantartEclipseAPI():
return self._pagination(endpoint, params) return self._pagination(endpoint, params)
def _call(self, endpoint, params=None): def _call(self, endpoint, params=None):
url = "https://www.deviantart.com/_napi/" + endpoint url = "https://www.deviantart.com/_napi" + endpoint
headers = {"Referer": "https://www.deviantart.com/"} headers = {"Referer": "https://www.deviantart.com/"}
response = self.extractor._limited_request( response = self.extractor._limited_request(