]> Arthur Taft Gitweb - yt-dlp-wrapper.git/blob - linux/yt-dlp-wrapper.sh
Add batch script
[yt-dlp-wrapper.git] / linux / yt-dlp-wrapper.sh
1 #!/bin/bash
2
3 # Define variables
4 current_dir="$PWD"
5 exe_location="$current_dir"/bin/yt-dlp
6 ffmpeg_location=/usr/bin/ffmpeg
7 audio_dir="$current_dir"/audio
8 video_dir="$current_dir"/video
9 val=0
10 url=""
11 type=""
12
13 # Function to hold audio download command
14 audio_dl () {
15     "$exe_location" -x -f 'ba' --audio-format mp3 -o "$audio_dir/%(title)s.%(ext)s" "$url"
16 }
17
18 # Function to hold video download command
19 video_dl () {
20     "$exe_location" -f 'bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4] / bv*+ba/b' -o "$video_dir/%(title)s.%(ext)s" "$url"
21 }
22
23 # Check if ffmpeg is installed
24 if [ ! "$ffmpeg_location" ]; then
25     echo "Missing dependency ffmpeg"
26     exit 1
27 fi 
28
29 # Remove executable
30 if [ "$exe_location" ]; then
31     rm "$exe_location"
32 fi
33
34 # Download new executable
35 wget -q -O "$exe_location" https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp
36
37 # Make executable executable
38 chmod +x "$exe_location"
39
40 # Check if audio directory exists, if not, create it
41 if [ ! "$audio_dir" ]; then
42     mkdir audio
43 fi
44
45 # Check if video directory exists, if not, create it
46 if [ ! "$video_dir" ]; then
47     mkdir video
48 fi
49
50 # While loop to contain download logic
51 while [ "$val" -ne 1 ]; do
52     # Ask user if they want to download audio or video
53     read -p "Audio or Video?: " type
54
55     # Download audio
56     if [ "$type" = "audio" ]; then
57         read -p "Enter URL Here: " url
58         audio_dl
59         val=1
60     # Download video
61     elif [ "$type" = "video" ]; then
62         read -p "Enter URL Here: " url
63         video_dl
64         val=1
65     # If invlaid response is given, start over
66     else
67         echo "Must be 'Audio' or 'Video'!"
68         continue
69     fi
70 done
71
72 # If you made it here you get a sweet exit code 0
73 exit 0