-
Notifications
You must be signed in to change notification settings - Fork 63
/
setup.py
51 lines (41 loc) · 1.44 KB
/
setup.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
43
44
45
46
47
48
49
50
51
import json
import shutil
import sys
from pathlib import Path
from typing import Optional
import ytmusicapi
from spotify_to_ytmusic.settings import DEFAULT_PATH, EXAMPLE_PATH, Settings
from spotify_to_ytmusic.utils.browser import has_browser
def setup(file: Optional[Path] = None):
if file:
shutil.copy(file, DEFAULT_PATH)
return
if not DEFAULT_PATH.is_file():
shutil.copy(EXAMPLE_PATH, DEFAULT_PATH)
choice = input("Choose which API to set up\n" "(1) Spotify\n" "(2) YouTube\n" "(3) both\n")
choices = ["1", "2", "3"]
if choice not in choices:
sys.exit("Invalid choice")
if choice == choices[0]:
setup_spotify()
elif choice == choices[1]:
setup_youtube()
elif choice == choices[2]:
setup_spotify()
setup_youtube()
def setup_youtube():
settings = Settings()
credentials = ytmusicapi.setup_oauth(open_browser=has_browser())
settings["youtube"]["headers"] = json.dumps(credentials)
settings.save()
def setup_spotify():
settings = Settings()
credentials = {
"client_id": input("Paste your client id from the Spotify developer dashboard:"),
"client_secret": input("Paste your client secret from the Spotify developer dashboard:"),
"use_oauth": input(
"Use OAuth method for authorization to transfer private playlists (yes/no):"
),
}
settings["spotify"].update(credentials)
settings.save()