diff --git a/modules/yt-dlp.nix b/modules/yt-dlp.nix index 322d966..f14f1f7 100644 --- a/modules/yt-dlp.nix +++ b/modules/yt-dlp.nix @@ -133,6 +133,8 @@ in local playlist_mode=false local max_downloads="" local custom_retries="" + local min_duration="" + local max_duration="" local url="" # Parse arguments @@ -142,7 +144,7 @@ in playlist_mode=true shift ;; - -n|--max) + -n|--count) max_downloads="$2" shift 2 ;; @@ -150,6 +152,14 @@ in custom_retries="$2" shift 2 ;; + --min) + min_duration="$2" + shift 2 + ;; + --max) + max_duration="$2" + shift 2 + ;; youtube|bilibili) platform="$1" shift @@ -165,15 +175,23 @@ in # Validate inputs if [[ -z "$platform" ]] || [[ -z "$url" ]]; then - echo "Usage: dlv [-p|--playlist] [-n|--max ] [-r|--retries ] " + echo "Usage: dlv [OPTIONS] " echo "" echo "Arguments:" - echo " youtube|bilibili Platform to download from" + echo " youtube|bilibili Platform to download from" echo "" echo "Options:" - echo " -p, --playlist Download as playlist" - echo " -n, --max Limit number of videos to process/download" - echo " -r, --retries Number of retry attempts (0 for no retries, default: 10)" + echo " -p, --playlist Download as playlist" + echo " -n, --count Limit number of videos to process/download" + echo " -r, --retries Number of retry attempts (0 for no retries, default: 10)" + echo " --min Minimum video duration in minutes" + echo " --max Maximum video duration in minutes" + echo "" + echo "Examples:" + echo " dlv youtube - Download single YouTube video" + echo " dlv youtube -p - Download YouTube playlist" + echo " dlv youtube --min 5 --max 30 - Download videos between 5-30 minutes" + echo " dlv bilibili -p -n 10 - Download first 10 videos from playlist" return 1 fi @@ -195,6 +213,23 @@ in ;; esac + # Build duration filter + local duration_filter="" + if [[ -n "$min_duration" ]] || [[ -n "$max_duration" ]]; then + local min_sec="" + local max_sec="" + [[ -n "$min_duration" ]] && min_sec=$((min_duration * 60)) + [[ -n "$max_duration" ]] && max_sec=$((max_duration * 60)) + + if [[ -n "$min_sec" ]] && [[ -n "$max_sec" ]]; then + duration_filter="--match-filter \"duration >= $min_sec & duration <= $max_sec\"" + elif [[ -n "$min_sec" ]]; then + duration_filter="--match-filter \"duration >= $min_sec\"" + elif [[ -n "$max_sec" ]]; then + duration_filter="--match-filter \"duration <= $max_sec\"" + fi + fi + # Build output template based on playlist mode local output_template if [[ "$playlist_mode" == true ]]; then @@ -218,7 +253,7 @@ in echo "Output directory: $DOWNLOAD_DIR/$platform_name" # Build command - local cmd="yt-dlp $platform_flags" + local cmd="yt-dlp $platform_flags $duration_filter" if [[ "$playlist_mode" == true ]]; then cmd="$cmd --yes-playlist" fi