Save youtube credentials

This commit is contained in:
Edgar P. Burkhart 2024-04-10 13:33:52 +02:00
parent 6f2726f423
commit 96c6bfa8fa
Signed by: edpibu
GPG Key ID: 9833D3C5A25BD227
2 changed files with 16 additions and 3 deletions

View File

@ -1,8 +1,8 @@
import logging
import random
import re
from datetime import datetime
import sys
from datetime import datetime
logger = logging.getLogger("musik.list")

View File

@ -1,5 +1,7 @@
import logging
from datetime import date
from pathlib import Path
import pickle
import google_auth_oauthlib.flow
import googleapiclient.discovery
@ -9,13 +11,24 @@ logger = logging.getLogger("musik.youtube")
def create_playlist(musik_list):
pickle_path = Path("./youtube.pickle")
# Connexion à l'API youtube, obtention d'un jeton OAuth
logger.info("Connexion à l'API Youtube")
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
"./secret.json", ["https://www.googleapis.com/auth/youtube.force-ssl"]
)
credentials = flow.run_local_server(port=0)
youtube = googleapiclient.discovery.build("youtube", "v3", credentials=credentials)
if 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)
youtube = googleapiclient.discovery.build(
"youtube", "v3", credentials=credentials
)
# Création d'une playlist
logger.info("Création de la playlist")