-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.py
42 lines (36 loc) · 1.41 KB
/
auth.py
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
#!/usr/bin/env python3
import sys
import tidalapi
import webbrowser
import yaml
def open_tidal_session(config = None):
try:
with open('.session.yml', 'r') as session_file:
previous_session = yaml.safe_load(session_file)
except OSError:
previous_session = None
if config:
session = tidalapi.Session(config=config)
else:
session = tidalapi.Session()
if previous_session:
try:
if session.load_oauth_session(token_type= previous_session['token_type'],
access_token=previous_session['access_token'],
refresh_token=previous_session['refresh_token'] ):
return session
except Exception as e:
print("Error loading previous Tidal Session: \n" + str(e) )
login, future = session.login_oauth()
print('Login with the webbrowser: ' + login.verification_uri_complete)
url = login.verification_uri_complete
if not url.startswith('https://'):
url = 'https://' + url
webbrowser.open(url)
future.result()
with open('.session.yml', 'w') as f:
yaml.dump( {'session_id': session.session_id,
'token_type': session.token_type,
'access_token': session.access_token,
'refresh_token': session.refresh_token}, f )
return session