question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Checklist

Region

Worldwide, depending on regional video blocking

Example URLs

https://youtube.com/clip/Ugkx9hS31W7ocpw8tLKo_m-Ht7j36o5StJof https://youtube.com/clip/UgytZKpehg-hEMBSn3F4AaABCQ

Description

(Note: This is not for post-processor segment trimming, like with FFMPEG. This is for the feature on YouTube that allows you to get a 5 - 60 second clip of a video.)

Right now, YouTube clips don’t work, and instead download the entire video. While this feature is currently lacking (it’s only available on certain channels and selecting start - end is pretty bad), it’s a lot more user-friendly then with FFMPEG, and it might be able to download a part of the video, instead of downloading the whole thing and trimming it. It also means pre-existing clips can be downloaded more easily.

Verbose log

ggtylerr@pop-os:~/Downloads$ yt-dlp -vU https://youtube.com/clip/Ugkx9hS31W7ocpw8tLKo_m-Ht7j36o5StJof
[debug] Command-line config: ['-vU', 'https://youtube.com/clip/Ugkx9hS31W7ocpw8tLKo_m-Ht7j36o5StJof']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, err utf-8, pref UTF-8
[debug] yt-dlp version 2022.01.21 [f20d607b0]
[debug] Python version 3.8.10 (CPython 64bit) - Linux-5.15.15-76051515-generic-x86_64-with-glibc2.29
[debug] exe versions: ffmpeg 4.2.4, ffprobe 4.2.4
[debug] Optional libraries: Cryptodome, secretstorage, mutagen, sqlite, websockets
[debug] Proxy map: {}
Latest version: 2022.01.21, Current version: 2022.01.21
yt-dlp is up to date (2022.01.21)
[debug] [youtube:clip] Extracting URL: https://youtube.com/clip/Ugkx9hS31W7ocpw8tLKo_m-Ht7j36o5StJof
WARNING: [youtube:clip] YouTube clips are not currently supported. The entire video will be downloaded instead
[debug] [generic] Extracting URL: https://youtube.com/clip/Ugkx9hS31W7ocpw8tLKo_m-Ht7j36o5StJof
[generic] Ugkx9hS31W7ocpw8tLKo_m-Ht7j36o5StJof: Requesting header
[redirect] Following redirect to https://www.youtube.com/clip/Ugkx9hS31W7ocpw8tLKo_m-Ht7j36o5StJof
[debug] [youtube:clip] Extracting URL: https://www.youtube.com/clip/Ugkx9hS31W7ocpw8tLKo_m-Ht7j36o5StJof
WARNING: [youtube:clip] YouTube clips are not currently supported. The entire video will be downloaded instead
[debug] [generic] Extracting URL: https://www.youtube.com/clip/Ugkx9hS31W7ocpw8tLKo_m-Ht7j36o5StJof
[generic] Ugkx9hS31W7ocpw8tLKo_m-Ht7j36o5StJof: Requesting header
WARNING: [generic] Falling back on generic information extractor.
[generic] Ugkx9hS31W7ocpw8tLKo_m-Ht7j36o5StJof: Downloading webpage
[generic] Ugkx9hS31W7ocpw8tLKo_m-Ht7j36o5StJof: Extracting information
[debug] Looking for video embeds
[debug] Identified a twitter:player iframe
[debug] [youtube] Extracting URL: https://www.youtube.com/embed/Jljy8KtoXOU?clip=Ugkx9hS31W7ocpw8tLKo_m-Ht7j36o5StJof&clipt=EIOqHBiv4Bw
[youtube] Jljy8KtoXOU: Downloading webpage
[youtube] Jljy8KtoXOU: Downloading android player API JSON
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, codec:vp9.2, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec:vp9.2(10), acodec, lang, proto, filesize, fs_approx, tbr, vbr, abr, asr, vext, aext, hasaud, id
[debug] Default format spec: bestvideo*+bestaudio/best
[info] Jljy8KtoXOU: Downloading 1 format(s): 248+251
[debug] Invoking downloader on "https://rr5---sn-a5mekned.googlevideo.com/videoplayback?expire=1643548302&ei=LTr2YajaO87zkgbYq7igAQ&ip=2600%3A8801%3A1333%3Aed00%3A2548%3A916e%3Ab5a2%3Adec6&id=o-AH5tMXeS8SK2NBVSfYgY5wO_SwOAe5nW4lSe5elQATt6&itag=248&source=youtube&requiressl=yes&mh=C2&mm=31%2C26&mn=sn-a5mekned%2Csn-n4v7sn7y&ms=au%2Conr&mv=m&mvi=5&pl=40&initcwndbps=2132500&vprv=1&mime=video%2Fwebm&gir=yes&clen=348986307&dur=1572.300&lmt=1586412459679522&mt=1643526288&fvip=5&keepalive=yes&fexp=24001373%2C24007246&c=ANDROID&txp=5535432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRQIgQK_RuPwxfFnrISESxlVdiXIJBlpBSLVdGwDOcVlCjaICIQDVp9Yixk61yJKAmzySAKjyiZ-H83wJ7oekyO3LgQMDWg%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRAIgXfTiGWCuosSN_NaOrzc8wdJQ4WXBMXVHL0CEHqaLOUkCIFgVtI_e4b5mppcHcdt8flVcQrZ3lwB2npnxetd7Vxjh"
[download] Destination: Game Collecting - Scott The Woz [Jljy8KtoXOU].f248.webm
[download] 100% of 332.82MiB in 00:20
[debug] Invoking downloader on "https://rr5---sn-a5mekned.googlevideo.com/videoplayback?expire=1643548302&ei=LTr2YajaO87zkgbYq7igAQ&ip=2600%3A8801%3A1333%3Aed00%3A2548%3A916e%3Ab5a2%3Adec6&id=o-AH5tMXeS8SK2NBVSfYgY5wO_SwOAe5nW4lSe5elQATt6&itag=251&source=youtube&requiressl=yes&mh=C2&mm=31%2C26&mn=sn-a5mekned%2Csn-n4v7sn7y&ms=au%2Conr&mv=m&mvi=5&pl=40&initcwndbps=2132500&vprv=1&mime=audio%2Fwebm&gir=yes&clen=25550094&dur=1572.321&lmt=1586402126333409&mt=1643526288&fvip=5&keepalive=yes&fexp=24001373%2C24007246&c=ANDROID&txp=5511222&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRQIhAMRPfwtCC7aP_SeQgnkjz7Kva89TQHQzGRNttNcUWMjDAiAwY6wBLLV3ETMuip1q7Tk47jrGFIdYsY7OL8uCSgbcPw%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRAIgXfTiGWCuosSN_NaOrzc8wdJQ4WXBMXVHL0CEHqaLOUkCIFgVtI_e4b5mppcHcdt8flVcQrZ3lwB2npnxetd7Vxjh"
[download] Destination: Game Collecting - Scott The Woz [Jljy8KtoXOU].f251.webm
[download] 100% of 24.37MiB in 00:01
[Merger] Merging formats into "Game Collecting - Scott The Woz [Jljy8KtoXOU].webm"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:Game Collecting - Scott The Woz [Jljy8KtoXOU].f248.webm' -i 'file:Game Collecting - Scott The Woz [Jljy8KtoXOU].f251.webm' -c copy -map 0:v:0 -map 1:a:0 -movflags +faststart 'file:Game Collecting - Scott The Woz [Jljy8KtoXOU].temp.webm'
Deleting original file Game Collecting - Scott The Woz [Jljy8KtoXOU].f251.webm (pass -k to keep)
Deleting original file Game Collecting - Scott The Woz [Jljy8KtoXOU].f248.webm (pass -k to keep)
ggtylerr@pop-os:~/Downloads$

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
puyoxyzcommented, Jun 24, 2022

Just tried this and it’s not downloading the right part of the video? It’s downloading like, from 5 seconds (clip duration?) before start of clip to the start of the clip, not from the start of the clip to the end of the clip

Here’s the clip I tried to download: https://youtube.com/clip/UgkxdIc_hmqiDzYn3zoGbskyrVEnI4t_1Sod

And here’s what it gave me: https://image-host.club/ih0tco.webm ( github doesn’t support webm uploads 😦 )

(yt-dlp compiled just now, through the AUR package yt-dlp-git)

2reactions
pukkandancommented, Jun 6, 2022

#52 is now closed. Once an extractor for clips is written, this should be all the core changes needed to make the download work:

diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py
index 8fff9ddc0..ddba8d5df 100644
--- a/yt_dlp/YoutubeDL.py
+++ b/yt_dlp/YoutubeDL.py
@@ -2443,7 +2443,9 @@ def sanitize_numeric_fields(info):

         sanitize_string_field(info_dict, 'id')
         sanitize_numeric_fields(info_dict)
-        if (info_dict.get('duration') or 0) <= 0 and info_dict.pop('duration', None):
+        if info_dict.get('section_end') and info_dict.get('section_start') is not None:
+            info_dict['duration'] = info_dict['section_end'] - info_dict['section_start']
+        elif (info_dict.get('duration') or 0) <= 0 and info_dict.pop('duration', None):
             self.report_warning('"duration" field is negative, there is an error in extractor')

         if 'playlist' not in info_dict:
@@ -2678,10 +2680,11 @@ def to_screen(*msg):
             for fmt, chapter in itertools.product(formats_to_download, requested_ranges or [{}]):
                 new_info = self._copy_infodict(info_dict)
                 new_info.update(fmt)
-                if chapter:
+                offset, duration = info_dict.get('section_start') or 0, info_dict.get('duration') or float('inf')
+                if chapter or offset:
                     new_info.update({
-                        'section_start': chapter.get('start_time'),
-                        'section_end': chapter.get('end_time', 0),
+                        'section_start': offset + chapter.get('start_time', 0),
+                        'section_end': offset + min(chapter.get('end_time', 0), duration),
                         'section_title': chapter.get('title'),
                         'section_number': chapter.get('index'),
                     })
diff --git a/yt_dlp/extractor/common.py b/yt_dlp/extractor/common.py
index 316b58ce3..bd5215ad7 100644
--- a/yt_dlp/extractor/common.py
+++ b/yt_dlp/extractor/common.py
@@ -385,6 +385,11 @@ class InfoExtractor:
     release_year:   Year (YYYY) when the album was released.
     composer:       Composer of the piece

+    The following fields should only be set for clips that should be cut from the original video:
+
+    section_start:  Start time of the section in seconds
+    section_end:    End time of the section in seconds
+
     Unless mentioned otherwise, the fields should be Unicode strings.

     Unless mentioned otherwise, None is equivalent to absence of information.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Share clips - YouTube Help
Select and share a small portion (clip) of a video or live stream with others by clipping it. Clips can be shared on...
Read more >
What Are YouTube Clips and How Do You Use Them?
Video Clips on YouTube are a new way for content creators and viewers to share bite-sized Clips of longer videos and live streams....
Read more >
How to Make YouTube Clips - Social Media Examiner
You can use a similar workflow to create clips from the YouTube app. Open one of your channel's videos and tap the Clip...
Read more >
The ultimate guide to YouTube's Clip button | Clipchamp Blog
The Clip button, also known as the scissor icon, lets anyone select and share 5 to 60 seconds of an existing YouTube video....
Read more >
YouTube's new “Clips” feature lets users share 60-second ...
YouTube's new “Clips” feature lets users share 60-second clips of videos · Just like on Twitch, "clips" lets users chop up and share...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found