3

I'm trying to write a Python script that downloads specific sections of videos using yt-dlp.

import yt_dlp

yt_opts = {
    'verbose': True,
    'download_sections': [{
        'section': {
            'start_time': 2,
            'end_time': 7
        }
    }]
}

ydl = yt_dlp.YoutubeDL(yt_opts)

ydl.download("https://www.youtube.com/watch?v=BxUS1K7xu30")

I expected this to download the video from 2 seconds to 7, as per the reference here. This actually downloads the entire video.

[debug] Encodings: locale cp1252, fs utf-8, pref cp1252, out utf-8, error utf-8, screen utf-8 [debug] yt-dlp version 2022.08.19 [48c88e0] (pip) [debug] Python 3.10.6 (CPython 64bit) - Windows-10-10.0.19044-SP0 [debug] Checking exe version: ffmpeg -bsfs [debug] Checking exe version: ffprobe -bsfs [debug] exe versions: none [debug] Optional libraries: Cryptodome-3.15.0, brotli-1.0.9, certifi-2022.06.15, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3 [debug] Proxy map: {} [debug] [youtube] Extracting URL: https://www.youtube.com/watch?v=BxUS1K7xu30 [youtube] BxUS1K7xu30: Downloading webpage [youtube] BxUS1K7xu30: Downloading android player API JSON [debug] Sort order given by extractor: quality, res, fps, hdr:12, source, vcodec:vp9.2, channels, acodec, lang, proto [debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec:vp9.2(10), channels, acodec, lang, proto, filesize, fs_approx, tbr, vbr, abr, asr, vext, aext, hasaud, id [debug] Default format spec: best/bestvideo+bestaudio [info] BxUS1K7xu30: Downloading 1 format(s): 22 [debug] Invoking http downloader on "https://rr2---sn-ab5l6nrd.googlevideo.com/videoplayback?expire=1661691812&ei=RBMLY6GdC5CR2LYP5OaJyAU&ip=98.2.224.68&id=o-AIi857cLRkqbZzQpqEAoGwELFeyM_FqC4hfs2P24lLbK&itag=22&source=youtube&requiressl=yes&mh=Rx&mm=31%2C26&mn=sn-ab5l6nrd%2Csn-vgqsrned&ms=au%2Conr&mv=m&mvi=2&pl=15&initcwndbps=2861250&spc=lT-KhhV_37ir7IXjdc7-8htrHPmO2eY&vprv=1&svpuc=1&mime=video%2Fmp4&cnr=14&ratebypass=yes&dur=542.673&lmt=1610233906593465&mt=1661669832&fvip=3&fexp=24001373%2C24007246&c=ANDROID&rbqsm=fr&txp=5535432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Ccnr%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRQIhANDQ2r6ktEGD59h9z22QuZQ9J3Tl_EN56_UzP5Hj7M4UAiBVR7vQOBCoLQjZClr43uEfIr6Ga3IeQx05D2zML9FoPw%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIhAJ3w_I3PKsyNWp0rGC2-y-DI4qHgQnyEfP6WxDKs5Gz9AiB_XvzG2yDBJ0D4hzyudyruuztdYxcBYWsH-CSvISnjeg%3D%3D" [debug] File locking is not supported. Proceeding without locking [download] Destination: The Ideal Gas Law: Crash Course Chemistry #12 [BxUS1K7xu30].mp4

I've tried to write the 'download_sections' definition several different ways, but I can't find the right one. Do I need to write the definition differently or apply this option in another place entirely?

zack fisher
  • 31
  • 1
  • 2

0 Answers0