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`.
|
||||
```
|
||||
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
|
||||
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
-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)
|
||||
-n NUMBER, --number NUMBER
|
||||
Modifier le nombre de musiques par joueur (default: 2)
|
||||
|
|
|
@ -23,6 +23,12 @@ def main():
|
|||
action="store_true",
|
||||
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(
|
||||
"-b",
|
||||
"--no-blacklist",
|
||||
|
@ -92,7 +98,7 @@ def main():
|
|||
musik_list = generate_list(args)
|
||||
|
||||
if not args.no_api:
|
||||
create_playlist(musik_list)
|
||||
create_playlist(musik_list, args)
|
||||
else:
|
||||
logger.info("Liste des musiques :")
|
||||
for _, musik in musik_list:
|
||||
|
|
|
@ -10,7 +10,7 @@ import googleapiclient.errors
|
|||
logger = logging.getLogger("musik.youtube")
|
||||
|
||||
|
||||
def create_playlist(musik_list):
|
||||
def create_playlist(musik_list, args):
|
||||
pickle_path = Path("./youtube.pickle")
|
||||
|
||||
# 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(
|
||||
"./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:
|
||||
credentials = pickle.load(f)
|
||||
else:
|
||||
credentials = flow.run_local_server(port=0)
|
||||
with pickle_path.open("wb") as f:
|
||||
pickle.dump(credentials, f)
|
||||
if not args.no_save_creds:
|
||||
with pickle_path.open("wb") as f:
|
||||
pickle.dump(credentials, f)
|
||||
|
||||
youtube = googleapiclient.discovery.build("youtube", "v3", credentials=credentials)
|
||||
|
||||
|
|
Loading…
Reference in a new issue