| echo "Downloading images..." | |
| mkdir -p images_new | |
| # Read the CSV file | |
| input="youtube_new.csv" | |
| row_num=0 # Initialize a row counter | |
| while IFS=',' read -r line || [[ -n "$line" ]] | |
| do | |
| row_num=$((row_num + 1)) # Increment the row counter | |
| # Skip the first row | |
| if [ $row_num -eq 1 ]; then | |
| continue | |
| fi | |
| # Locate the "video_id" column (assuming it's the first column) | |
| video_id=$(echo $line | cut -d',' -f 1) | |
| url="https://img.youtube.com/vi/${video_id}/maxresdefault.jpg" | |
| output="images_new/${video_id}.jpg" | |
| wget -O "$output" "$url" 2>/dev/null | |
| # Check if wget was successful and the file is a proper image | |
| if [[ $? -ne 0 || ! $(file --mime-type -b "$output") =~ ^image/ ]]; then | |
| echo "Failed to download or invalid image for video_id: $video_id" | |
| rm -f "$output" # Optional: remove the invalid file | |
| fi | |
| done < "$input" | |
| # #!/bin/bash | |
| # mkdir -p images_new | |
| # # Read the CSV file | |
| # input="youtube_new.csv" | |
| # while IFS=',' read -r line || [[ -n "$line" ]] | |
| # do | |
| # # Locate the "video_id" column (assuming it's the first column) | |
| # video_id=$(echo $line | cut -d',' -f 1) | |
| # url="https://img.youtube.com/vi/${video_id}/maxresdefault.jpg" | |
| # output="images_new/${video_id}.jpg" | |
| # wget -O "$output" "$url" 2>/dev/null | |
| # # Check if wget was successful and the file is a proper image | |
| # if [[ $? -ne 0 || ! $(file --mime-type -b "$output") =~ ^image/ ]]; then | |
| # echo "Failed to download or invalid image for video_id: $video_id" | |
| # rm -f "$output" # Optional: remove the invalid file | |
| # fi | |
| # done < "$input" | |