Save youtube credentials
This commit is contained in:
parent
6f2726f423
commit
96c6bfa8fa
2 changed files with 16 additions and 3 deletions
|
@ -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")
|
||||
|
||||
|
|
|
@ -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"]
|
||||
)
|
||||
if pickle_path.is_file():
|
||||
with pickle_path.open("rb") as f:
|
||||
credentials = pickle.load(f)
|
||||
else:
|
||||
credentials = flow.run_local_server(port=0)
|
||||
youtube = googleapiclient.discovery.build("youtube", "v3", credentials=credentials)
|
||||
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")
|
||||
|
|
Loading…
Reference in a new issue