0

I am trying to download short portions from same youtube video URL but some how many videos are getting skipped from downloading as it was already downloaded.

#!/bin/bash
missing=false
while IFS=, read -r url start_time_z end_time_z
do
    if [ "$url" == "" ]
    then
        echo "url is empty or no value set"
        missing=true
    elif [ "$start_time_z" == "" ]
    then
        echo "Start Time is empty or no value set for URL: $url"
        missing=true
    elif [ "$end_time_z" == "" ]
        then
                echo "End Time is empty or no value set for URL: $url"
                missing=true
        else
    
        echo "Downloading: $url | Start Time: $start_time_z | End Time: $end_time_zc
        echo "-------------------------------------------------------------------------------------------------------------"
        yt-dlp -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]" \
        --download-sections "*$start_time_z-$end_time_z" --restrict-filenames \
        -o "%(id)s_%(title)s_%(duration)s.%(ext)s" "$url" \
        --cookies /home/user1/yt-downloads/youtube_cookie.txt
                echo "-------------------------------------------------------------------------------------------------------------"
    fi
done < $1
if [ $missing ]
then
    echo "WARNING: Missing values in a CSV file. Please use the proper format. Operation failed."
    exit 1
else
    echo "CSV file read successfully."
fi

input csv file format as follows:

https://www.youtube.com/watch?v=tdjQkXmxGms,50:39:00,57:12:00
https://www.youtube.com/watch?v=tdjQkXmxGms,50:39:00,55:43:00
https://www.youtube.com/watch?v=ktx3Jc0ctEw,4:47:00,9:28:00
https://www.youtube.com/watch?v=TmQyZ4fopm8,37:03:00,40:08:00
https://www.youtube.com/watch?v=rzPpH0WJpHo,18:55:00,20:15:00
https://www.youtube.com/watch?v=dpCJeFcH338,1:19:00,5:24:00
Yashodhan K
  • 83
  • 1
  • 5

0 Answers0