yt dlp - andyceo/documentation GitHub Wiki

yt-dlp

Бывший youtube-dl.

Разные сценарии

  • скачать лучшее качество в формате WEBM, используя прокси: yt-dlp --proxy "http://username:password@your_proxy.com:port" "https://www.youtube.com/watch?v=VIDEO_ID"
  • download the best quality WEBM under 50MB: yt-dlp -f "webm[filesize<50M]" <video_url>
  • download the best quality MP4 instead of WEBM: yt-dlp -f "best,mp4" <video_url>
  • download the best available format and recode it to MP4: yt-dlp <video_url> --recode mp4

Скачать субтитры

  • посмотреть доступные субтитры для видео: yt-dlp --list-subs <URL>

  • скачать все доступные (не автоматически сгенерированные): youtube-dl --all-subs --skip-download <URL>

  • скачать только автоматически сгенерированные yt-dlp --write-auto-sub --skip-download <URL>

  • скачать субтитры, а затем убрать форматирование, т.е. оставить только текст (отсюда):

      # сначала скачать субтитры
      yt-dlp --skip-download --write-subs --write-auto-subs  --sub-lang en --sub-format ttml --convert-subs srt <URL>
    
      # оставить только текст
      sed -e \
        '/^[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9] --> [0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9]$/d' \
        -e '/^[[:digit:]]\{1,3\}$/d' -e 's/<[^>]*>//g' \
        -e '/^[[:space:]]*$/d' -i '' <FILENAME>
    

Полезные ссылки

yt-dlp
-f "bestvideo+bestaudio/best"
-o "%(title)s.%(ext)s"
--verbose
--cookies /tmp/cookies.txt
--referer "https://example.com/"
--user-agent "Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0"
--add-header "Origin:https://example.com"
--add-header "Referer:https://example.com/"
--concurrent-fragments 5
--downloader ffmpeg --hls-use-mpegts
--extractor-arg "generic:hls_key=URL,KEYHEX"
"https://URL/TO/playlist.m3u8"

Перевести ключ, представленный в кодировке base64, в 16-ричный формат, который нужен yt-dlp:

$ echo twWuUoB8NHy3WnK7 | openssl  base64 -A -d | xxd -ps
$ b705ae52807c347cb75a72bb

Или использовать следующий Python-код:

#!/usr/bin/env python3
import argparse
import base64

import requests


def read_cookies(cookie_file):
    cookies = {}
    with open(cookie_file, "r") as f:
        for line in f:
            if not line.startswith("#") and line.strip():
                parts = line.strip().split("\t")
                if len(parts) >= 7:
                    cookies[parts[5]] = parts[6]
    return cookies


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("cookies_file", help="Path to cookies file")
    parser.add_argument("url", help="URL to process")
    args = parser.parse_args()

    cookies = read_cookies(args.cookies_file)
    response = requests.get(args.url, cookies=cookies)
    key = base64.b64decode(response.content).hex()

    print(f"generic:hls_key={args.url},{key}")


if __name__ == "__main__":
    main()
⚠️ **GitHub.com Fallback** ⚠️