Command-line youtube downloader for watching high-resolution videos with captions offline. Audio(mp3) and captions(srt) files can be also downloaded.
To edit videos you need to install ffmpeg.
$ brew install ffmpeg
First you need to install dependencies.
$ pip install -r requirements.lock
You can also use Rye.
$ rye sync
revise .venv/lib/python3.12/site-packages/pytube/cipher.py in line 264 to the following code.
function_patterns = [
# https://github.com/ytdl-org/youtube-dl/issues/29326#issuecomment-865985377
# https://github.com/yt-dlp/yt-dlp/commit/48416bc4a8f1d5ff07d5977659cb8ece7640dcd8
# var Bpa = [iha];
# ...
# a.C && (b = a.get("n")) && (b = Bpa[0](b), a.set("n", b),
# Bpa.length || iha("")) }};
# In the above case, `iha` is the relevant function name
r'a\.[a-zA-Z]\s*&&\s*\([a-z]\s*=\s*a\.get\("n"\)\)\s*&&.*?\|\|\s*([a-z]+)',
r'\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])?\([a-z]\)',
r'\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])\([a-z]\)',
]
[UPDATE: 2024/08/11] issues
#pattern = r"%s=function\(\w\){[a-z=\.\(\"\)]*;(.*);(?:.+)}" % name
pattern = r"%s=function\(\w\){[a-z=\.\(\"\)]*;((\w+\.\w+\([\w\"\'\[\]\(\)\.\,\s]*\);)+)(?:.+)}" % name
$ python src/main.py <YOUTUBE_ID>
Since combining a video and its audio with ffmpeg is compute-intensive, you can skip the procedure with --download_only flag.
$ python src/main.py <YOUTUBE_ID> --download_only 1
$ python src/main.py <YOUTUBE_ID> -r 720p
$ python src/main.py <YOUTUBE_ID> -m audio -o music --srt 0 --metadata false -f favorite_song
This command saves the audio data of outputs/music/favorite_song.mp3
. No video, captions, or url.txt.