Spaces:
Runtime error
Runtime error
jpdiazpardo
commited on
Commit
•
ff63bdc
1
Parent(s):
bba23d3
Upload youtubetowav.py
Browse files- youtubetowav.py +31 -0
youtubetowav.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import unicode_literals
|
2 |
+
import yt_dlp
|
3 |
+
import ffmpeg
|
4 |
+
import sys
|
5 |
+
|
6 |
+
ydl_opts = {
|
7 |
+
'format': 'bestaudio/best',
|
8 |
+
# 'outtmpl': 'output.%(ext)s',
|
9 |
+
'postprocessors': [{
|
10 |
+
'key': 'FFmpegExtractAudio',
|
11 |
+
'preferredcodec': 'wav',
|
12 |
+
}],
|
13 |
+
}
|
14 |
+
def download_from_url(url):
|
15 |
+
ydl.download([url])
|
16 |
+
stream = ffmpeg.input('output.m4a')
|
17 |
+
stream = ffmpeg.output(stream, 'output.wav')
|
18 |
+
|
19 |
+
|
20 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
21 |
+
args = sys.argv[1:]
|
22 |
+
if len(args) > 1:
|
23 |
+
print("Too many arguments.")
|
24 |
+
print("Usage: python youtubetowav.py <optional link>")
|
25 |
+
print("If a link is given it will automatically convert it to .wav. Otherwise a prompt will be shown")
|
26 |
+
exit()
|
27 |
+
if len(args) == 0:
|
28 |
+
url=input("Enter Youtube URL: ")
|
29 |
+
download_from_url(url)
|
30 |
+
else:
|
31 |
+
download_from_url(args[0])
|