Last active
September 21, 2024 14:50
-
-
Save azimut/e556bc106cdeabd89e3cf249b874cbaa to your computer and use it in GitHub Desktop.
download all the neetcode vides, with proper ranking/category classification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -xuo pipefail | |
declare -A urls | |
urls[easy]='https://www.youtube.com/playlist?list=PLot-Xpze53lfQmTEztbgdp8ALEoydvnRQ' | |
urls[medium]='https://www.youtube.com/playlist?list=PLot-Xpze53lfOdF3KwpMSFEyfE77zIwiP' | |
urls[hard]='https://www.youtube.com/playlist?list=PLot-Xpze53letfIu9dMzIIO7na_sqvl0w' | |
urls[sliding_window]='https://www.youtube.com/playlist?list=PLot-Xpze53leOBgcVsJBEGrHPd_7x_koV' | |
urls[stack]='https://www.youtube.com/playlist?list=PLot-Xpze53lfxD6l5pAGvCD4nPvWKU8Qo' | |
urls[graph]='https://www.youtube.com/playlist?list=PLot-Xpze53ldBT_7QA8NVot219jFNr_GI' | |
urls[backtracking]='https://www.youtube.com/playlist?list=PLot-Xpze53lf5C3HSjCnyFghlW0G1HHXo' | |
urls[tree]='https://www.youtube.com/playlist?list=PLot-Xpze53ldg4pN6PfzoJY7KsKcxF1jg' | |
urls[binary_search]='https://www.youtube.com/playlist?list=PLot-Xpze53leNZQd0iINpD-MAhMOMzWvO' | |
urls[linked_list]='https://www.youtube.com/playlist?list=PLot-Xpze53leU0Ec0VkBhnf4npMRFiNcB' | |
urls[dynamic_programming]='https://www.youtube.com/playlist?list=PLot-Xpze53lcvx_tjrr_m2lgD2NsRHlNO' | |
is_downloaded() { | |
local needles | |
local id | |
id="${1##*=}" | |
needles="$(find . -name '*\['"${id}"'\]*')" | |
[[ ${needles} != "" ]] | |
return $? | |
} | |
get_ranking() { | |
grep -q "$1" easy.txt && echo "easy" && return | |
grep -q "$1" medium.txt && echo "medium" && return | |
grep -q "$1" hard.txt && echo "hard" && return | |
echo "unranked" | |
} | |
get_playlist() { yt-dlp --print webpage_url --flat-playlist "$1"; } | |
get_video() { yt-dlp -S tbr -f 'worstvideo[height>360]+worstaudio[tbr!=none]' "$1"; } | |
# ------------------------------- | |
for category in "${!urls[@]}"; do | |
filename="${category}.txt" | |
[[ -f ${filename} ]] && continue | |
get_playlist "${urls[$category]}" | tee "${filename}" | |
done | |
mkdir -p easy medium hard unranked | |
for category in "${!urls[@]}"; do | |
[[ ${category} =~ easy|medium|hard ]] && | |
continue | |
mkdir -p {easy,medium,hard,unranked}/"${category}" | |
filename="${category}.txt" | |
while read -r video_url; do | |
is_downloaded "${video_url}" && | |
continue | |
ranking="$(get_ranking "${video_url}")" | |
cd ${ranking}/${category} || exit 1 | |
get_video "${video_url}" | |
cd - | |
done <"${filename}" | |
done | |
for category in easy medium hard; do | |
filename="${category}.txt" | |
while read -r video_url; do | |
if ! is_downloaded "${video_url}"; then | |
cd "${category}"/ || exit 1 | |
get_video "${video_url}" | |
cd - | |
fi | |
done <"${filename}" | |
done | |
find . -type d -empty -delete | |
tree -P '*mp4|*mkv' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment