Skip to content

Commit

Permalink
[oauth] use custom key/secret values during oauth:…
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Jan 16, 2018
1 parent 421a974 commit 91ed147
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
1 change: 0 additions & 1 deletion gallery_dl/extractor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def __init__(self, categories, extractors=None):
for _, klass in _list_patterns():
if klass.category in categories:
self.extractors.append(klass)
print(self.extractors)

def __enter__(self):
_blacklist.update(self.extractors)
Expand Down
24 changes: 15 additions & 9 deletions gallery_dl/extractor/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from .common import Extractor, Message
from . import deviantart, flickr, reddit, tumblr
from .. import text, util
from .. import text, util, config
import os
import urllib.parse

Expand All @@ -24,6 +24,10 @@ def __init__(self, match):
Extractor.__init__(self)
self.client = None

def oauth_config(self, key, default=None):
return config.interpolate(
("extractor", self.subcategory, key), default)

def recv(self):
"""Open local HTTP server and recv callback parameters"""
import socket
Expand Down Expand Up @@ -66,7 +70,7 @@ def open(self, url, params):
import webbrowser
url += "?" + urllib.parse.urlencode(params)
browser = self.config("browser", True)
if not browser or (browser and not webbrowser.open(url)):
if not browser or not webbrowser.open(url):
print("Please open this URL in your browser:")
print(url, end="\n\n", flush=True)
return self.recv()
Expand Down Expand Up @@ -155,8 +159,10 @@ def items(self):
yield Message.Version, 1

self._oauth2_authorization_code_grant(
deviantart.DeviantartAPI.CLIENT_ID,
deviantart.DeviantartAPI.CLIENT_SECRET,
self.oauth_config(
"client-id", deviantart.DeviantartAPI.CLIENT_ID),
self.oauth_config(
"client-secret", deviantart.DeviantartAPI.CLIENT_SECRET),
"https://www.deviantart.com/oauth2/authorize",
"https://www.deviantart.com/oauth2/token",
"browse",
Expand All @@ -171,8 +177,8 @@ def __init__(self, match):
OAuthBase.__init__(self, match)
self.session = util.OAuthSession(
self.session,
flickr.FlickrAPI.API_KEY,
flickr.FlickrAPI.API_SECRET,
self.oauth_config("api-key", flickr.FlickrAPI.API_KEY),
self.oauth_config("api-secret", flickr.FlickrAPI.API_SECRET),
)

def items(self):
Expand All @@ -194,7 +200,7 @@ def items(self):

self.session.headers["User-Agent"] = reddit.RedditAPI.USER_AGENT
self._oauth2_authorization_code_grant(
reddit.RedditAPI.CLIENT_ID,
self.oauth_config("client-id", reddit.RedditAPI.CLIENT_ID),
"",
"https://www.reddit.com/api/v1/authorize",
"https://www.reddit.com/api/v1/access_token",
Expand All @@ -210,8 +216,8 @@ def __init__(self, match):
OAuthBase.__init__(self, match)
self.session = util.OAuthSession(
self.session,
tumblr.TumblrAPI.API_KEY,
tumblr.TumblrAPI.API_SECRET,
self.oauth_config("api-key", tumblr.TumblrAPI.API_KEY),
self.oauth_config("api-secret", tumblr.TumblrAPI.API_SECRET),
)

def items(self):
Expand Down

0 comments on commit 91ed147

Please sign in to comment.