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 logging
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
|
||||||
import sys
|
import sys
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
logger = logging.getLogger("musik.list")
|
logger = logging.getLogger("musik.list")
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
from pathlib import Path
|
||||||
|
import pickle
|
||||||
|
|
||||||
import google_auth_oauthlib.flow
|
import google_auth_oauthlib.flow
|
||||||
import googleapiclient.discovery
|
import googleapiclient.discovery
|
||||||
|
@ -9,13 +11,24 @@ logger = logging.getLogger("musik.youtube")
|
||||||
|
|
||||||
|
|
||||||
def create_playlist(musik_list):
|
def create_playlist(musik_list):
|
||||||
|
pickle_path = Path("./youtube.pickle")
|
||||||
|
|
||||||
# Connexion à l'API youtube, obtention d'un jeton OAuth
|
# Connexion à l'API youtube, obtention d'un jeton OAuth
|
||||||
logger.info("Connexion à l'API Youtube")
|
logger.info("Connexion à l'API Youtube")
|
||||||
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"]
|
||||||
)
|
)
|
||||||
credentials = flow.run_local_server(port=0)
|
if pickle_path.is_file():
|
||||||
youtube = googleapiclient.discovery.build("youtube", "v3", credentials=credentials)
|
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
|
# Création d'une playlist
|
||||||
logger.info("Création de la playlist")
|
logger.info("Création de la playlist")
|
||||||
|
|
Loading…
Reference in a new issue