Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Youtube-2-mp3
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Louis Devillez
Youtube-2-mp3
Commits
823910a2
Commit
823910a2
authored
6 years ago
by
Louis Devillez
Browse files
Options
Downloads
Patches
Plain Diff
version 0.1
parent
0d12f661
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+18
-1
18 additions, 1 deletion
README.md
main.py
+113
-37
113 additions, 37 deletions
main.py
with
131 additions
and
38 deletions
README.md
+
18
−
1
View file @
823910a2
# Youtube-2-mp3
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
This diff is collapsed.
Click to expand it.
main.py
+
113
−
37
View file @
823910a2
...
...
@@ -4,11 +4,17 @@ 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
# 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
"
))
...
...
@@ -22,14 +28,12 @@ for win in jdata.get("windows"):
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
'
)))
if
"
https://www.youtube.com/watch?
"
in
i
:
ydl_opts
=
{
'
format
'
:
'
bestaudio/best
'
,
'
forcetitle
'
:
'
true
'
,
'
forcejson
'
:
'
true
'
,
'
noplaylist
'
:
'
true
'
,
'
postprocessors
'
:
[{
'
key
'
:
'
FFmpegExtractAudio
'
,
'
preferredcodec
'
:
'
mp3
'
,
...
...
@@ -37,12 +41,84 @@ for i in URLS:
}],
}
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
"
)
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
'
)
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