My wrapper for youtube-dl for download lessons
When my spouse or I buy a video lecture course, we want to have that content because we paid for it. But there are situations where the course platform won’t let us download the videos, and over time, access to the lectures can disappear for a variety of reasons.
I always download my lectures for myself and make backups on an external drive.
How do I download? I used to use VLC player and ffmpeg. But now I do everything via youtube-dl.
To authorize in the system I prepare a file cookies.txt
For this I use extension Get cookies.txt
Then I find through the web inspector (usually, but there are exceptions) the m3u file used by the player.
To avoid typing file names by hand, I made a simple counter. The script looks through the files and looks for the last lecture, takes its number and adds one.
#!/bin/zsh
function get_video_file() {
youtube-dl --cookies ./cookies.txt "$1" -o $2
}
# Iterate through the file names
for file in $(ls lesson-*.mp4)
do
# Extract the last numeric field from the file name
file="${file%.*}"
# Extract the number preceded by a hyphen using the cut command
number_with_hyphen=$(cut -d '-' -f 2 <<< "$file")
# Remove the hyphen from the number using parameter expansion
number=${number_with_hyphen/-/}
done
last_lesson="lesson-$number.mp4"
echo "Last lesson $last_lesson"
((number++))
next_lesson="lesson-$number.mp4"
echo "Next lesson name $next_lesson"
get_video_file "$1" "$next_lesson"
Try :)