-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgenerate_config
executable file
·68 lines (54 loc) · 1.5 KB
/
generate_config
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
"""Script to retrieve an access and refresh token for using the Spotify API"""
from argparse import ArgumentParser
import json
import spotipy
import spotipy.util as util
DEFAULT_REDIRECT_URI = "http://localhost/callback"
parser = ArgumentParser(description=__doc__)
parser.add_argument(
"--client_id",
"--client-id",
help="Spotify client ID",
)
parser.add_argument(
"--client_secret",
"--client-secret",
help="Spotify client secret",
)
parser.add_argument(
"--redirect_uri",
"--redirect-uri",
default=DEFAULT_REDIRECT_URI,
help="Redirect URI"
)
parser.add_argument(
"--username",
help="Spotify username"
)
def main():
args = parser.parse_args()
scope = "streaming user-read-playback-state"
auth = spotipy.SpotifyOAuth(
args.client_id,
args.client_secret,
args.redirect_uri,
username=args.username,
scope=scope,
show_dialog=False
)
token_info = auth.get_cached_token()
if not token_info:
code = auth.get_auth_response()
token_info = auth.get_access_token(code, as_dict=True)
config = {
"platform": "Spotify",
"name": "Spotify",
"service_type": "light", # "light" or "speaker"; Speaker is not supported by HomeKit
"client_id": args.client_id,
"client_secret": args.client_secret,
"refresh_token": token_info["refresh_token"]
}
print(json.dumps(config, indent=2))
if __name__ == "__main__":
main()