Skip to content
Snippets Groups Projects
Commit 7092ed31 authored by BuildTools's avatar BuildTools
Browse files

séparation des playlists pour le client

parent 92f019cd
Branches
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
# coding: latin-1
import os
from time import time
......@@ -10,6 +10,60 @@ from credentials import KEY
#commande test : "yt-dlp -f 'ba' -x --audio-format mp3 https://www.youtube.com/watch?v=zA2YBT9z6pA -o '%(id)s.mp3' "
caracteres = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_=+\';,:!?$%&#~<> "
remplacements = {"(":"-" , ")": "-" , "\"" : "\'","":"e","":"a","":"e","":"u","":"e","":"a","":"o","":"i","":"u","":"U","/":" "}
def replace(caract,remplacements) :
if caract in remplacements.keys() :
return remplacements[caract]
else :
return caract
#Supprimer tous les caracteres interdits
def garde(chn,caracteres):
print("filtrage de : "+chn)
res = ("".join([x for x in chn if x in caracteres]) )
return res
def remplacer(chn,remplacements):
res = ("".join([replace(x,remplacements) for x in chn]))
print("type(res) : "+ str(type(res)) )
return res
def addplaylist(playlistid):
os.chdir("/mnt/usb/bleezrdata")
chn = 'https://www.googleapis.com/youtube/v3/playlists?part=snippet&id='+playlistid+'&key='+KEY
dico = get(chn).json()
playlistname = dico["items"][0]["snippet"]["title"]
with open("playlistinfo.json",'r') as f :
data = load(f)
if not playlistid in [x['id'] for x in data] :
data.append({'id':playlistid,'name':playlistname})
with open("playlistinfo.json",'w') as f :
f.write(dumps(data))
with open("playlists.json",'r') as f :
data = load(f)
if not playlistid in data:
data.append(playlistid)
with open("playlists.json",'w') as f :
f.write(dumps(data))
addplaylist("PL8V2Ld0Is1-kUaNtXmvYGtYoyZ0O2aqDt")
os.chdir("/mnt/usb/bleezrdata")
t = time()
......@@ -27,6 +81,7 @@ while True :
for playlist in data :
if playlist not in os.listdir("musics"):
print("La playlist " + playlist + " n\'est pas dans le rpertoire" )
os.chdir("musics")
os.mkdir(playlist)
......@@ -40,17 +95,20 @@ while True :
os.chdir("../..")
#A supprimer lorsque tout le code aura été fait proprement
#A supprimer lorsque tout le code aura t fait proprement
if "seen_names.json" not in os.listdir("musics/"+playlist):
print("seen_names.json n\'est pas dans le rpertoire de la playlist")
with open("musics/"+playlist+"/seen_names.json",'w') as f :
f.write("[]")
os.chdir("musics/"+playlist)
chn = 'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=25&playlistId='+playlist+'&key='+KEY
print(chn)
requete = get(chn)
dico = requete.json()
all_videos = [x['snippet']['resourceId']['videoId'] for x in dico['items']]
all_videos_names = [x['snippet']['title'] for x in dico['items']]
#print("longueur de all_videos : {}".format(len(all_videos)))
with open('seen.json','r') as f2 :
seen_videos = load(f2)
with open('seen_names.json','r') as f3 :
......@@ -60,10 +118,15 @@ while True :
i = 0
while i < len(all_videos) and all_videos[i] not in seen_videos :
vid = all_videos[i]
vid_name = all_videos_names[i]
vid_name = garde(remplacer(all_videos_names[i],remplacements),caracteres)
print(vid)
command = "yt-dlp -f 'ba' -x --audio-format mp3 https://www.youtube.com/watch?v={0} -o '%(title)s.mp3' ".format(vid)
print(vid_name)
#command = "yt-dlp -f 'ba' -x --audio-format mp3 https://www.youtube.com/watch?v={0} -o '%(title)s.mp3' ".format(vid)
command = "yt-dlp -f 'ba' -x --audio-format mp3 https://www.youtube.com/watch?v={0} -o \"{1}.mp3\"".format(vid,vid_name)
print(command)
os.system(command)
if vid_name+".mp3" in os.listdir(".") :
seen_videos.append(vid)
seen_videos_names.append(vid_name)
i += 1
......@@ -78,8 +141,6 @@ while True :
os.chdir("../")
os.chdir("../")
"""
playlist = "PL8V2Ld0Is1-kWGtqHFOJiwwnU1lWbpC1r"
chn = 'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=25&playlistId='+playlist+'&key='+KEY
......@@ -90,3 +151,4 @@ dico = requete.json()
l = dico['items']
print([x['snippet']['resourceId']['videoId'] for x in l])
"""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment