Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Louis Devillez
Youtube-2-mp3
Commits
823910a2
Commit
823910a2
authored
Oct 24, 2018
by
Louis Devillez
Browse files
version 0.1
parent
0d12f661
Changes
2
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
823910a2
# Youtube-2-mp3
From one key press, you download the youtube video from your browser.
From one key press, you download the youtube video from your browser.
## Utilisation
Il suffit d'installer les dépendances(
**TODO**
) puis de lancer
`python3 main.py`
On peut aussi lancer
`python main.py full`
Pour pouvoir spécifier le titre et l'auteur de la musique
## settings
*
**browser**
: pour l'instant l'app ne supporte que Firefox
*
**path**
: le chemin qui mène vers l'endroit ou sont stocké les urls des vidéos
*
**pathMusique**
: Le chemin où il faut sauvegarder les musiques
main.py
View file @
823910a2
...
...
@@ -4,45 +4,121 @@ import json
import
lz4.block
import
requests
import
youtube_dl
import
sys
from
eyed3
import
id3
from
urllib.request
import
urlopen
,
FancyURLopener
from
urllib.parse
import
urlparse
,
parse_qs
,
unquote
import
tkinter
from
settings
import
settings
f
=
open
(
settings
[
"path"
]
+
"/recovery.jsonlz4"
,
"rb"
)
magic
=
f
.
read
(
8
)
jdata
=
json
.
loads
(
lz4
.
block
.
decompress
(
f
.
read
()).
decode
(
"utf-8"
))
f
.
close
()
URLS
=
[]
for
win
in
jdata
.
get
(
"windows"
):
for
tab
in
win
.
get
(
"tabs"
):
i
=
tab
.
get
(
"index"
)
-
1
urls
=
tab
.
get
(
"entries"
)[
i
].
get
(
"url"
)
if
"www.youtube.com"
in
urls
:
list
.
append
(
URLS
,
urls
)
for
i
in
URLS
:
video_id
=
parse_qs
(
urlparse
(
i
).
query
)[
'v'
][
0
]
url_data
=
urlopen
(
'http://www.youtube.com/get_video_info?&video;_id='
+
video_id
).
read
()
url_info
=
parse_qs
(
unquote
(
url_data
.
decode
(
'utf-8'
)))
ydl_opts
=
{
'format'
:
'bestaudio/best'
,
'forcetitle'
:
'true'
,
'forcejson'
:
'true'
,
'postprocessors'
:
[{
'key'
:
'FFmpegExtractAudio'
,
'preferredcodec'
:
'mp3'
,
'preferredquality'
:
'192'
,
}],
}
with
youtube_dl
.
YoutubeDL
(
ydl_opts
)
as
ydl
:
info_dict
=
ydl
.
extract_info
(
i
,
download
=
False
)
print
(
info_dict
[
"title"
])
title
=
input
(
"Titre de la musique: "
)
ydl
.
download
([
i
])
dir
=
os
.
listdir
(
settings
[
"pathMusique"
])
for
i
in
range
(
0
,
len
(
dir
)):
print
(
str
(
i
)
+
" - "
+
dir
[
i
])
dirFinal
=
dir
[
int
(
input
(
"Dossier final:"
))]
os
.
rename
(
info_dict
[
"title"
]
+
'-'
+
info_dict
[
"id"
]
+
".mp3"
,
settings
[
"pathMusique"
]
+
'/'
+
dirFinal
+
'/'
+
title
+
".mp3"
)
# On regarde dans quel mode on est
if
(
len
(
sys
.
argv
)
<
2
):
tag
=
id3
.
Tag
()
f
=
open
(
settings
[
"path"
]
+
"/recovery.jsonlz4"
,
"rb"
)
magic
=
f
.
read
(
8
)
jdata
=
json
.
loads
(
lz4
.
block
.
decompress
(
f
.
read
()).
decode
(
"utf-8"
))
f
.
close
()
URLS
=
[]
for
win
in
jdata
.
get
(
"windows"
):
for
tab
in
win
.
get
(
"tabs"
):
i
=
tab
.
get
(
"index"
)
-
1
urls
=
tab
.
get
(
"entries"
)[
i
].
get
(
"url"
)
if
"www.youtube.com"
in
urls
:
list
.
append
(
URLS
,
urls
)
for
i
in
URLS
:
if
"https://www.youtube.com/watch?"
in
i
:
ydl_opts
=
{
'format'
:
'bestaudio/best'
,
'forcetitle'
:
'true'
,
'forcejson'
:
'true'
,
'noplaylist'
:
'true'
,
'postprocessors'
:
[{
'key'
:
'FFmpegExtractAudio'
,
'preferredcodec'
:
'mp3'
,
'preferredquality'
:
'192'
,
}],
}
with
youtube_dl
.
YoutubeDL
(
ydl_opts
)
as
ydl
:
info_dict
=
ydl
.
extract_info
(
i
.
split
(
"&index"
)[
0
].
split
(
"&list="
)[
0
],
download
=
False
)
ydl
.
download
([
i
.
split
(
"&index"
)[
0
].
split
(
"&list="
)[
0
]])
tag
.
parse
(
info_dict
[
"title"
]
+
'-'
+
info_dict
[
"id"
]
+
".mp3"
)
title
=
'default'
if
(
len
(
info_dict
[
"title"
].
split
(
" - "
))
>
1
):
tag
.
title
=
info_dict
[
"title"
].
split
(
" - "
)[
1
]
tag
.
artist
=
info_dict
[
"title"
].
split
(
" - "
)[
0
]
title
=
info_dict
[
"title"
].
split
(
"-"
)[
1
]
elif
(
len
(
info_dict
[
"title"
].
split
(
"-"
))
>
1
):
tag
.
title
=
info_dict
[
"title"
].
split
(
"-"
)[
1
]
tag
.
artist
=
info_dict
[
"title"
].
split
(
"-"
)[
0
]
title
=
info_dict
[
"title"
].
split
(
"-"
)[
1
]
else
:
tag
.
title
=
info_dict
[
"title"
]
title
=
info_dict
[
"title"
]
tag
.
save
()
os
.
rename
(
info_dict
[
"title"
]
+
'-'
+
info_dict
[
"id"
]
+
".mp3"
,
settings
[
"pathMusique"
]
+
'/ToSort/'
+
title
+
".mp3"
)
elif
(
str
(
sys
.
argv
[
1
])
==
'full'
):
tag
=
id3
.
Tag
()
f
=
open
(
settings
[
"path"
]
+
"/recovery.jsonlz4"
,
"rb"
)
magic
=
f
.
read
(
8
)
jdata
=
json
.
loads
(
lz4
.
block
.
decompress
(
f
.
read
()).
decode
(
"utf-8"
))
f
.
close
()
URLS
=
[]
for
win
in
jdata
.
get
(
"windows"
):
for
tab
in
win
.
get
(
"tabs"
):
i
=
tab
.
get
(
"index"
)
-
1
urls
=
tab
.
get
(
"entries"
)[
i
].
get
(
"url"
)
if
"www.youtube.com"
in
urls
:
list
.
append
(
URLS
,
urls
)
for
i
in
URLS
:
if
"https://www.youtube.com/watch?"
in
i
:
ydl_opts
=
{
'format'
:
'bestaudio/best'
,
'noplaylist:'
:
'true'
,
'postprocessors'
:
[{
'key'
:
'FFmpegExtractAudio'
,
'preferredcodec'
:
'mp3'
,
'preferredquality'
:
'192'
,
}],
}
with
youtube_dl
.
YoutubeDL
(
ydl_opts
)
as
ydl
:
print
(
i
)
info_dict
=
ydl
.
extract_info
(
i
.
split
(
"&index"
)[
0
].
split
(
"&list="
)[
0
],
download
=
False
)
ydl
.
download
([
i
.
split
(
"&index"
)[
0
].
split
(
"&list="
)[
0
]])
tag
.
parse
(
info_dict
[
"title"
]
+
'-'
+
info_dict
[
"id"
]
+
".mp3"
)
top
=
tkinter
.
Tk
()
done
=
False
def
delWindow
(
a
):
done
=
False
top
.
quit
()
def
CloseWindow
():
done
=
True
top
.
quit
()
top
.
title
(
"Youtube to MP3"
)
title
=
tkinter
.
StringVar
()
artist
=
tkinter
.
StringVar
()
tkinter
.
Label
(
top
,
text
=
info_dict
[
"title"
]).
grid
(
column
=
2
,
row
=
1
)
tkinter
.
Label
(
top
,
text
=
"Titre"
,
width
=
10
).
grid
(
column
=
1
,
row
=
2
)
tkinter
.
Entry
(
top
,
text
=
"Titre"
,
textvariable
=
title
).
grid
(
column
=
2
,
row
=
2
)
tkinter
.
Label
(
top
,
text
=
"Artiste"
).
grid
(
column
=
1
,
row
=
3
)
tkinter
.
Entry
(
top
,
text
=
"Artiste"
,
textvariable
=
artist
).
grid
(
column
=
2
,
row
=
3
)
tkinter
.
Label
(
top
,
text
=
""
).
grid
(
column
=
2
,
row
=
4
)
top
.
bind
(
"<KeyPress-Escape>"
,
delWindow
)
tkinter
.
Button
(
top
,
text
=
"Convertir"
,
command
=
CloseWindow
,
width
=
10
).
grid
(
column
=
3
,
row
=
5
)
top
.
mainloop
()
if
done
==
True
:
tag
.
title
=
title
.
get
()
tag
.
artist
=
artist
.
get
()
title
=
title
.
get
()
tag
.
save
()
os
.
rename
(
info_dict
[
"title"
]
+
'-'
+
info_dict
[
"id"
]
+
".mp3"
,
settings
[
"pathMusique"
]
+
'/ToSort/'
+
title
+
".mp3"
)
else
:
print
(
'do it'
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment