nirish

config files for niri window manager
Log | Files | Refs | README | LICENSE

vidl (5671B)


      1 #!/usr/bin/env bash
      2 
      3 set -eou pipefail
      4 
      5 check_deps(){
      6 	app_list=(yt-dlp gum)
      7 	for app in "${app_list[@]}"; do
      8 		_have=$(command -v "$app")
      9 		if [ -z "$_have" ]; then
     10 			printf "%b\n" "$app is not installed."
     11 			exit 1
     12 		fi
     13 	done
     14 }
     15 
     16 msg() {
     17     case "$1" in
     18         "error") gum log --structured --level error "$2"; exit 1 ;;
     19         "info") gum log --structured --level info "$2" ;;
     20         "success") gum log --structured --level success "$2" ;;
     21         "complete") gum spin --spinner "globe" --title "Done! Press any key to close..." -- bash -c 'read -n 1 -s' ;;
     22     esac
     23 }
     24 
     25 # Check for dependencies
     26 check_deps
     27 
     28 Url=$(gum input --header.bold --header.foreground="#FCB8EF" --header="URL of video:" --placeholder="Enter URL..." || msg error "Please enter a url.")
     29 VideoDownloadMode=$(gum choose --header="How many files to download:" --header.bold --header.foreground="#FCB8EF" "Single" "Batch" || msg error "Please choose a video download mode.")
     30 DownloadDirectory=$(find "$HOME/Videos" -type d | fzf --layout=reverse --height=50% --border || msg error "Did not select a download directory.")
     31 
     32 if [ -n "$Url" ]; then
     33     case "$VideoDownloadMode" in
     34         Single)
     35             VideoQuality=$(gum choose --header="Choose video quality:" --header.bold --header.foreground="#FCB8EF" "Default" "720p" "1080p" || msg error "Please choose video quality.")
     36             case "$VideoQuality" in
     37                 Default)
     38                     SeekOptions=$(gum choose --header="Download a portion of video?" --header.bold --header.foreground="#FCB8EF" "1. No Seek" "2. One point to Another" "3. One point to End of video")
     39                     case "$SeekOptions" in
     40                         1*)
     41                             yt-dlp -N 5 -o "$DownloadDirectory/%(title)s.%(ext)s" "$Url"
     42                             ;;
     43                         2*)
     44                             StartSeek=$(gum input --header.bold --header.foreground="#FCB8EF" --header="Enter seek start point:" --placeholder="HH:MM:SS or MM:SS or seconds")
     45                             EndSeek=$(gum input --header.bold --header.foreground="#FCB8EF" --header="Enter seek end point:" --placeholder="HH:MM:SS or MM:SS or seconds")
     46                             yt-dlp --download-sections "*$StartSeek-$EndSeek" -o "$DownloadDirectory/%(title)s.%(ext)s" "$Url"
     47                             ;;
     48                         3*)
     49                             StartSeek=$(gum input --header.bold --header.foreground="#FCB8EF" --header="Enter seek start point:" --placeholder="HH:MM:SS or MM:SS or seconds")
     50                             yt-dlp --download-sections "*$StartSeek-inf" -N 5 -o "$DownloadDirectory/%(title)s.%(ext)s" "$Url"
     51                             ;;
     52                     esac
     53                     ;;
     54                 720p)
     55                     SeekOptions=$(gum choose --header="Download a portion of video?" --header.bold --header.foreground="#FCB8EF" "1. No Seek" "2. One point to Another" "3. One point to End of video")
     56                     case "$SeekOptions" in
     57                         1*)
     58                             yt-dlp -f "best[height<=720]" -N 5 -o "$DownloadDirectory/%(title)s.%(ext)s" "$Url"
     59                             ;;
     60                         2*)
     61                             StartSeek=$(gum input --header.bold --header.foreground="#FCB8EF" --header="Enter seek start point:" --placeholder="HH:MM:SS or MM:SS or seconds")
     62                             EndSeek=$(gum input --header.bold --header.foreground="#FCB8EF" --header="Enter seek end point:" --placeholder="HH:MM:SS or MM:SS or seconds")
     63                             yt-dlp -f "best[height<=720]" --download-sections "*$StartSeek-$EndSeek" -o "$DownloadDirectory/%(title)s.%(ext)s" "$Url"
     64                             ;;
     65                         3*)
     66                             StartSeek=$(gum input --header.bold --header.foreground="#FCB8EF" --header="Enter seek start point:" --placeholder="HH:MM:SS or MM:SS or seconds")
     67                             yt-dlp -f "best[height<=720]" --download-sections "*$StartSeek-inf" -N 5 -o "$DownloadDirectory/%(title)s.%(ext)s" "$Url"
     68                             ;;
     69                     esac
     70                     ;;
     71                 1080p)
     72                     SeekOptions=$(gum choose --header="Download a portion of video?" --header.bold --header.foreground="#FCB8EF" "1. No Seek" "2. One point to Another" "3. One point to End of video")
     73                     case "$SeekOptions" in
     74                         1*)
     75                             yt-dlp -f "best[height<=1080]" -N 5 -o "$DownloadDirectory/%(title)s.%(ext)s" "$Url"
     76                             ;;
     77                         2*)
     78                             StartSeek=$(gum input --header.bold --header.foreground="#FCB8EF" --header="Enter seek start point:" --placeholder="HH:MM:SS or MM:SS or seconds")
     79                             EndSeek=$(gum input --header.bold --header.foreground="#FCB8EF" --header="Enter seek end point:" --placeholder="HH:MM:SS or MM:SS or seconds")
     80                             yt-dlp -f "best[height<=1080]" --download-sections "*$StartSeek-$EndSeek" -o "$DownloadDirectory/%(title)s.%(ext)s" "$Url"
     81                             ;;
     82                         3*)
     83                             StartSeek=$(gum input --header.bold --header.foreground="#FCB8EF" --header="Enter seek start point:" --placeholder="HH:MM:SS or MM:SS or seconds")
     84                             yt-dlp -f "best[height<=1080]" --download-sections "*$StartSeek-inf" -N 5 -o "$DownloadDirectory/%(title)s.%(ext)s" "$Url"
     85                             ;;
     86                     esac
     87                     ;;
     88             esac
     89             ;;
     90         Batch) ;;
     91     esac
     92 fi
     93 
     94 msg complete