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
0d12f661
Commit
0d12f661
authored
Oct 08, 2018
by
Louis Devillez
Browse files
V1.0
parent
5dd5523f
Changes
3
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
0d12f661
# Youtube-2-mp3
Download song from youtube directly into your folders
From one key press, you download the youtube video from your browser.
main.py
0 → 100644
View file @
0d12f661
from
__future__
import
unicode_literals
import
os
import
json
import
lz4.block
import
requests
import
youtube_dl
from
urllib.request
import
urlopen
,
FancyURLopener
from
urllib.parse
import
urlparse
,
parse_qs
,
unquote
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"
)
settings.py
0 → 100644
View file @
0d12f661
settings
=
{
"browser"
:
"firefox"
,
"path"
:
"/home/westornd/.mozilla/firefox/euy0mqkl.default/sessionstore-backups"
,
"pathMusique"
:
"/home/westornd/Musique"
}
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