diff --git a/download b/download index 5cf7b2c..6c733bb 100644 --- a/download +++ b/download @@ -88,11 +88,11 @@ download_github_directory() { echo "API Response Contents:" echo "$contents" - # Parse and download each file and directory recursively + # Parse and download each file echo "Parsing and downloading files..." echo "$contents" | grep '"type": "file"' | while read -r line; do - file_path=$(echo "$line" | sed -n 's|.*"path": "\([^"]*\)".*|\1|p') - download_url=$(echo "$line" | sed -n 's|.*"download_url": "\([^"]*\)".*|\1|p') + file_path=$(echo "$line" | grep -Po '"path": "\K[^"]+') + download_url=$(echo "$line" | grep -Po '"download_url": "\K[^"]+') if [ -n "$file_path" ] && [ -n "$download_url" ]; then file_name=$(basename "$file_path") @@ -103,9 +103,10 @@ download_github_directory() { fi done + # Parse and handle subdirectories echo "Parsing and handling directories..." echo "$contents" | grep '"type": "dir"' | while read -r line; do - sub_dir=$(echo "$line" | sed -n 's|.*"path": "\([^"]*\)".*|\1|p') + sub_dir=$(echo "$line" | grep -Po '"path": "\K[^"]+') if [ -n "$sub_dir" ]; then echo "Recursively handling directory: $sub_dir" download_github_directory "https://github.com/$owner_repo/tree/$branch/$sub_dir" "$output_dir"