Last active
November 5, 2023 20:22
-
-
Save szepeviktor/a09ebd63d465a5502460e0e2904e9562 to your computer and use it in GitHub Desktop.
Get YouTube download URL-s of video and audio
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 | |
# Save HTML | |
wget -O watch.html "https://www.youtube.com/watch?v=VIDEO_ID" | |
# Extract player data | |
sed -n -e 's#.*var ytInitialPlayerResponse = \({[^<]\+}\);</script>.*#\1#p' <watch.html >video.json | |
# For HTML from the browser | |
#sed -n -e 's#.*var ytInitialPlayerResponse = \({[^<]\+}\);var meta = .*#\1#p' <watch.html >video.json | |
# Get URL for best video format | |
jq -r '."streamingData"."adaptiveFormats"[] | select(."itag" == 298) | ."url"' video.json | |
#jq -r '."streamingData"."adaptiveFormats"[] | select(."itag" == 137) | ."url"' video.json | |
# Get URL for best audio format | |
jq -r '."streamingData"."adaptiveFormats"[] | select(."itag" == 140) | ."url"' video.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment