Add option to prevent saving youtube credentials
This commit is contained in:
parent
80dfaf1dfe
commit
95f8d5741a
3 changed files with 15 additions and 6 deletions
|
@ -21,13 +21,15 @@ des joueurs.
|
||||||
|
|
||||||
Lancer le script à l'aide de la commande `python -m musik`.
|
Lancer le script à l'aide de la commande `python -m musik`.
|
||||||
```
|
```
|
||||||
usage: python -m musik [-h] [-a] [-b] [-n NUMBER] [--lists LISTS] [--blacklists BLACKLISTS] [--results RESULTS] [-v]
|
usage: python -m musik [-h] [-a] [-c] [-b] [-n NUMBER] [--lists LISTS] [--blacklists BLACKLISTS] [--results RESULTS]
|
||||||
|
[-v]
|
||||||
|
|
||||||
Lancer une partie de Musik
|
Lancer une partie de Musik
|
||||||
|
|
||||||
options:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-a, --no-api Désactiver l'API Youtube ; affiche la liste des liens (default: False)
|
-a, --no-api Désactiver l'API Youtube ; affiche la liste des liens (default: False)
|
||||||
|
-c, --no-save-creds Désactiver l'enregistrement de la connexion Youtube (default: False)
|
||||||
-b, --no-blacklist Désactiver le méchanisme de blacklist en lecture et écriture (default: False)
|
-b, --no-blacklist Désactiver le méchanisme de blacklist en lecture et écriture (default: False)
|
||||||
-n NUMBER, --number NUMBER
|
-n NUMBER, --number NUMBER
|
||||||
Modifier le nombre de musiques par joueur (default: 2)
|
Modifier le nombre de musiques par joueur (default: 2)
|
||||||
|
|
|
@ -23,6 +23,12 @@ def main():
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Désactiver l'API Youtube ; affiche la liste des liens",
|
help="Désactiver l'API Youtube ; affiche la liste des liens",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-c",
|
||||||
|
"--no-save-creds",
|
||||||
|
action="store_true",
|
||||||
|
help="Désactiver l'enregistrement de la connexion Youtube",
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-b",
|
"-b",
|
||||||
"--no-blacklist",
|
"--no-blacklist",
|
||||||
|
@ -92,7 +98,7 @@ def main():
|
||||||
musik_list = generate_list(args)
|
musik_list = generate_list(args)
|
||||||
|
|
||||||
if not args.no_api:
|
if not args.no_api:
|
||||||
create_playlist(musik_list)
|
create_playlist(musik_list, args)
|
||||||
else:
|
else:
|
||||||
logger.info("Liste des musiques :")
|
logger.info("Liste des musiques :")
|
||||||
for _, musik in musik_list:
|
for _, musik in musik_list:
|
||||||
|
|
|
@ -10,7 +10,7 @@ import googleapiclient.errors
|
||||||
logger = logging.getLogger("musik.youtube")
|
logger = logging.getLogger("musik.youtube")
|
||||||
|
|
||||||
|
|
||||||
def create_playlist(musik_list):
|
def create_playlist(musik_list, args):
|
||||||
pickle_path = Path("./youtube.pickle")
|
pickle_path = Path("./youtube.pickle")
|
||||||
|
|
||||||
# Connexion à l'API youtube, obtention d'un jeton OAuth
|
# Connexion à l'API youtube, obtention d'un jeton OAuth
|
||||||
|
@ -18,13 +18,14 @@ def create_playlist(musik_list):
|
||||||
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
|
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
|
||||||
"./secret.json", ["https://www.googleapis.com/auth/youtube.force-ssl"]
|
"./secret.json", ["https://www.googleapis.com/auth/youtube.force-ssl"]
|
||||||
)
|
)
|
||||||
if pickle_path.is_file():
|
if (not args.no_save_creds) and pickle_path.is_file():
|
||||||
with pickle_path.open("rb") as f:
|
with pickle_path.open("rb") as f:
|
||||||
credentials = pickle.load(f)
|
credentials = pickle.load(f)
|
||||||
else:
|
else:
|
||||||
credentials = flow.run_local_server(port=0)
|
credentials = flow.run_local_server(port=0)
|
||||||
with pickle_path.open("wb") as f:
|
if not args.no_save_creds:
|
||||||
pickle.dump(credentials, f)
|
with pickle_path.open("wb") as f:
|
||||||
|
pickle.dump(credentials, f)
|
||||||
|
|
||||||
youtube = googleapiclient.discovery.build("youtube", "v3", credentials=credentials)
|
youtube = googleapiclient.discovery.build("youtube", "v3", credentials=credentials)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue