Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Bleezr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hector Blondel
Bleezr
Commits
7092ed31
You need to sign in or sign up before continuing.
Commit
7092ed31
authored
2 years ago
by
BuildTools
Browse files
Options
Downloads
Patches
Plain Diff
séparation des playlists pour le client
parent
92f019cd
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
download_server.py
+74
-12
74 additions, 12 deletions
download_server.py
with
74 additions
and
12 deletions
download_server.py
+
74
−
12
View file @
7092ed31
#
-*-
coding:
utf-8 -*-
# coding:
latin-1
import
os
import
os
from
time
import
time
from
time
import
time
...
@@ -10,6 +10,60 @@ from credentials import KEY
...
@@ -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' "
#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
"
)
os
.
chdir
(
"
/mnt/usb/bleezrdata
"
)
t
=
time
()
t
=
time
()
...
@@ -27,6 +81,7 @@ while True :
...
@@ -27,6 +81,7 @@ while True :
for
playlist
in
data
:
for
playlist
in
data
:
if
playlist
not
in
os
.
listdir
(
"
musics
"
):
if
playlist
not
in
os
.
listdir
(
"
musics
"
):
print
(
"
La playlist
"
+
playlist
+
"
n
\'
est pas dans le rpertoire
"
)
os
.
chdir
(
"
musics
"
)
os
.
chdir
(
"
musics
"
)
os
.
mkdir
(
playlist
)
os
.
mkdir
(
playlist
)
...
@@ -40,17 +95,20 @@ while True :
...
@@ -40,17 +95,20 @@ while True :
os
.
chdir
(
"
../..
"
)
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
):
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
:
with
open
(
"
musics/
"
+
playlist
+
"
/seen_names.json
"
,
'
w
'
)
as
f
:
f
.
write
(
"
[]
"
)
f
.
write
(
"
[]
"
)
os
.
chdir
(
"
musics/
"
+
playlist
)
os
.
chdir
(
"
musics/
"
+
playlist
)
chn
=
'
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=25&playlistId=
'
+
playlist
+
'
&key=
'
+
KEY
chn
=
'
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=25&playlistId=
'
+
playlist
+
'
&key=
'
+
KEY
print
(
chn
)
requete
=
get
(
chn
)
requete
=
get
(
chn
)
dico
=
requete
.
json
()
dico
=
requete
.
json
()
all_videos
=
[
x
[
'
snippet
'
][
'
resourceId
'
][
'
videoId
'
]
for
x
in
dico
[
'
items
'
]]
all_videos
=
[
x
[
'
snippet
'
][
'
resourceId
'
][
'
videoId
'
]
for
x
in
dico
[
'
items
'
]]
all_videos_names
=
[
x
[
'
snippet
'
][
'
title
'
]
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
:
with
open
(
'
seen.json
'
,
'
r
'
)
as
f2
:
seen_videos
=
load
(
f2
)
seen_videos
=
load
(
f2
)
with
open
(
'
seen_names.json
'
,
'
r
'
)
as
f3
:
with
open
(
'
seen_names.json
'
,
'
r
'
)
as
f3
:
...
@@ -60,10 +118,15 @@ while True :
...
@@ -60,10 +118,15 @@ while True :
i
=
0
i
=
0
while
i
<
len
(
all_videos
)
and
all_videos
[
i
]
not
in
seen_videos
:
while
i
<
len
(
all_videos
)
and
all_videos
[
i
]
not
in
seen_videos
:
vid
=
all_videos
[
i
]
vid
=
all_videos
[
i
]
vid_name
=
all_videos_names
[
i
]
vid_name
=
garde
(
remplacer
(
all_videos_names
[
i
]
,
remplacements
),
caracteres
)
print
(
vid
)
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
)
os
.
system
(
command
)
if
vid_name
+
"
.mp3
"
in
os
.
listdir
(
"
.
"
)
:
seen_videos
.
append
(
vid
)
seen_videos
.
append
(
vid
)
seen_videos_names
.
append
(
vid_name
)
seen_videos_names
.
append
(
vid_name
)
i
+=
1
i
+=
1
...
@@ -78,8 +141,6 @@ while True :
...
@@ -78,8 +141,6 @@ while True :
os
.
chdir
(
"
../
"
)
os
.
chdir
(
"
../
"
)
os
.
chdir
(
"
../
"
)
os
.
chdir
(
"
../
"
)
"""
"""
playlist =
"
PL8V2Ld0Is1-kWGtqHFOJiwwnU1lWbpC1r
"
playlist =
"
PL8V2Ld0Is1-kWGtqHFOJiwwnU1lWbpC1r
"
chn =
'
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=25&playlistId=
'
+playlist+
'
&key=
'
+KEY
chn =
'
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=25&playlistId=
'
+playlist+
'
&key=
'
+KEY
...
@@ -90,3 +151,4 @@ dico = requete.json()
...
@@ -90,3 +151,4 @@ dico = requete.json()
l = dico[
'
items
'
]
l = dico[
'
items
'
]
print([x[
'
snippet
'
][
'
resourceId
'
][
'
videoId
'
] for x in l])
print([x[
'
snippet
'
][
'
resourceId
'
][
'
videoId
'
] for x in l])
"""
"""
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment