This repository was archived by the owner on Mar 28, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathmedia-download
More file actions
executable file
·91 lines (74 loc) · 2.24 KB
/
Copy pathmedia-download
File metadata and controls
executable file
·91 lines (74 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
source "$HOME/.local/share/dotfiles/bin/lib/helpers.sh"
clear
log_header "Media Downloader"
url=$(gum input --prompt "Media URL: " --placeholder "YouTube, Reddit, Instagram...")
if [[ -z "$url" ]]; then
log_info "Cancelled"
exit 0
fi
# Validate URL with yt-dlp
echo
if ! spinner "Validating URL..." yt-dlp --dump-json --quiet --no-warnings "$url" > /dev/null 2>&1; then
log_error "URL not supported or invalid"
show_done
exit 1
fi
log_success "Site supported!"
echo
type=$(gum choose --header "Select download type" "Video" "Audio")
if [[ -z "$type" ]]; then
log_info "Cancelled"
exit 0
fi
download_dir="$HOME/Downloads"
if [[ "$type" == "Video" ]]; then
echo
quality=$(gum choose --header "Select video quality" "Best Quality" "1080p" "720p" "480p" "360p")
if [[ -z "$quality" ]]; then
log_info "Cancelled"
exit 0
fi
case "$quality" in
"Best Quality")
format_spec="bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"
;;
"1080p")
format_spec="bestvideo[height<=1080][ext=mp4]+bestaudio[ext=m4a]/best[height<=1080]"
;;
"720p")
format_spec="bestvideo[height<=720][ext=mp4]+bestaudio[ext=m4a]/best[height<=720]"
;;
"480p")
format_spec="bestvideo[height<=480][ext=mp4]+bestaudio[ext=m4a]/best[height<=480]"
;;
"360p")
format_spec="bestvideo[height<=360][ext=mp4]+bestaudio[ext=m4a]/best[height<=360]"
;;
esac
echo
if spinner "Downloading video ($quality)..." yt-dlp -f "$format_spec" --quiet --no-warnings -o "$download_dir/%(title)s.%(ext)s" "$url"; then
log_success "Video saved to ~/Downloads"
else
log_error "Download failed"
show_done
exit 1
fi
elif [[ "$type" == "Audio" ]]; then
echo
audio_format=$(gum choose --header "Select audio format" "MP3" "M4A" "Opus" "FLAC")
if [[ -z "$audio_format" ]]; then
log_info "Cancelled"
exit 0
fi
audio_format=$(echo "$audio_format" | tr '[:upper:]' '[:lower:]')
echo
if spinner "Downloading audio ($audio_format)..." yt-dlp -x --audio-format "$audio_format" --quiet --no-warnings -o "$download_dir/%(title)s.%(ext)s" "$url"; then
log_success "Audio saved to ~/Downloads"
else
log_error "Download failed"
show_done
exit 1
fi
fi
show_done