yt download instrument example
frdel committed
Oct 6, 2024 at 15:53 UTC
ff6c196d155d89f07a067412098db06ce8453c9c
3 files changed
+2
-60
initialize.py
+1
-1
@@ -30,7 +30,7 @@ def initialize():
30
chat_model = chat_llm,
31
utility_model = utility_llm,
32
embeddings_model = embedding_llm,
33
- # prompts_subdir = "",
33
+ # prompts_subdir = "default",
34
# memory_subdir = "",
35
knowledge_subdirs = ["default","custom"],
36
auto_memory_count = 0,
instruments/default/yt_download/yt_download.md
+1
-1
@@ -1,6 +1,6 @@
1
# Problem
2
Download a YouTube video
3
# Solution
4
-1. cd to the desired location to download
4
+1. If folder is specified, cd to it
5
2. Run instrument "bash /instruments/default/yt_download/yt_download.sh <url>" with your video URL
6
3. Wait for the terminal to finish
\ No newline at end of file
instruments/default/yt_download/yt_download.py
deleted
-58
@@ -1,58 +0,0 @@
1
-import subprocess
2
-import sys
3
-import os
4
-import argparse
5
-
6
-def install_yt_dlp():
7
- """Install yt-dlp using pip if it's not already installed."""
8
- try:
9
- __import__('yt_dlp')
10
- except ImportError:
11
- print("yt-dlp not found. Installing...")
12
- subprocess.check_call([sys.executable, "-m", "pip", "install", "yt-dlp"])
13
-
14
-def is_ffmpeg_installed():
15
- """Check if ffmpeg is installed by trying to run 'ffmpeg -version'."""
16
- try:
17
- subprocess.run(["ffmpeg", "-version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
18
- return True
19
- except FileNotFoundError:
20
- return False
21
-
22
-def install_ffmpeg():
23
- """Install ffmpeg on Linux using apt-get if it's not already installed."""
24
- if is_ffmpeg_installed():
25
- print("ffmpeg is already installed.")
26
- return
27
-
28
- print("ffmpeg not found. Installing using apt-get...")
29
- subprocess.check_call(["sudo", "apt-get", "install", "-y", "ffmpeg"])
30
-
31
-def download_video(url):
32
- """Download video using yt-dlp."""
33
- install_yt_dlp()
34
-
35
- yt_dlp = __import__('yt_dlp')
36
-
37
- if not is_ffmpeg_installed():
38
- install_ffmpeg()
39
-
40
- ydl_opts = {
41
- 'format': 'bestvideo+bestaudio/best', # Download best video and audio separately, merge them
42
- 'outtmpl': '%(title)s.%(ext)s', # Output file naming pattern
43
- 'merge_output_format': 'mp4', # Output format after merging
44
- }
45
-
46
- with yt_dlp.YoutubeDL(ydl_opts) as ydl: # type: ignore
47
- ydl.download([url])
48
-
49
-if __name__ == "__main__":
50
-
51
- # Parse command-line arguments
52
- parser = argparse.ArgumentParser(description='Download video from a URL using yt-dlp.')
53
- parser.add_argument('url', help='The URL of the video to download')
54
-
55
- args = parser.parse_args()
56
-
57
- # Download the video from the provided URL
58
- download_video(args.url)