ayaanzaveri commited on
Commit
039034a
1 Parent(s): 62932a4

Create video.py

Browse files
Files changed (1) hide show
  1. video.py +25 -0
video.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pathlib
2
+
3
+ # List of all supported video sites here https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md
4
+ def download_convert_video_to_audio(
5
+ yt_dlp,
6
+ video_url: str,
7
+ destination_path: pathlib.Path,
8
+ ) -> None:
9
+ ydl_opts = {
10
+ "format": "bestaudio/best",
11
+ "postprocessors": [
12
+ { # Extract audio using ffmpeg
13
+ "key": "FFmpegExtractAudio",
14
+ "preferredcodec": "mp3",
15
+ }
16
+ ],
17
+ "outtmpl": f"{destination_path}.%(ext)s",
18
+ }
19
+ try:
20
+ print(f"Downloading video from {video_url}")
21
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
22
+ ydl.download(video_url)
23
+ print(f"Downloaded video from {video_url} to {destination_path}")
24
+ except Exception as e:
25
+ raise (e)