File size: 1,633 Bytes
e86a312 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
#!/bin/bash
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"
|