我正在尝试从同一个 YouTube 视频 URL 下载简短的部分,但有些视频由于已经下载而被跳过下载。
#!/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
输入csv文件格式如下:
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
尝试使用开始和结束时间生成文件名: -o "%(id)s-%(section_start)s-%(section_end)s.%(ext)s"