1YOUTUBE-DL(1) YOUTUBE-DL(1)
2
3
4
6 youtube-dl - download videos from youtube.com or other video platforms
7
9 youtube-dl [OPTIONS] URL [URL...]
10
12 youtube-dl is a command-line program to download videos from
13 YouTube.com and a few more sites. It requires the Python interpreter,
14 version 2.6, 2.7, or 3.2+, and it is not platform specific. It should
15 work on your Unix box, on Windows or on macOS. It is released to the
16 public domain, which means you can modify it, redistribute it or use it
17 however you like.
18
20 -h, --help
21 Print this help text and exit
22
23 --version
24 Print program version and exit
25
26 -U, --update
27 Update this program to latest version. Make sure that you have
28 sufficient permissions (run with sudo if needed)
29
30 -i, --ignore-errors
31 Continue on download errors, for example to skip unavailable
32 videos in a playlist
33
34 --abort-on-error
35 Abort downloading of further videos (in the playlist or the com‐
36 mand line) if an error occurs
37
38 --dump-user-agent
39 Display the current browser identification
40
41 --list-extractors
42 List all supported extractors
43
44 --extractor-descriptions
45 Output descriptions of all supported extractors
46
47 --force-generic-extractor
48 Force extraction to use the generic extractor
49
50 --default-search PREFIX
51 Use this prefix for unqualified URLs. For example "gvsearch2:"
52 downloads two videos from google videos for youtube- dl "large
53 apple". Use the value "auto" to let youtube-dl guess ("au‐
54 to_warning" to emit a warning when guessing). "error" just
55 throws an error. The default value "fixup_error" repairs broken
56 URLs, but emits an error if this is not possible instead of
57 searching.
58
59 --ignore-config
60 Do not read configuration files. When given in the global con‐
61 figuration file /etc/youtube-dl.conf: Do not read the user con‐
62 figuration in ~/.config/youtube-dl/config (%APPDATA%/youtube-
63 dl/config.txt on Windows)
64
65 --config-location PATH
66 Location of the configuration file; either the path to the con‐
67 fig or its containing directory.
68
69 --flat-playlist
70 Do not extract the videos of a playlist, only list them.
71
72 --mark-watched
73 Mark videos watched (YouTube only)
74
75 --no-mark-watched
76 Do not mark videos watched (YouTube only)
77
78 --no-color
79 Do not emit color codes in output
80
81 Network Options:
82 --proxy URL
83 Use the specified HTTP/HTTPS/SOCKS proxy. To enable SOCKS
84 proxy, specify a proper scheme. For example
85 socks5://127.0.0.1:1080/. Pass in an empty string (--proxy "")
86 for direct connection
87
88 --socket-timeout SECONDS
89 Time to wait before giving up, in seconds
90
91 --source-address IP
92 Client-side IP address to bind to
93
94 -4, --force-ipv4
95 Make all connections via IPv4
96
97 -6, --force-ipv6
98 Make all connections via IPv6
99
100 Geo Restriction:
101 --geo-verification-proxy URL
102 Use this proxy to verify the IP address for some geo-restricted
103 sites. The default proxy specified by --proxy (or none, if the
104 option is not present) is used for the actual downloading.
105
106 --geo-bypass
107 Bypass geographic restriction via faking X-Forwarded-For HTTP
108 header
109
110 --no-geo-bypass
111 Do not bypass geographic restriction via faking X-Forwarded-For
112 HTTP header
113
114 --geo-bypass-country CODE
115 Force bypass geographic restriction with explicitly provided
116 two-letter ISO 3166-2 country code
117
118 --geo-bypass-ip-block IP_BLOCK
119 Force bypass geographic restriction with explicitly provided IP
120 block in CIDR notation
121
122 Video Selection:
123 --playlist-start NUMBER
124 Playlist video to start at (default is 1)
125
126 --playlist-end NUMBER
127 Playlist video to end at (default is last)
128
129 --playlist-items ITEM_SPEC
130 Playlist video items to download. Specify indices of the videos
131 in the playlist separated by commas like: "-- playlist-items
132 1,2,5,8" if you want to download videos indexed 1, 2, 5, 8 in
133 the playlist. You can specify range: " --playlist-items
134 1-3,7,10-13", it will download the videos at index 1, 2, 3, 7,
135 10, 11, 12 and 13.
136
137 --match-title REGEX
138 Download only matching titles (case- insensitive regex or al‐
139 phanumeric sub- string)
140
141 --reject-title REGEX
142 Skip download for matching titles (case-insensitive regex or al‐
143 phanumeric sub-string)
144
145 --max-downloads NUMBER
146 Abort after downloading NUMBER files
147
148 --min-filesize SIZE
149 Do not download any videos smaller than SIZE (e.g. 50k or
150 44.6m)
151
152 --max-filesize SIZE
153 Do not download any videos larger than SIZE (e.g. 50k or 44.6m)
154
155 --date DATE
156 Download only videos uploaded in this date
157
158 --datebefore DATE
159 Download only videos uploaded on or before this date (i.e. in‐
160 clusive)
161
162 --dateafter DATE
163 Download only videos uploaded on or after this date (i.e. in‐
164 clusive)
165
166 --min-views COUNT
167 Do not download any videos with less than COUNT views
168
169 --max-views COUNT
170 Do not download any videos with more than COUNT views
171
172 --match-filter FILTER
173 Generic video filter. Specify any key (see the "OUTPUT TEM‐
174 PLATE" for a list of available keys) to match if the key is
175 present, !key to check if the key is not present, key > NUMBER
176 (like "comment_count > 12", also works with >=, <, <=, !=, =) to
177 compare against a number, key = 'LITERAL' (like "uploader =
178 'Mike Smith'", also works with !=) to match against a string
179 literal and & to require multiple matches. Values which are not
180 known are excluded unless you put a question mark (?) after the
181 operator. For example, to only match videos that have been
182 liked more than 100 times and disliked less than 50 times (or
183 the dislike functionality is not available at the given ser‐
184 vice), but who also have a description, use --match-filter
185 "like_count > 100 & dislike_count <? 50 & description" .
186
187 --no-playlist
188 Download only the video, if the URL refers to a video and a
189 playlist.
190
191 --yes-playlist
192 Download the playlist, if the URL refers to a video and a
193 playlist.
194
195 --age-limit YEARS
196 Download only videos suitable for the given age
197
198 --download-archive FILE
199 Download only videos not listed in the archive file. Record the
200 IDs of all downloaded videos in it.
201
202 --include-ads
203 Download advertisements as well (experimental)
204
205 Download Options:
206 -r, --limit-rate RATE
207 Maximum download rate in bytes per second (e.g. 50K or 4.2M)
208
209 -R, --retries RETRIES
210 Number of retries (default is 10), or "infinite".
211
212 --fragment-retries RETRIES
213 Number of retries for a fragment (default is 10), or "infinite"
214 (DASH, hlsnative and ISM)
215
216 --skip-unavailable-fragments
217 Skip unavailable fragments (DASH, hlsnative and ISM)
218
219 --abort-on-unavailable-fragment
220 Abort downloading when some fragment is not available
221
222 --keep-fragments
223 Keep downloaded fragments on disk after downloading is finished;
224 fragments are erased by default
225
226 --buffer-size SIZE
227 Size of download buffer (e.g. 1024 or 16K) (default is 1024)
228
229 --no-resize-buffer
230 Do not automatically adjust the buffer size. By default, the
231 buffer size is automatically resized from an initial value of
232 SIZE.
233
234 --http-chunk-size SIZE
235 Size of a chunk for chunk-based HTTP downloading (e.g. 10485760
236 or 10M) (default is disabled). May be useful for bypassing
237 bandwidth throttling imposed by a webserver (experimental)
238
239 --playlist-reverse
240 Download playlist videos in reverse order
241
242 --playlist-random
243 Download playlist videos in random order
244
245 --xattr-set-filesize
246 Set file xattribute ytdl.filesize with expected file size
247
248 --hls-prefer-native
249 Use the native HLS downloader instead of ffmpeg
250
251 --hls-prefer-ffmpeg
252 Use ffmpeg instead of the native HLS downloader
253
254 --hls-use-mpegts
255 Use the mpegts container for HLS videos, allowing to play the
256 video while downloading (some players may not be able to play
257 it)
258
259 --external-downloader COMMAND
260 Use the specified external downloader. Currently supports
261 aria2c,aria2p,avconv ,axel,curl,ffmpeg,httpie,wget
262
263 --external-downloader-args ARGS
264 Give these arguments to the external downloader
265
266 Filesystem Options:
267 -a, --batch-file FILE
268 File containing URLs to download ('-' for stdin), one URL per
269 line. Lines starting with '#', ';' or ']' are considered as
270 comments and ignored.
271
272 --id Use only video ID in file name
273
274 -o, --output TEMPLATE
275 Output filename template, see the "OUTPUT TEMPLATE" for all the
276 info
277
278 --output-na-placeholder PLACEHOLDER
279 Placeholder value for unavailable meta fields in output filename
280 template (default is "NA")
281
282 --autonumber-start NUMBER
283 Specify the start value for %(autonumber)s (default is 1)
284
285 --restrict-filenames
286 Restrict filenames to only ASCII characters, and avoid "&" and
287 spaces in filenames
288
289 -w, --no-overwrites
290 Do not overwrite files
291
292 -c, --continue
293 Force resume of partially downloaded files. By default,
294 youtube-dl will resume downloads if possible.
295
296 --no-continue
297 Do not resume partially downloaded files (restart from begin‐
298 ning)
299
300 --no-part
301 Do not use .part files - write directly into output file
302
303 --mtime
304 Use the Last-modified header to set the file modification time
305 (default)
306
307 --no-mtime
308 Do not use the Last-modified header to set the file modification
309 time
310
311 --write-description
312 Write video description to a .description file
313
314 --write-info-json
315 Write video metadata to a .info.json file
316
317 --write-annotations
318 Write video annotations to a .annotations.xml file
319
320 --load-info-json FILE
321 JSON file containing the video information (created with the
322 "--write- info-json" option)
323
324 --cookies FILE
325 File to read cookies from and dump cookie jar in
326
327 --cache-dir DIR
328 Location in the filesystem where youtube-dl can store some down‐
329 loaded information permanently. By default
330 $XDG_CACHE_HOME/youtube-dl or ~/.cache/youtube-dl . At the mo‐
331 ment, only YouTube player files (for videos with obfuscated sig‐
332 natures) are cached, but that may change.
333
334 --no-cache-dir
335 Disable filesystem caching
336
337 --rm-cache-dir
338 Delete all filesystem cache files
339
340 Thumbnail Options:
341 --write-thumbnail
342 Write thumbnail image to disk
343
344 --write-all-thumbnails
345 Write all thumbnail image formats to disk
346
347 --list-thumbnails
348 Simulate and list all available thumbnail formats
349
350 Verbosity / Simulation Options:
351 -q, --quiet
352 Activate quiet mode
353
354 --no-warnings
355 Ignore warnings
356
357 -s, --simulate
358 Do not download the video and do not write anything to disk
359
360 --skip-download
361 Do not download the video
362
363 -g, --get-url
364 Simulate, quiet but print URL
365
366 -e, --get-title
367 Simulate, quiet but print title
368
369 --get-id
370 Simulate, quiet but print id
371
372 --get-thumbnail
373 Simulate, quiet but print thumbnail URL
374
375 --get-description
376 Simulate, quiet but print video description
377
378 --get-duration
379 Simulate, quiet but print video length
380
381 --get-filename
382 Simulate, quiet but print output filename
383
384 --get-format
385 Simulate, quiet but print output format
386
387 -j, --dump-json
388 Simulate, quiet but print JSON information. See the "OUTPUT
389 TEMPLATE" for a description of available keys.
390
391 -J, --dump-single-json
392 Simulate, quiet but print JSON information for each command-line
393 argument. If the URL refers to a playlist, dump the whole
394 playlist information in a single line.
395
396 --print-json
397 Be quiet and print the video information as JSON (video is still
398 being downloaded).
399
400 --newline
401 Output progress bar as new lines
402
403 --no-progress
404 Do not print progress bar
405
406 --console-title
407 Display progress in console titlebar
408
409 -v, --verbose
410 Print various debugging information
411
412 --dump-pages
413 Print downloaded pages encoded using base64 to debug problems
414 (very verbose)
415
416 --write-pages
417 Write downloaded intermediary pages to files in the current di‐
418 rectory to debug problems
419
420 --print-traffic
421 Display sent and read HTTP traffic
422
423 -C, --call-home
424 Contact the youtube-dl server for debugging
425
426 --no-call-home
427 Do NOT contact the youtube-dl server for debugging
428
429 Workarounds:
430 --encoding ENCODING
431 Force the specified encoding (experimental)
432
433 --no-check-certificate
434 Suppress HTTPS certificate validation
435
436 --prefer-insecure
437 Use an unencrypted connection to retrieve information about the
438 video. (Currently supported only for YouTube)
439
440 --user-agent UA
441 Specify a custom user agent
442
443 --referer URL
444 Specify a custom Referer: use if the video access is restricted
445 to one domain
446
447 --add-header FIELD:VALUE
448 Specify a custom HTTP header and its value, separated by a colon
449 ':'. You can use this option multiple times. NB Use --cookies
450 rather than adding a Cookie header if its contents may be sensi‐
451 tive; data from a Cookie header will be sent to all domains, not
452 just the one intended
453
454 --bidi-workaround
455 Work around terminals that lack bidirectional text support. Re‐
456 quires bidiv or fribidi executable in PATH
457
458 --sleep-interval SECONDS
459 Number of seconds to sleep before each download when used alone
460 or a lower bound of a range for randomized sleep before each
461 download (minimum possible number of seconds to sleep) when used
462 along with --max-sleep-interval.
463
464 --max-sleep-interval SECONDS
465 Upper bound of a range for randomized sleep before each download
466 (maximum possible number of seconds to sleep). Must only be
467 used along with --min- sleep-interval.
468
469 Video Format Options:
470 -f, --format FORMAT
471 Video format code, see the "FORMAT SELECTION" for all the info
472
473 --all-formats
474 Download all available video formats
475
476 --prefer-free-formats
477 Prefer free video formats unless a specific one is requested
478
479 -F, --list-formats
480 List all available formats of requested videos
481
482 --youtube-skip-dash-manifest
483 Do not download the DASH manifests and related data on YouTube
484 videos
485
486 --merge-output-format FORMAT
487 If a merge is required (e.g. bestvideo+bestaudio), output to
488 given container format. One of mkv, mp4, ogg, webm, flv. Ig‐
489 nored if no merge is required
490
491 Subtitle Options:
492 --write-sub
493 Write subtitle file
494
495 --write-auto-sub
496 Write automatically generated subtitle file (YouTube only)
497
498 --all-subs
499 Download all the available subtitles of the video
500
501 --list-subs
502 List all available subtitles for the video
503
504 --sub-format FORMAT
505 Subtitle format, accepts formats preference, for example: "srt"
506 or "ass/srt/best"
507
508 --sub-lang LANGS
509 Languages of the subtitles to download (optional) separated by
510 commas, use --list-subs for available language tags
511
512 Authentication Options:
513 -u, --username USERNAME
514 Login with this account ID
515
516 -p, --password PASSWORD
517 Account password. If this option is left out, youtube-dl will
518 ask interactively.
519
520 -2, --twofactor TWOFACTOR
521 Two-factor authentication code
522
523 -n, --netrc
524 Use .netrc authentication data
525
526 --video-password PASSWORD
527 Video password (vimeo, youku)
528
529 Adobe Pass Options:
530 --ap-mso MSO
531 Adobe Pass multiple-system operator (TV provider) identifier,
532 use --ap-list-mso for a list of available MSOs
533
534 --ap-username USERNAME
535 Multiple-system operator account login
536
537 --ap-password PASSWORD
538 Multiple-system operator account password. If this option is
539 left out, youtube-dl will ask interactively.
540
541 --ap-list-mso
542 List all supported multiple-system operators
543
544 Post-processing Options:
545 -x, --extract-audio
546 Convert video files to audio-only files (requires ffmpeg/avconv
547 and ffprobe/avprobe)
548
549 --audio-format FORMAT
550 Specify audio format: "best", "aac", "flac", "mp3", "m4a",
551 "opus", "vorbis", or "wav"; "best" by default; No effect without
552 -x
553
554 --audio-quality QUALITY
555 Specify ffmpeg/avconv audio quality, insert a value between 0
556 (better) and 9 (worse) for VBR or a specific bitrate like 128K
557 (default 5)
558
559 --recode-video FORMAT
560 Encode the video to another format if necessary (currently sup‐
561 ported: mp4|flv|ogg|webm|mkv|avi)
562
563 --postprocessor-args ARGS
564 Give these arguments to the postprocessor (if postprocessing is
565 required)
566
567 -k, --keep-video
568 Keep the video file on disk after the post-processing; the video
569 is erased by default
570
571 --no-post-overwrites
572 Do not overwrite post-processed files; the post-processed files
573 are overwritten by default
574
575 --embed-subs
576 Embed subtitles in the video (only for mp4, webm and mkv videos)
577
578 --embed-thumbnail
579 Embed thumbnail in the audio as cover art
580
581 --add-metadata
582 Write metadata to the video file
583
584 --metadata-from-title FORMAT
585 Parse additional metadata like song title / artist from the
586 video title. The format syntax is the same as --output. Regu‐
587 lar expression with named capture groups may also be used. The
588 parsed parameters replace existing values. Example: --metadata-
589 from-title "%(artist)s - %(title)s" matches a title like "Cold‐
590 play - Paradise". Example (regex): --metadata-from-title
591 "(?P.+?) - (?P
592 .+)"
593
594 --xattrs
595 Write metadata to the video file's xattrs (using dublin core and
596 xdg standards)
597
598 --fixup POLICY
599 Automatically correct known faults of the file. One of never
600 (do nothing), warn (only emit a warning), detect_or_warn (the
601 default; fix file if we can, warn otherwise)
602
603 --prefer-avconv
604 Prefer avconv over ffmpeg for running the postprocessors
605
606 --prefer-ffmpeg
607 Prefer ffmpeg over avconv for running the postprocessors (de‐
608 fault)
609
610 --ffmpeg-location PATH
611 Location of the ffmpeg/avconv binary; either the path to the bi‐
612 nary or its containing directory.
613
614 --exec CMD
615 Execute a command on the file after downloading and post-pro‐
616 cessing, similar to find's -exec syntax. Example: --exec 'adb
617 push {} /sdcard/Music/ && rm {}'
618
619 --convert-subs FORMAT
620 Convert the subtitles to other format (currently supported:
621 srt|ass|vtt|lrc)
622
624 You can configure youtube-dl by placing any supported command line op‐
625 tion to a configuration file. On Linux and macOS, the system wide con‐
626 figuration file is located at /etc/youtube-dl.conf and the user wide
627 configuration file at ~/.config/youtube-dl/config. On Windows, the us‐
628 er wide configuration file locations are %APPDATA%\youtube-dl\con‐
629 fig.txt or C:\Users\<user name>\youtube-dl.conf. Note that by default
630 configuration file may not exist so you may need to create it yourself.
631
632 For example, with the following configuration file youtube-dl will al‐
633 ways extract the audio, not copy the mtime, use a proxy and save all
634 videos under Movies directory in your home directory:
635
636 # Lines starting with # are comments
637
638 # Always extract audio
639 -x
640
641 # Do not copy the mtime
642 --no-mtime
643
644 # Use this proxy
645 --proxy 127.0.0.1:3128
646
647 # Save all videos under Movies directory in your home directory
648 -o ~/Movies/%(title)s.%(ext)s
649
650 Note that options in configuration file are just the same options aka
651 switches used in regular command line calls thus there must be no
652 whitespace after - or --, e.g. -o or --proxy but not - o or -- proxy.
653
654 You can use --ignore-config if you want to disable the configuration
655 file for a particular youtube-dl run.
656
657 You can also use --config-location if you want to use custom configura‐
658 tion file for a particular youtube-dl run.
659
660 Authentication with .netrc file
661 You may also want to configure automatic credentials storage for ex‐
662 tractors that support authentication (by providing login and password
663 with --username and --password) in order not to pass credentials as
664 command line arguments on every youtube-dl execution and prevent track‐
665 ing plain text passwords in the shell command history. You can achieve
666 this using a .netrc file (https://stackoverflow.com/tags/.netrc/info)
667 on a per extractor basis. For that you will need to create a .netrc
668 file in your $HOME and restrict permissions to read/write by only you:
669
670 touch $HOME/.netrc
671 chmod a-rwx,u+rw $HOME/.netrc
672
673 After that you can add credentials for an extractor in the following
674 format, where extractor is the name of the extractor in lowercase:
675
676 machine <extractor> login <login> password <password>
677
678 For example:
679
680 machine youtube login myaccount@gmail.com password my_youtube_password
681 machine twitch login my_twitch_account_name password my_twitch_password
682
683 To activate authentication with the .netrc file you should pass --netrc
684 to youtube-dl or place it in the configuration file.
685
686 On Windows you may also need to setup the %HOME% environment variable
687 manually. For example:
688
689 set HOME=%USERPROFILE%
690
692 The -o option allows users to indicate a template for the output file
693 names.
694
695 tl;dr: navigate me to examples.
696
697 The basic usage is not to set any template arguments when downloading a
698 single file, like in youtube-dl -o funny_video.flv
699 "https://some/video". However, it may contain special sequences that
700 will be replaced when downloading each video. The special sequences
701 may be formatted according to python string formatting operations
702 (https://docs.python.org/2/library/stdtypes.html#string-formatting).
703 For example, %(NAME)s or %(NAME)05d. To clarify, that is a percent
704 symbol followed by a name in parentheses, followed by formatting opera‐
705 tions. Allowed names along with sequence type are:
706
707 • id (string): Video identifier
708
709 • title (string): Video title
710
711 • url (string): Video URL
712
713 • ext (string): Video filename extension
714
715 • alt_title (string): A secondary title of the video
716
717 • display_id (string): An alternative identifier for the video
718
719 • uploader (string): Full name of the video uploader
720
721 • license (string): License name the video is licensed under
722
723 • creator (string): The creator of the video
724
725 • release_date (string): The date (YYYYMMDD) when the video was re‐
726 leased
727
728 • timestamp (numeric): UNIX timestamp of the moment the video became
729 available
730
731 • upload_date (string): Video upload date (YYYYMMDD)
732
733 • uploader_id (string): Nickname or id of the video uploader
734
735 • channel (string): Full name of the channel the video is uploaded on
736
737 • channel_id (string): Id of the channel
738
739 • location (string): Physical location where the video was filmed
740
741 • duration (numeric): Length of the video in seconds
742
743 • view_count (numeric): How many users have watched the video on the
744 platform
745
746 • like_count (numeric): Number of positive ratings of the video
747
748 • dislike_count (numeric): Number of negative ratings of the video
749
750 • repost_count (numeric): Number of reposts of the video
751
752 • average_rating (numeric): Average rating give by users, the scale
753 used depends on the webpage
754
755 • comment_count (numeric): Number of comments on the video
756
757 • age_limit (numeric): Age restriction for the video (years)
758
759 • is_live (boolean): Whether this video is a live stream or a fixed-
760 length video
761
762 • start_time (numeric): Time in seconds where the reproduction should
763 start, as specified in the URL
764
765 • end_time (numeric): Time in seconds where the reproduction should
766 end, as specified in the URL
767
768 • format (string): A human-readable description of the format
769
770 • format_id (string): Format code specified by --format
771
772 • format_note (string): Additional info about the format
773
774 • width (numeric): Width of the video
775
776 • height (numeric): Height of the video
777
778 • resolution (string): Textual description of width and height
779
780 • tbr (numeric): Average bitrate of audio and video in KBit/s
781
782 • abr (numeric): Average audio bitrate in KBit/s
783
784 • acodec (string): Name of the audio codec in use
785
786 • asr (numeric): Audio sampling rate in Hertz
787
788 • vbr (numeric): Average video bitrate in KBit/s
789
790 • fps (numeric): Frame rate
791
792 • vcodec (string): Name of the video codec in use
793
794 • container (string): Name of the container format
795
796 • filesize (numeric): The number of bytes, if known in advance
797
798 • filesize_approx (numeric): An estimate for the number of bytes
799
800 • protocol (string): The protocol that will be used for the actual
801 download
802
803 • extractor (string): Name of the extractor
804
805 • extractor_key (string): Key name of the extractor
806
807 • epoch (numeric): Unix epoch when creating the file
808
809 • autonumber (numeric): Number that will be increased with each down‐
810 load, starting at --autonumber-start
811
812 • playlist (string): Name or id of the playlist that contains the video
813
814 • playlist_index (numeric): Index of the video in the playlist padded
815 with leading zeros according to the total length of the playlist
816
817 • playlist_id (string): Playlist identifier
818
819 • playlist_title (string): Playlist title
820
821 • playlist_uploader (string): Full name of the playlist uploader
822
823 • playlist_uploader_id (string): Nickname or id of the playlist upload‐
824 er
825
826 Available for the video that belongs to some logical chapter or sec‐
827 tion:
828
829 • chapter (string): Name or title of the chapter the video belongs to
830
831 • chapter_number (numeric): Number of the chapter the video belongs to
832
833 • chapter_id (string): Id of the chapter the video belongs to
834
835 Available for the video that is an episode of some series or programme:
836
837 • series (string): Title of the series or programme the video episode
838 belongs to
839
840 • season (string): Title of the season the video episode belongs to
841
842 • season_number (numeric): Number of the season the video episode be‐
843 longs to
844
845 • season_id (string): Id of the season the video episode belongs to
846
847 • episode (string): Title of the video episode
848
849 • episode_number (numeric): Number of the video episode within a season
850
851 • episode_id (string): Id of the video episode
852
853 Available for the media that is a track or a part of a music album:
854
855 • track (string): Title of the track
856
857 • track_number (numeric): Number of the track within an album or a disc
858
859 • track_id (string): Id of the track
860
861 • artist (string): Artist(s) of the track
862
863 • genre (string): Genre(s) of the track
864
865 • album (string): Title of the album the track belongs to
866
867 • album_type (string): Type of the album
868
869 • album_artist (string): List of all artists appeared on the album
870
871 • disc_number (numeric): Number of the disc or other physical medium
872 the track belongs to
873
874 • release_year (numeric): Year (YYYY) when the album was released
875
876 Each aforementioned sequence when referenced in an output template will
877 be replaced by the actual value corresponding to the sequence name.
878 Note that some of the sequences are not guaranteed to be present since
879 they depend on the metadata obtained by a particular extractor. Such
880 sequences will be replaced with placeholder value provided with --out‐
881 put-na-placeholder (NA by default).
882
883 For example for -o %(title)s-%(id)s.%(ext)s and an mp4 video with title
884 youtube-dl test video and id BaW_jenozKcj, this will result in a
885 youtube-dl test video-BaW_jenozKcj.mp4 file created in the current di‐
886 rectory.
887
888 For numeric sequences you can use numeric related formatting, for exam‐
889 ple, %(view_count)05d will result in a string with view count padded
890 with zeros up to 5 characters, like in 00042.
891
892 Output templates can also contain arbitrary hierarchical path, e.g. -o
893 '%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s' which will result
894 in downloading each video in a directory corresponding to this path
895 template. Any missing directory will be automatically created for you.
896
897 To use percent literals in an output template use %%. To output to
898 stdout use -o -.
899
900 The current default template is %(title)s-%(id)s.%(ext)s.
901
902 In some cases, you don't want special characters such as 中, spaces, or
903 &, such as when transferring the downloaded filename to a Windows sys‐
904 tem or the filename through an 8bit-unsafe channel. In these cases,
905 add the --restrict-filenames flag to get a shorter title.
906
907 Output template and Windows batch files
908 If you are using an output template inside a Windows batch file then
909 you must escape plain percent characters (%) by doubling, so that -o
910 "%(title)s-%(id)s.%(ext)s" should become -o "%%(ti‐
911 tle)s-%%(id)s.%%(ext)s". However you should not touch %'s that are not
912 plain characters, e.g. environment variables for expansion should stay
913 intact: -o "C:\%HOMEPATH%\Desktop\%%(title)s.%%(ext)s".
914
915 Output template examples
916 Note that on Windows you may need to use double quotes instead of sin‐
917 gle.
918
919 $ youtube-dl --get-filename -o '%(title)s.%(ext)s' BaW_jenozKc
920 youtube-dl test video ''_ä↭𝕐.mp4 # All kinds of weird characters
921
922 $ youtube-dl --get-filename -o '%(title)s.%(ext)s' BaW_jenozKc --restrict-filenames
923 youtube-dl_test_video_.mp4 # A simple file name
924
925 # Download YouTube playlist videos in separate directory indexed by video order in a playlist
926 $ youtube-dl -o '%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s' https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re
927
928 # Download all playlists of YouTube channel/user keeping each playlist in separate directory:
929 $ youtube-dl -o '%(uploader)s/%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s' https://www.youtube.com/user/TheLinuxFoundation/playlists
930
931 # Download Udemy course keeping each chapter in separate directory under MyVideos directory in your home
932 $ youtube-dl -u user -p password -o '~/MyVideos/%(playlist)s/%(chapter_number)s - %(chapter)s/%(title)s.%(ext)s' https://www.udemy.com/java-tutorial/
933
934 # Download entire series season keeping each series and each season in separate directory under C:/MyVideos
935 $ youtube-dl -o "C:/MyVideos/%(series)s/%(season_number)s - %(season)s/%(episode_number)s - %(episode)s.%(ext)s" https://videomore.ru/kino_v_detalayah/5_sezon/367617
936
937 # Stream the video being downloaded to stdout
938 $ youtube-dl -o - BaW_jenozKc
939
941 By default youtube-dl tries to download the best available quality,
942 i.e. if you want the best quality you don't need to pass any special
943 options, youtube-dl will guess it for you by default.
944
945 But sometimes you may want to download in a different format, for exam‐
946 ple when you are on a slow or intermittent connection. The key mecha‐
947 nism for achieving this is so-called format selection based on which
948 you can explicitly specify desired format, select formats based on some
949 criterion or criteria, setup precedence and much more.
950
951 The general syntax for format selection is --format FORMAT or shorter
952 -f FORMAT where FORMAT is a selector expression, i.e. an expression
953 that describes format or formats you would like to download.
954
955 tl;dr: navigate me to examples.
956
957 The simplest case is requesting a specific format, for example with -f
958 22 you can download the format with format code equal to 22. You can
959 get the list of available format codes for particular video using
960 --list-formats or -F. Note that these format codes are extractor spe‐
961 cific.
962
963 You can also use a file extension (currently 3gp, aac, flv, m4a, mp3,
964 mp4, ogg, wav, webm are supported) to download the best quality format
965 of a particular file extension served as a single file, e.g. -f webm
966 will download the best quality format with the webm extension served as
967 a single file.
968
969 You can also use special names to select particular edge case formats:
970
971 • best: Select the best quality format represented by a single file
972 with video and audio.
973
974 • worst: Select the worst quality format represented by a single file
975 with video and audio.
976
977 • bestvideo: Select the best quality video-only format (e.g. DASH
978 video). May not be available.
979
980 • worstvideo: Select the worst quality video-only format. May not be
981 available.
982
983 • bestaudio: Select the best quality audio only-format. May not be
984 available.
985
986 • worstaudio: Select the worst quality audio only-format. May not be
987 available.
988
989 For example, to download the worst quality video-only format you can
990 use -f worstvideo.
991
992 If you want to download multiple videos and they don't have the same
993 formats available, you can specify the order of preference using slash‐
994 es. Note that slash is left-associative, i.e. formats on the left
995 hand side are preferred, for example -f 22/17/18 will download format
996 22 if it's available, otherwise it will download format 17 if it's
997 available, otherwise it will download format 18 if it's available, oth‐
998 erwise it will complain that no suitable formats are available for
999 download.
1000
1001 If you want to download several formats of the same video use a comma
1002 as a separator, e.g. -f 22,17,18 will download all these three for‐
1003 mats, of course if they are available. Or a more sophisticated example
1004 combined with the precedence feature: -f
1005 136/137/mp4/bestvideo,140/m4a/bestaudio.
1006
1007 You can also filter the video formats by putting a condition in brack‐
1008 ets, as in -f "best[height=720]" (or -f "[filesize>10M]").
1009
1010 The following numeric meta fields can be used with comparisons <, <=,
1011 >, >=, = (equals), != (not equals):
1012
1013 • filesize: The number of bytes, if known in advance
1014
1015 • width: Width of the video, if known
1016
1017 • height: Height of the video, if known
1018
1019 • tbr: Average bitrate of audio and video in KBit/s
1020
1021 • abr: Average audio bitrate in KBit/s
1022
1023 • vbr: Average video bitrate in KBit/s
1024
1025 • asr: Audio sampling rate in Hertz
1026
1027 • fps: Frame rate
1028
1029 Also filtering work for comparisons = (equals), ^= (starts with), $=
1030 (ends with), *= (contains) and following string meta fields:
1031
1032 • ext: File extension
1033
1034 • acodec: Name of the audio codec in use
1035
1036 • vcodec: Name of the video codec in use
1037
1038 • container: Name of the container format
1039
1040 • protocol: The protocol that will be used for the actual download,
1041 lower-case (http, https, rtsp, rtmp, rtmpe, mms, f4m, ism,
1042 http_dash_segments, m3u8, or m3u8_native)
1043
1044 • format_id: A short description of the format
1045
1046 • language: Language code
1047
1048 Any string comparison may be prefixed with negation ! in order to pro‐
1049 duce an opposite comparison, e.g. !*= (does not contain).
1050
1051 Note that none of the aforementioned meta fields are guaranteed to be
1052 present since this solely depends on the metadata obtained by particu‐
1053 lar extractor, i.e. the metadata offered by the video hoster.
1054
1055 Formats for which the value is not known are excluded unless you put a
1056 question mark (?) after the operator. You can combine format filters,
1057 so -f "[height <=? 720][tbr>500]" selects up to 720p videos (or videos
1058 where the height is not known) with a bitrate of at least 500 KBit/s.
1059
1060 You can merge the video and audio of two formats into a single file us‐
1061 ing -f <video-format>+<audio-format> (requires ffmpeg or avconv in‐
1062 stalled), for example -f bestvideo+bestaudio will download the best
1063 video-only format, the best audio-only format and mux them together
1064 with ffmpeg/avconv.
1065
1066 Format selectors can also be grouped using parentheses, for example if
1067 you want to download the best mp4 and webm formats with a height lower
1068 than 480 you can use -f '(mp4,webm)[height<480]'.
1069
1070 Since the end of April 2015 and version 2015.04.26, youtube-dl uses -f
1071 bestvideo+bestaudio/best as the default format selection (see #5447
1072 (https://github.com/ytdl-org/youtube-dl/issues/5447), #5456
1073 (https://github.com/ytdl-org/youtube-dl/issues/5456)). If ffmpeg or
1074 avconv are installed this results in downloading bestvideo and bestau‐
1075 dio separately and muxing them together into a single file giving the
1076 best overall quality available. Otherwise it falls back to best and
1077 results in downloading the best available quality served as a single
1078 file. best is also needed for videos that don't come from YouTube be‐
1079 cause they don't provide the audio and video in two different files.
1080 If you want to only download some DASH formats (for example if you are
1081 not interested in getting videos with a resolution higher than 1080p),
1082 you can add -f bestvideo[height<=?1080]+bestaudio/best to your configu‐
1083 ration file. Note that if you use youtube-dl to stream to stdout (and
1084 most likely to pipe it to your media player then), i.e. you explicitly
1085 specify output template as -o -, youtube-dl still uses -f best format
1086 selection in order to start content delivery immediately to your player
1087 and not to wait until bestvideo and bestaudio are downloaded and muxed.
1088
1089 If you want to preserve the old format selection behavior (prior to
1090 youtube-dl 2015.04.26), i.e. you want to download the best available
1091 quality media served as a single file, you should explicitly specify
1092 your choice with -f best. You may want to add it to the configuration
1093 file in order not to type it every time you run youtube-dl.
1094
1095 Format selection examples
1096 Note that on Windows you may need to use double quotes instead of sin‐
1097 gle.
1098
1099 # Download best mp4 format available or any other best if no mp4 available
1100 $ youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'
1101
1102 # Download best format available but no better than 480p
1103 $ youtube-dl -f 'bestvideo[height<=480]+bestaudio/best[height<=480]'
1104
1105 # Download best video only format but no bigger than 50 MB
1106 $ youtube-dl -f 'best[filesize<50M]'
1107
1108 # Download best format available via direct link over HTTP/HTTPS protocol
1109 $ youtube-dl -f '(bestvideo+bestaudio/best)[protocol^=http]'
1110
1111 # Download the best video format and the best audio format without merging them
1112 $ youtube-dl -f 'bestvideo,bestaudio' -o '%(title)s.f%(format_id)s.%(ext)s'
1113
1114 Note that in the last example, an output template is recommended as
1115 bestvideo and bestaudio may have the same file name.
1116
1118 Videos can be filtered by their upload date using the options --date,
1119 --datebefore or --dateafter. They accept dates in two formats:
1120
1121 • Absolute dates: Dates in the format YYYYMMDD.
1122
1123 • Relative dates: Dates in the format (now|to‐
1124 day)[+-][0-9](day|week|month|year)(s)?
1125
1126 Examples:
1127
1128 # Download only the videos uploaded in the last 6 months
1129 $ youtube-dl --dateafter now-6months
1130
1131 # Download only the videos uploaded on January 1, 1970
1132 $ youtube-dl --date 19700101
1133
1134 $ # Download only the videos uploaded in the 200x decade
1135 $ youtube-dl --dateafter 20000101 --datebefore 20091231
1136
1138 How do I update youtube-dl?
1139 If you've followed our manual installation instructions (https://ytdl-
1140 org.github.io/youtube-dl/download.html), you can simply run youtube-dl
1141 -U (or, on Linux, sudo youtube-dl -U).
1142
1143 If you have used pip, a simple sudo pip install -U youtube-dl is suffi‐
1144 cient to update.
1145
1146 If you have installed youtube-dl using a package manager like apt-get
1147 or yum, use the standard system update mechanism to update. Note that
1148 distribution packages are often outdated. As a rule of thumb, youtube-
1149 dl releases at least once a month, and often weekly or even daily.
1150 Simply go to https://yt-dl.org to find out the current version. Unfor‐
1151 tunately, there is nothing we youtube-dl developers can do if your dis‐
1152 tribution serves a really outdated version. You can (and should) com‐
1153 plain to your distribution in their bugtracker or support forum.
1154
1155 As a last resort, you can also uninstall the version installed by your
1156 package manager and follow our manual installation instructions. For
1157 that, remove the distribution's package, with a line like
1158
1159 sudo apt-get remove -y youtube-dl
1160
1161 Afterwards, simply follow our manual installation instructions
1162 (https://ytdl-org.github.io/youtube-dl/download.html):
1163
1164 sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl
1165 sudo chmod a+rx /usr/local/bin/youtube-dl
1166 hash -r
1167
1168 Again, from then on you'll be able to update with sudo youtube-dl -U.
1169
1170 youtube-dl is extremely slow to start on Windows
1171 Add a file exclusion for youtube-dl.exe in Windows Defender settings.
1172
1173 I'm getting an error Unable to extract OpenGraph title on YouTube playlists
1174 YouTube changed their playlist format in March 2014 and later on, so
1175 you'll need at least youtube-dl 2014.07.25 to download all YouTube
1176 videos.
1177
1178 If you have installed youtube-dl with a package manager, pip, setup.py
1179 or a tarball, please use that to update. Note that Ubuntu packages do
1180 not seem to get updated anymore. Since we are not affiliated with
1181 Ubuntu, there is little we can do. Feel free to report bugs
1182 (https://bugs.launchpad.net/ubuntu/+source/youtube-dl/+filebug) to the
1183 Ubuntu packaging people (mailto:ubuntu-motu@lists.ubuntu.com?sub‐
1184 ject=outdated%20version%20of%20youtube-dl) - all they have to do is up‐
1185 date the package to a somewhat recent version. See above for a way to
1186 update.
1187
1188 I'm getting an error when trying to use output template: error: using out‐
1189 put template conflicts with using title, video ID or auto number
1190 Make sure you are not using -o with any of these options -t, --title,
1191 --id, -A or --auto-number set in command line or in a configuration
1192 file. Remove the latter if any.
1193
1194 Do I always have to pass -citw?
1195 By default, youtube-dl intends to have the best options (incidentally,
1196 if you have a convincing case that these should be different, please
1197 file an issue where you explain that (https://yt-dl.org/bug)). There‐
1198 fore, it is unnecessary and sometimes harmful to copy long option
1199 strings from webpages. In particular, the only option out of -citw
1200 that is regularly useful is -i.
1201
1202 Can you please put the -b option back?
1203 Most people asking this question are not aware that youtube-dl now de‐
1204 faults to downloading the highest available quality as reported by
1205 YouTube, which will be 1080p or 720p in some cases, so you no longer
1206 need the -b option. For some specific videos, maybe YouTube does not
1207 report them to be available in a specific high quality format you're
1208 interested in. In that case, simply request it with the -f option and
1209 youtube-dl will try to download it.
1210
1211 I get HTTP error 402 when trying to download a video. What's this?
1212 Apparently YouTube requires you to pass a CAPTCHA test if you download
1213 too much. We're considering to provide a way to let you solve the
1214 CAPTCHA (https://github.com/ytdl-org/youtube-dl/issues/154), but at the
1215 moment, your best course of action is pointing a web browser to the
1216 youtube URL, solving the CAPTCHA, and restart youtube-dl.
1217
1218 Do I need any other programs?
1219 youtube-dl works fine on its own on most sites. However, if you want
1220 to convert video/audio, you'll need avconv (https://libav.org/) or ffm‐
1221 peg (https://www.ffmpeg.org/). On some sites - most notably YouTube -
1222 videos can be retrieved in a higher quality format without sound.
1223 youtube-dl will detect whether avconv/ffmpeg is present and automati‐
1224 cally pick the best option.
1225
1226 Videos or video formats streamed via RTMP protocol can only be down‐
1227 loaded when rtmpdump (https://rtmpdump.mplayerhq.hu/) is installed.
1228 Downloading MMS and RTSP videos requires either mplayer (https://mplay‐
1229 erhq.hu/) or mpv (https://mpv.io/) to be installed.
1230
1231 I have downloaded a video but how can I play it?
1232 Once the video is fully downloaded, use any video player, such as mpv
1233 (https://mpv.io/), vlc (https://www.videolan.org/) or mplayer
1234 (https://www.mplayerhq.hu/).
1235
1236 I extracted a video URL with -g, but it does not play on another machine /
1237 in my web browser.
1238 It depends a lot on the service. In many cases, requests for the video
1239 (to download/play it) must come from the same IP address and with the
1240 same cookies and/or HTTP headers. Use the --cookies option to write
1241 the required cookies into a file, and advise your downloader to read
1242 cookies from that file. Some sites also require a common user agent to
1243 be used, use --dump-user-agent to see the one in use by youtube-dl.
1244 You can also get necessary cookies and HTTP headers from JSON output
1245 obtained with --dump-json.
1246
1247 It may be beneficial to use IPv6; in some cases, the restrictions are
1248 only applied to IPv4. Some services (sometimes only for a subset of
1249 videos) do not restrict the video URL by IP address, cookie, or user-
1250 agent, but these are the exception rather than the rule.
1251
1252 Please bear in mind that some URL protocols are not supported by
1253 browsers out of the box, including RTMP. If you are using -g, your own
1254 downloader must support these as well.
1255
1256 If you want to play the video on a machine that is not running youtube-
1257 dl, you can relay the video content from the machine that runs youtube-
1258 dl. You can use -o - to let youtube-dl stream a video to stdout, or
1259 simply allow the player to download the files written by youtube-dl in
1260 turn.
1261
1262 ERROR: no fmt_url_map or conn information found in video info
1263 YouTube has switched to a new video info format in July 2011 which is
1264 not supported by old versions of youtube-dl. See above for how to up‐
1265 date youtube-dl.
1266
1267 ERROR: unable to download video
1268 YouTube requires an additional signature since September 2012 which is
1269 not supported by old versions of youtube-dl. See above for how to up‐
1270 date youtube-dl.
1271
1272 Video URL contains an ampersand and I'm getting some strange output [1]
1273 2839 or 'v' is not recognized as an internal or external command
1274 That's actually the output from your shell. Since ampersand is one of
1275 the special shell characters it's interpreted by the shell preventing
1276 you from passing the whole URL to youtube-dl. To disable your shell
1277 from interpreting the ampersands (or any other special characters) you
1278 have to either put the whole URL in quotes or escape them with a back‐
1279 slash (which approach will work depends on your shell).
1280
1281 For example if your URL is
1282 https://www.youtube.com/watch?t=4&v=BaW_jenozKc you should end up with
1283 following command:
1284
1285 youtube-dl 'https://www.youtube.com/watch?t=4&v=BaW_jenozKc'
1286
1287 or
1288
1289 youtube-dl https://www.youtube.com/watch?t=4\&v=BaW_jenozKc
1290
1291 For Windows you have to use the double quotes:
1292
1293 youtube-dl "https://www.youtube.com/watch?t=4&v=BaW_jenozKc"
1294
1295 ExtractorError: Could not find JS function u'OF'
1296 In February 2015, the new YouTube player contained a character sequence
1297 in a string that was misinterpreted by old versions of youtube-dl. See
1298 above for how to update youtube-dl.
1299
1300 HTTP Error 429: Too Many Requests or 402: Payment Required
1301 These two error codes indicate that the service is blocking your IP ad‐
1302 dress because of overuse. Usually this is a soft block meaning that
1303 you can gain access again after solving CAPTCHA. Just open a browser
1304 and solve a CAPTCHA the service suggests you and after that pass cook‐
1305 ies to youtube-dl. Note that if your machine has multiple external IPs
1306 then you should also pass exactly the same IP you've used for solving
1307 CAPTCHA with --source-address. Also you may need to pass a User-Agent
1308 HTTP header of your browser with --user-agent.
1309
1310 If this is not the case (no CAPTCHA suggested to solve by the service)
1311 then you can contact the service and ask them to unblock your IP ad‐
1312 dress, or - if you have acquired a whitelisted IP address already - use
1313 the --proxy or --source-address options to select another IP address.
1314
1315 SyntaxError: Non-ASCII character
1316 The error
1317
1318 File "youtube-dl", line 2
1319 SyntaxError: Non-ASCII character '\x93' ...
1320
1321 means you're using an outdated version of Python. Please update to
1322 Python 2.6 or 2.7.
1323
1324 What is this binary file? Where has the code gone?
1325 Since June 2012 (#342 (https://github.com/ytdl-org/youtube-dl/is‐
1326 sues/342)) youtube-dl is packed as an executable zipfile, simply unzip
1327 it (might need renaming to youtube-dl.zip first on some systems) or
1328 clone the git repository, as laid out above. If you modify the code,
1329 you can run it by executing the __main__.py file. To recompile the ex‐
1330 ecutable, run make youtube-dl.
1331
1332 The exe throws an error due to missing MSVCR100.dll
1333 To run the exe you need to install first the Microsoft Visual C++ 2010
1334 Service Pack 1 Redistributable Package (x86) (https://download.micro‐
1335 soft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcre‐
1336 dist_x86.exe).
1337
1338 On Windows, how should I set up ffmpeg and youtube-dl? Where should I put
1339 the exe files?
1340 If you put youtube-dl and ffmpeg in the same directory that you're run‐
1341 ning the command from, it will work, but that's rather cumbersome.
1342
1343 To make a different directory work - either for ffmpeg, or for youtube-
1344 dl, or for both - simply create the directory (say, C:\bin, or
1345 C:\Users\<User name>\bin), put all the executables directly in there,
1346 and then set your PATH environment variable (https://www.ja‐
1347 va.com/en/download/help/path.xml) to include that directory.
1348
1349 From then on, after restarting your shell, you will be able to access
1350 both youtube-dl and ffmpeg (and youtube-dl will be able to find ffmpeg)
1351 by simply typing youtube-dl or ffmpeg, no matter what directory you're
1352 in.
1353
1354 How do I put downloads into a specific folder?
1355 Use the -o to specify an output template, for example -o "/home/us‐
1356 er/videos/%(title)s-%(id)s.%(ext)s". If you want this for all of your
1357 downloads, put the option into your configuration file.
1358
1359 How do I download a video starting with a -?
1360 Either prepend https://www.youtube.com/watch?v= or separate the ID from
1361 the options with --:
1362
1363 youtube-dl -- -wNyEUrxzFU
1364 youtube-dl "https://www.youtube.com/watch?v=-wNyEUrxzFU"
1365
1366 How do I pass cookies to youtube-dl?
1367 Use the --cookies option, for example --cookies /path/to/cook‐
1368 ies/file.txt.
1369
1370 In order to extract cookies from browser use any conforming browser ex‐
1371 tension for exporting cookies. For example, Get cookies.txt LOCALLY
1372 (https://chrome.google.com/webstore/detail/get-cookiestxt-local‐
1373 ly/cclelndahbckbenkjhflpdbgdldlbecc) (for Chrome) or cookies.txt
1374 (https://addons.mozilla.org/en-US/firefox/addon/cookies-txt/) (for
1375 Firefox).
1376
1377 Note that the cookies file must be in Mozilla/Netscape format and the
1378 first line of the cookies file must be either # HTTP Cookie File or #
1379 Netscape HTTP Cookie File. Make sure you have correct newline format
1380 (https://en.wikipedia.org/wiki/Newline) in the cookies file and convert
1381 newlines if necessary to correspond with your OS, namely CRLF (\r\n)
1382 for Windows and LF (\n) for Unix and Unix-like systems (Linux, macOS,
1383 etc.). HTTP Error 400: Bad Request when using --cookies is a good sign
1384 of invalid newline format.
1385
1386 Passing cookies to youtube-dl is a good way to workaround login when a
1387 particular extractor does not implement it explicitly. Another use
1388 case is working around CAPTCHA (https://en.wikipedia.org/wiki/CAPTCHA)
1389 some websites require you to solve in particular cases in order to get
1390 access (e.g. YouTube, CloudFlare).
1391
1392 How do I stream directly to media player?
1393 You will first need to tell youtube-dl to stream media to stdout with
1394 -o -, and also tell your media player to read from stdin (it must be
1395 capable of this for streaming) and then pipe former to latter. For ex‐
1396 ample, streaming to vlc (https://www.videolan.org/) can be achieved
1397 with:
1398
1399 youtube-dl -o - "https://www.youtube.com/watch?v=BaW_jenozKcj" | vlc -
1400
1401 How do I download only new videos from a playlist?
1402 Use download-archive feature. With this feature you should initially
1403 download the complete playlist with --download-archive /path/to/down‐
1404 load/archive/file.txt that will record identifiers of all the videos in
1405 a special file. Each subsequent run with the same --download-archive
1406 will download only new videos and skip all videos that have been down‐
1407 loaded before. Note that only successful downloads are recorded in the
1408 file.
1409
1410 For example, at first,
1411
1412 youtube-dl --download-archive archive.txt "https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re"
1413
1414 will download the complete PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re playlist
1415 and create a file archive.txt. Each subsequent run will only download
1416 new videos if any:
1417
1418 youtube-dl --download-archive archive.txt "https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re"
1419
1420 Should I add --hls-prefer-native into my config?
1421 When youtube-dl detects an HLS video, it can download it either with
1422 the built-in downloader or ffmpeg. Since many HLS streams are slightly
1423 invalid and ffmpeg/youtube-dl each handle some invalid cases better
1424 than the other, there is an option to switch the downloader if needed.
1425
1426 When youtube-dl knows that one particular downloader works better for a
1427 given website, that downloader will be picked. Otherwise, youtube-dl
1428 will pick the best downloader for general compatibility, which at the
1429 moment happens to be ffmpeg. This choice may change in future versions
1430 of youtube-dl, with improvements of the built-in downloader and/or ffm‐
1431 peg.
1432
1433 In particular, the generic extractor (used when your website is not in
1434 the list of supported sites by youtube-dl (https://ytdl-
1435 org.github.io/youtube-dl/supportedsites.html) cannot mandate one spe‐
1436 cific downloader.
1437
1438 If you put either --hls-prefer-native or --hls-prefer-ffmpeg into your
1439 configuration, a different subset of videos will fail to download cor‐
1440 rectly. Instead, it is much better to file an issue (https://yt-
1441 dl.org/bug) or a pull request which details why the native or the ffm‐
1442 peg HLS downloader is a better choice for your use case.
1443
1444 Can you add support for this anime video site, or site which shows current
1445 movies for free?
1446 As a matter of policy (as well as legality), youtube-dl does not in‐
1447 clude support for services that specialize in infringing copyright. As
1448 a rule of thumb, if you cannot easily find a video that the service is
1449 quite obviously allowed to distribute (i.e. that has been uploaded by
1450 the creator, the creator's distributor, or is published under a free
1451 license), the service is probably unfit for inclusion to youtube-dl.
1452
1453 A note on the service that they don't host the infringing content, but
1454 just link to those who do, is evidence that the service should not be
1455 included into youtube-dl. The same goes for any DMCA note when the
1456 whole front page of the service is filled with videos they are not al‐
1457 lowed to distribute. A "fair use" note is equally unconvincing if the
1458 service shows copyright-protected videos in full without authorization.
1459
1460 Support requests for services that do purchase the rights to distribute
1461 their content are perfectly fine though. If in doubt, you can simply
1462 include a source that mentions the legitimate purchase of content.
1463
1464 How can I speed up work on my issue?
1465 (Also known as: Help, my important issue not being solved!) The
1466 youtube-dl core developer team is quite small. While we do our best to
1467 solve as many issues as possible, sometimes that can take quite a
1468 while. To speed up your issue, here's what you can do:
1469
1470 First of all, please do report the issue at our issue tracker
1471 (https://yt-dl.org/bugs). That allows us to coordinate all efforts by
1472 users and developers, and serves as a unified point. Unfortunately,
1473 the youtube-dl project has grown too large to use personal email as an
1474 effective communication channel.
1475
1476 Please read the bug reporting instructions below. A lot of bugs lack
1477 all the necessary information. If you can, offer proxy, VPN, or shell
1478 access to the youtube-dl developers. If you are able to, test the is‐
1479 sue from multiple computers in multiple countries to exclude local cen‐
1480 sorship or misconfiguration issues.
1481
1482 If nobody is interested in solving your issue, you are welcome to take
1483 matters into your own hands and submit a pull request (or coerce/pay
1484 somebody else to do so).
1485
1486 Feel free to bump the issue from time to time by writing a small com‐
1487 ment ("Issue is still present in youtube-dl version ...from France, but
1488 fixed from Belgium"), but please not more than once a month. Please do
1489 not declare your issue as important or urgent.
1490
1491 How can I detect whether a given URL is supported by youtube-dl?
1492 For one, have a look at the list of supported sites. Note that it can
1493 sometimes happen that the site changes its URL scheme (say, from
1494 https://example.com/video/1234567 to https://example.com/v/1234567 )
1495 and youtube-dl reports an URL of a service in that list as unsupported.
1496 In that case, simply report a bug.
1497
1498 It is not possible to detect whether a URL is supported or not. That's
1499 because youtube-dl contains a generic extractor which matches all URLs.
1500 You may be tempted to disable, exclude, or remove the generic extrac‐
1501 tor, but the generic extractor not only allows users to extract videos
1502 from lots of websites that embed a video from another service, but may
1503 also be used to extract video from a service that it's hosting itself.
1504 Therefore, we neither recommend nor support disabling, excluding, or
1505 removing the generic extractor.
1506
1507 If you want to find out whether a given URL is supported, simply call
1508 youtube-dl with it. If you get no videos back, chances are the URL is
1509 either not referring to a video or unsupported. You can find out which
1510 by examining the output (if you run youtube-dl on the console) or
1511 catching an UnsupportedError exception if you run it from a Python pro‐
1512 gram.
1513
1515 Before we had the issue template, despite our extensive bug reporting
1516 instructions, about 80% of the issue reports we got were useless, for
1517 instance because people used ancient versions hundreds of releases old,
1518 because of simple syntactic errors (not in youtube-dl but in general
1519 shell usage), because the problem was already reported multiple times
1520 before, because people did not actually read an error message, even if
1521 it said "please install ffmpeg", because people did not mention the URL
1522 they were trying to download and many more simple, easy-to-avoid prob‐
1523 lems, many of whom were totally unrelated to youtube-dl.
1524
1525 youtube-dl is an open-source project manned by too few volunteers, so
1526 we'd rather spend time fixing bugs where we are certain none of those
1527 simple problems apply, and where we can be reasonably confident to be
1528 able to reproduce the issue without asking the reporter repeatedly. As
1529 such, the output of youtube-dl -v YOUR_URL_HERE is really all that's
1530 required to file an issue. The issue template also guides you through
1531 some basic steps you can do, such as checking that your version of
1532 youtube-dl is current.
1533
1535 Most users do not need to build youtube-dl and can download the builds
1536 (https://ytdl-org.github.io/youtube-dl/download.html) or get them from
1537 their distribution.
1538
1539 To run youtube-dl as a developer, you don't need to build anything ei‐
1540 ther. Simply execute
1541
1542 python -m youtube_dl
1543
1544 To run the test, simply invoke your favorite test runner, or execute a
1545 test file directly; any of the following work:
1546
1547 python -m unittest discover
1548 python test/test_download.py
1549 nosetests
1550
1551 For Python versions 3.6 and later, you can use pynose
1552 (https://pypi.org/project/pynose/) to implement nosetests. The origi‐
1553 nal nose (https://pypi.org/project/nose/) has not been upgraded for
1554 3.10 and later.
1555
1556 See item 6 of new extractor tutorial for how to run extractor specific
1557 test cases.
1558
1559 If you want to create a build of youtube-dl yourself, you'll need
1560
1561 • python
1562
1563 • make (only GNU make is supported)
1564
1565 • pandoc
1566
1567 • zip
1568
1569 • nosetests
1570
1571 Adding support for a new site
1572 If you want to add support for a new site, first of all make sure this
1573 site is not dedicated to copyright infringement. youtube-dl does not
1574 support such sites thus pull requests adding support for them will be
1575 rejected.
1576
1577 After you have ensured this site is distributing its content legally,
1578 you can follow this quick list (assuming your service is called yourex‐
1579 tractor):
1580
1581 1. Fork this repository (https://github.com/ytdl-org/youtube-dl/fork)
1582
1583 2. Check out the source code with:
1584
1585 git clone git@github.com:YOUR_GITHUB_USERNAME/youtube-dl.git
1586
1587 3. Start a new git branch with
1588
1589 cd youtube-dl
1590 git checkout -b yourextractor
1591
1592 4. Start with this simple template and save it to youtube_dl/extrac‐
1593 tor/yourextractor.py:
1594
1595 # coding: utf-8
1596 from __future__ import unicode_literals
1597
1598 from .common import InfoExtractor
1599
1600
1601 class YourExtractorIE(InfoExtractor):
1602 _VALID_URL = r'https?://(?:www\.)?yourextractor\.com/watch/(?P<id>[0-9]+)'
1603 _TEST = {
1604 'url': 'https://yourextractor.com/watch/42',
1605 'md5': 'TODO: md5 sum of the first 10241 bytes of the video file (use --test)',
1606 'info_dict': {
1607 'id': '42',
1608 'ext': 'mp4',
1609 'title': 'Video title goes here',
1610 'thumbnail': r're:^https?://.*\.jpg$',
1611 # TODO more properties, either as:
1612 # * A value
1613 # * MD5 checksum; start the string with md5:
1614 # * A regular expression; start the string with re:
1615 # * Any Python type (for example int or float)
1616 }
1617 }
1618
1619 def _real_extract(self, url):
1620 video_id = self._match_id(url)
1621 webpage = self._download_webpage(url, video_id)
1622
1623 # TODO more code goes here, for example ...
1624 title = self._html_search_regex(r'<h1>(.+?)</h1>', webpage, 'title')
1625
1626 return {
1627 'id': video_id,
1628 'title': title,
1629 'description': self._og_search_description(webpage),
1630 'uploader': self._search_regex(r'<div[^>]+id="uploader"[^>]*>([^<]+)<', webpage, 'uploader', fatal=False),
1631 # TODO more properties (see youtube_dl/extractor/common.py)
1632 }
1633
1634 5. Add an import in youtube_dl/extractor/extractors.py
1635 (https://github.com/ytdl-org/youtube-dl/blob/master/youtube_dl/ex‐
1636 tractor/extractors.py).
1637
1638 6. Run python test/test_download.py TestDownload.test_YourExtractor.
1639 This should fail at first, but you can continually re-run it until
1640 you're done. If you decide to add more than one test (actually,
1641 test case) then rename _TEST to _TESTS and make it into a list of
1642 dictionaries. The tests will then be named TestDown‐
1643 load.test_YourExtractor, TestDownload.test_YourExtractor_1, Test‐
1644 Download.test_YourExtractor_2, etc. Note:
1645
1646 • the test names use the extractor class name without the trailing
1647 IE
1648
1649 • tests with only_matching key in test's dict are not counted.
1650
1651 7. Have a look at youtube_dl/extractor/common.py
1652 (https://github.com/ytdl-org/youtube-dl/blob/master/youtube_dl/ex‐
1653 tractor/common.py) for possible helper methods and a detailed de‐
1654 scription of what your extractor should and may return
1655 (https://github.com/ytdl-org/youtube-
1656 dl/blob/7f41a598b3fba1bcab2817de64a08941200aa3c8/youtube_dl/extrac‐
1657 tor/common.py#L94-L303). Add tests and code for as many as you
1658 want.
1659
1660 8. Make sure your code follows youtube-dl coding conventions and check
1661 the code with flake8 (https://flake8.pycqa.org/en/latest/in‐
1662 dex.html#quickstart):
1663
1664 $ flake8 youtube_dl/extractor/yourextractor.py
1665
1666 9. Make sure your code works under all Python
1667 (https://www.python.org/) versions claimed supported by youtube-dl,
1668 namely 2.6, 2.7, and 3.2+.
1669
1670 10. When the tests pass, add (https://git-scm.com/docs/git-add) the new
1671 files and commit (https://git-scm.com/docs/git-commit) them and
1672 push (https://git-scm.com/docs/git-push) the result, like this:
1673
1674 $ git add youtube_dl/extractor/extractors.py
1675 $ git add youtube_dl/extractor/yourextractor.py
1676 $ git commit -m '[yourextractor] Add new extractor'
1677 $ git push origin yourextractor
1678
1679 11. Finally, create a pull request (https://help.github.com/arti‐
1680 cles/creating-a-pull-request). We'll then review and merge it.
1681
1682 In any case, thank you very much for your contributions!
1683
1684 youtube-dl coding conventions
1685 This section introduces guidelines for writing idiomatic, robust and
1686 future-proof extractor code.
1687
1688 Extractors are very fragile by nature since they depend on the layout
1689 of the source data provided by 3rd party media hosters out of your con‐
1690 trol and this layout tends to change. As an extractor implementer your
1691 task is not only to write code that will extract media links and meta‐
1692 data correctly but also to minimize dependency on the source's layout
1693 and even to make the code foresee potential future changes and be ready
1694 for that. This is important because it will allow the extractor not to
1695 break on minor layout changes thus keeping old youtube-dl versions
1696 working. Even though this breakage issue is easily fixed by emitting a
1697 new version of youtube-dl with a fix incorporated, all the previous
1698 versions become broken in all repositories and distros' packages that
1699 may not be so prompt in fetching the update from us. Needless to say,
1700 some non rolling release distros may never receive an update at all.
1701
1702 Mandatory and optional metafields
1703 For extraction to work youtube-dl relies on metadata your extractor ex‐
1704 tracts and provides to youtube-dl expressed by an information dictio‐
1705 nary (https://github.com/ytdl-org/youtube-
1706 dl/blob/7f41a598b3fba1bcab2817de64a08941200aa3c8/youtube_dl/extrac‐
1707 tor/common.py#L94-L303) or simply info dict. Only the following meta
1708 fields in the info dict are considered mandatory for a successful ex‐
1709 traction process by youtube-dl:
1710
1711 • id (media identifier)
1712
1713 • title (media title)
1714
1715 • url (media download URL) or formats
1716
1717 In fact only the last option is technically mandatory (i.e. if you
1718 can't figure out the download location of the media the extraction does
1719 not make any sense). But by convention youtube-dl also treats id and
1720 title as mandatory. Thus the aforementioned metafields are the criti‐
1721 cal data that the extraction does not make any sense without and if any
1722 of them fail to be extracted then the extractor is considered complete‐
1723 ly broken.
1724
1725 Any field (https://github.com/ytdl-org/youtube-
1726 dl/blob/7f41a598b3fba1bcab2817de64a08941200aa3c8/youtube_dl/extrac‐
1727 tor/common.py#L188-L303) apart from the aforementioned ones are consid‐
1728 ered optional. That means that extraction should be tolerant to situa‐
1729 tions when sources for these fields can potentially be unavailable
1730 (even if they are always available at the moment) and future-proof in
1731 order not to break the extraction of general purpose mandatory fields.
1732
1733 Example
1734 Say you have some source dictionary meta that you've fetched as JSON
1735 with HTTP request and it has a key summary:
1736
1737 meta = self._download_json(url, video_id)
1738
1739 Assume at this point meta's layout is:
1740
1741 {
1742 ...
1743 "summary": "some fancy summary text",
1744 ...
1745 }
1746
1747 Assume you want to extract summary and put it into the resulting info
1748 dict as description. Since description is an optional meta field you
1749 should be ready that this key may be missing from the meta dict, so
1750 that you should extract it like:
1751
1752 description = meta.get('summary') # correct
1753
1754 and not like:
1755
1756 description = meta['summary'] # incorrect
1757
1758 The latter will break extraction process with KeyError if summary dis‐
1759 appears from meta at some later time but with the former approach ex‐
1760 traction will just go ahead with description set to None which is per‐
1761 fectly fine (remember None is equivalent to the absence of data).
1762
1763 Similarly, you should pass fatal=False when extracting optional data
1764 from a webpage with _search_regex, _html_search_regex or similar meth‐
1765 ods, for instance:
1766
1767 description = self._search_regex(
1768 r'<span[^>]+id="title"[^>]*>([^<]+)<',
1769 webpage, 'description', fatal=False)
1770
1771 With fatal set to False if _search_regex fails to extract description
1772 it will emit a warning and continue extraction.
1773
1774 You can also pass default=<some fallback value>, for example:
1775
1776 description = self._search_regex(
1777 r'<span[^>]+id="title"[^>]*>([^<]+)<',
1778 webpage, 'description', default=None)
1779
1780 On failure this code will silently continue the extraction with de‐
1781 scription set to None. That is useful for metafields that may or may
1782 not be present.
1783
1784 Provide fallbacks
1785 When extracting metadata try to do so from multiple sources. For exam‐
1786 ple if title is present in several places, try extracting from at least
1787 some of them. This makes it more future-proof in case some of the
1788 sources become unavailable.
1789
1790 Example
1791 Say meta from the previous example has a title and you are about to ex‐
1792 tract it. Since title is a mandatory meta field you should end up with
1793 something like:
1794
1795 title = meta['title']
1796
1797 If title disappears from meta in future due to some changes on the
1798 hoster's side the extraction would fail since title is mandatory.
1799 That's expected.
1800
1801 Assume that you have some another source you can extract title from,
1802 for example og:title HTML meta of a webpage. In this case you can pro‐
1803 vide a fallback scenario:
1804
1805 title = meta.get('title') or self._og_search_title(webpage)
1806
1807 This code will try to extract from meta first and if it fails it will
1808 try extracting og:title from a webpage.
1809
1810 Regular expressions
1811 Don't capture groups you don't use
1812 Capturing group must be an indication that it's used somewhere in the
1813 code. Any group that is not used must be non capturing.
1814
1815 Example
1816 Don't capture id attribute name here since you can't use it for any‐
1817 thing anyway.
1818
1819 Correct:
1820
1821 r'(?:id|ID)=(?P<id>\d+)'
1822
1823 Incorrect:
1824
1825 r'(id|ID)=(?P<id>\d+)'
1826
1827 Make regular expressions relaxed and flexible
1828 When using regular expressions try to write them fuzzy, relaxed and
1829 flexible, skipping insignificant parts that are more likely to change,
1830 allowing both single and double quotes for quoted values and so on.
1831
1832 Example
1833 Say you need to extract title from the following HTML code:
1834
1835 <span style="position: absolute; left: 910px; width: 90px; float: right; z-index: 9999;" class="title">some fancy title</span>
1836
1837 The code for that task should look similar to:
1838
1839 title = self._search_regex(
1840 r'<span[^>]+class="title"[^>]*>([^<]+)', webpage, 'title')
1841
1842 Or even better:
1843
1844 title = self._search_regex(
1845 r'<span[^>]+class=(["\'])title\1[^>]*>(?P<title>[^<]+)',
1846 webpage, 'title', group='title')
1847
1848 Note how you tolerate potential changes in the style attribute's value
1849 or switch from using double quotes to single for class attribute:
1850
1851 The code definitely should not look like:
1852
1853 title = self._search_regex(
1854 r'<span style="position: absolute; left: 910px; width: 90px; float: right; z-index: 9999;" class="title">(.*?)</span>',
1855 webpage, 'title', group='title')
1856
1857 Long lines policy
1858 There is a soft limit to keep lines of code under 80 characters long.
1859 This means it should be respected if possible and if it does not make
1860 readability and code maintenance worse.
1861
1862 For example, you should never split long string literals like URLs or
1863 some other often copied entities over multiple lines to fit this limit:
1864
1865 Correct:
1866
1867 'https://www.youtube.com/watch?v=FqZTN594JQw&list=PLMYEtVRpaqY00V9W81Cwmzp6N6vZqfUKD4'
1868
1869 Incorrect:
1870
1871 'https://www.youtube.com/watch?v=FqZTN594JQw&list='
1872 'PLMYEtVRpaqY00V9W81Cwmzp6N6vZqfUKD4'
1873
1874 Inline values
1875 Extracting variables is acceptable for reducing code duplication and
1876 improving readability of complex expressions. However, you should
1877 avoid extracting variables used only once and moving them to opposite
1878 parts of the extractor file, which makes reading the linear flow diffi‐
1879 cult.
1880
1881 Example
1882 Correct:
1883
1884 title = self._html_search_regex(r'<title>([^<]+)</title>', webpage, 'title')
1885
1886 Incorrect:
1887
1888 TITLE_RE = r'<title>([^<]+)</title>'
1889 # ...some lines of code...
1890 title = self._html_search_regex(TITLE_RE, webpage, 'title')
1891
1892 Collapse fallbacks
1893 Multiple fallback values can quickly become unwieldy. Collapse multi‐
1894 ple fallback values into a single expression via a list of patterns.
1895
1896 Example
1897 Good:
1898
1899 description = self._html_search_meta(
1900 ['og:description', 'description', 'twitter:description'],
1901 webpage, 'description', default=None)
1902
1903 Unwieldy:
1904
1905 description = (
1906 self._og_search_description(webpage, default=None)
1907 or self._html_search_meta('description', webpage, default=None)
1908 or self._html_search_meta('twitter:description', webpage, default=None))
1909
1910 Methods supporting list of patterns are: _search_regex,
1911 _html_search_regex, _og_search_property, _html_search_meta.
1912
1913 Trailing parentheses
1914 Always move trailing parentheses after the last argument.
1915
1916 Example
1917 Correct:
1918
1919 lambda x: x['ResultSet']['Result'][0]['VideoUrlSet']['VideoUrl'],
1920 list)
1921
1922 Incorrect:
1923
1924 lambda x: x['ResultSet']['Result'][0]['VideoUrlSet']['VideoUrl'],
1925 list,
1926 )
1927
1928 Use convenience conversion and parsing functions
1929 Wrap all extracted numeric data into safe functions from
1930 youtube_dl/utils.py (https://github.com/ytdl-org/youtube-dl/blob/mas‐
1931 ter/youtube_dl/utils.py): int_or_none, float_or_none. Use them for
1932 string to number conversions as well.
1933
1934 Use url_or_none for safe URL processing.
1935
1936 Use traverse_obj for safe metadata extraction from parsed JSON.
1937
1938 Use unified_strdate for uniform upload_date or any YYYYMMDD meta field
1939 extraction, unified_timestamp for uniform timestamp extraction,
1940 parse_filesize for filesize extraction, parse_count for count meta
1941 fields extraction, parse_resolution, parse_duration for duration ex‐
1942 traction, parse_age_limit for age_limit extraction.
1943
1944 Explore youtube_dl/utils.py (https://github.com/ytdl-org/youtube-
1945 dl/blob/master/youtube_dl/utils.py) for more useful convenience func‐
1946 tions.
1947
1948 More examples
1949 Safely extract optional description from parsed JSON
1950 When processing complex JSON, as often returned by site API requests or
1951 stashed in web pages for "hydration", you can use the traverse_obj()
1952 utility function to handle multiple fallback values and to ensure the
1953 expected type of metadata items. The function's docstring defines how
1954 the function works: also review usage in the codebase for more exam‐
1955 ples.
1956
1957 In this example, a text description, or None, is pulled from the .re‐
1958 sult.video[0].summary member of the parsed JSON response, if available.
1959
1960 description = traverse_obj(response, ('result', 'video', 0, 'summary', T(compat_str)))
1961
1962 T(...) is a shorthand for a set literal; if you hate people who still
1963 run Python 2.6, T(type_or_transformation) could be written as a set
1964 literal {type_or_transformation}.
1965
1966 Some extractors use the older and less capable try_get() function in
1967 the same way.
1968
1969 description = try_get(response, lambda x: x['result']['video'][0]['summary'], compat_str)
1970
1971 Safely extract more optional metadata
1972 In this example, various optional metadata values are extracted from
1973 the .result.video[0] member of the parsed JSON response, which is ex‐
1974 pected to be a JS object, parsed into a dict, with no crash if that
1975 isn't so, or if any of the target values are missing or invalid.
1976
1977 video = traverse_obj(response, ('result', 'video', 0, T(dict))) or {}
1978 # formerly:
1979 # video = try_get(response, lambda x: x['result']['video'][0], dict) or {}
1980 description = video.get('summary')
1981 duration = float_or_none(video.get('durationMs'), scale=1000)
1982 view_count = int_or_none(video.get('views'))
1983
1984 Safely extract nested lists
1985 Suppose you've extracted JSON like this into a Python data structure
1986 named media_json using, say, the _download_json() or _parse_json()
1987 methods of InfoExtractor:
1988
1989 {
1990 "title": "Example video",
1991 "comment": "try extracting this",
1992 "media": [{
1993 "type": "bad",
1994 "size": 320,
1995 "url": "https://some.cdn.site/bad.mp4"
1996 }, {
1997 "type": "streaming",
1998 "url": "https://some.cdn.site/hls.m3u8"
1999 }, {
2000 "type": "super",
2001 "size": 1280,
2002 "url": "https://some.cdn.site/good.webm"
2003 }],
2004 "moreStuff": "more values",
2005 ...
2006 }
2007
2008 Then extractor code like this can collect the various fields of the
2009 JSON:
2010
2011 ...
2012 from ..utils import (
2013 determine_ext,
2014 int_or_none,
2015 T,
2016 traverse_obj,
2017 txt_or_none,
2018 url_or_none,
2019 )
2020 ...
2021 ...
2022 info_dict = {}
2023 # extract title and description if valid and not empty
2024 info_dict.update(traverse_obj(media_json, {
2025 'title': ('title', T(txt_or_none)),
2026 'description': ('comment', T(txt_or_none)),
2027 }))
2028
2029 # extract any recognisable media formats
2030 fmts = []
2031 # traverse into "media" list, extract `dict`s with desired keys
2032 for fmt in traverse_obj(media_json, ('media', Ellipsis, {
2033 'format_id': ('type', T(txt_or_none)),
2034 'url': ('url', T(url_or_none)),
2035 'width': ('size', T(int_or_none)), })):
2036 # bad `fmt` values were `None` and removed
2037 if 'url' not in fmt:
2038 continue
2039 fmt_url = fmt['url'] # known to be valid URL
2040 ext = determine_ext(fmt_url)
2041 if ext == 'm3u8':
2042 fmts.extend(self._extract_m3u8_formats(fmt_url, video_id, 'mp4', fatal=False))
2043 else:
2044 fmt['ext'] = ext
2045 fmts.append(fmt)
2046
2047 # sort, raise if no formats
2048 self._sort_formats(fmts)
2049
2050 info_dict['formats'] = fmts
2051 ...
2052
2053 The extractor raises an exception rather than random crashes if the
2054 JSON structure changes so that no formats are found.
2055
2057 youtube-dl makes the best effort to be a good command-line program, and
2058 thus should be callable from any programming language. If you en‐
2059 counter any problems parsing its output, feel free to create a report
2060 (https://github.com/ytdl-org/youtube-dl/issues/new).
2061
2062 From a Python program, you can embed youtube-dl in a more powerful
2063 fashion, like this:
2064
2065 from __future__ import unicode_literals
2066 import youtube_dl
2067
2068 ydl_opts = {}
2069 with youtube_dl.YoutubeDL(ydl_opts) as ydl:
2070 ydl.download(['https://www.youtube.com/watch?v=BaW_jenozKc'])
2071
2072 Most likely, you'll want to use various options. For a list of options
2073 available, have a look at youtube_dl/YoutubeDL.py
2074 (https://github.com/ytdl-org/youtube-
2075 dl/blob/3e4cedf9e8cd3157df2457df7274d0c842421945/youtube_dl/YoutubeDL.py#L137-L312).
2076 For a start, if you want to intercept youtube-dl's output, set a logger
2077 object.
2078
2079 Here's a more complete example of a program that outputs only errors
2080 (and a short message after the download is finished), and down‐
2081 loads/converts the video to an mp3 file:
2082
2083 from __future__ import unicode_literals
2084 import youtube_dl
2085
2086
2087 class MyLogger(object):
2088 def debug(self, msg):
2089 pass
2090
2091 def warning(self, msg):
2092 pass
2093
2094 def error(self, msg):
2095 print(msg)
2096
2097
2098 def my_hook(d):
2099 if d['status'] == 'finished':
2100 print('Done downloading, now converting ...')
2101
2102
2103 ydl_opts = {
2104 'format': 'bestaudio/best',
2105 'postprocessors': [{
2106 'key': 'FFmpegExtractAudio',
2107 'preferredcodec': 'mp3',
2108 'preferredquality': '192',
2109 }],
2110 'logger': MyLogger(),
2111 'progress_hooks': [my_hook],
2112 }
2113 with youtube_dl.YoutubeDL(ydl_opts) as ydl:
2114 ydl.download(['https://www.youtube.com/watch?v=BaW_jenozKc'])
2115
2117 Bugs and suggestions should be reported in the issue tracker:
2118 <https://github.com/ytdl-org/youtube-dl/issues> (<https://yt-
2119 dl.org/bug> is an alias for this). Unless you were prompted to or
2120 there is another pertinent reason (e.g. GitHub fails to accept the bug
2121 report), please do not send bug reports via personal email. For dis‐
2122 cussions, join us in the IRC channel #youtube-dl (irc://chat.freen‐
2123 ode.net/#youtube-dl) on freenode (webchat (https://webchat.freen‐
2124 ode.net/?randomnick=1&channels=youtube-dl)).
2125
2126 Opening a bug report or suggestion
2127 Be sure to follow instructions provided below and in the issue tracker.
2128 Complete the appropriate issue template fully. Consider whether your
2129 problem is covered by an existing issue: if so, follow the discussion
2130 there. Avoid commenting on existing duplicate issues as such comments
2131 do not add to the discussion of the issue and are liable to be treated
2132 as spam.
2133
2134 Please include the full output of youtube-dl when run with -v, i.e.
2135 add -v flag to your command line, copy the whole output and post it in
2136 the issue body wrapped in ``` for better formatting. It should look
2137 similar to this:
2138
2139 $ youtube-dl -v <your command line>
2140 [debug] System config: []
2141 [debug] User config: []
2142 [debug] Command-line args: [u'-v', u'https://www.youtube.com/watch?v=BaW_jenozKcj']
2143 [debug] Encodings: locale cp1251, fs mbcs, out cp866, pref cp1251
2144 [debug] youtube-dl version 2015.12.06
2145 [debug] Git HEAD: 135392e
2146 [debug] Python version 2.6.6 - Windows-2003Server-5.2.3790-SP2
2147 [debug] exe versions: ffmpeg N-75573-g1d0487f, ffprobe N-75573-g1d0487f, rtmpdump 2.4
2148 [debug] Proxy map: {}
2149 ...
2150
2151 Do not post screenshots of verbose logs; only plain text is acceptable.
2152
2153 The output (including the first lines) contains important debugging in‐
2154 formation. Issues without the full output are often not reproducible
2155 and therefore do not get solved in short order, if ever.
2156
2157 Finally please review your issue to avoid various common mistakes (you
2158 can and should use this as a checklist) listed below.
2159
2160 Is the description of the issue itself sufficient?
2161 We often get issue reports that are hard to understand. To avoid sub‐
2162 sequent clarifications, and to assist participants who are not native
2163 English speakers, please elaborate on what feature you are requesting,
2164 or what bug you want to be fixed.
2165
2166 Make sure that it's obvious
2167
2168 • What the problem is
2169
2170 • How it could be fixed
2171
2172 • How your proposed solution would look
2173
2174 If your report is shorter than two lines, it is almost certainly miss‐
2175 ing some of these, which makes it hard for us to respond to it. We're
2176 often too polite to close the issue outright, but the missing info
2177 makes misinterpretation likely. As a committer myself, I often get
2178 frustrated by these issues, since the only possible way for me to move
2179 forward on them is to ask for clarification over and over.
2180
2181 For bug reports, this means that your report should contain the com‐
2182 plete output of youtube-dl when called with the -v flag. The error
2183 message you get for (most) bugs even says so, but you would not believe
2184 how many of our bug reports do not contain this information.
2185
2186 If your server has multiple IPs or you suspect censorship, adding
2187 --call-home may be a good idea to get more diagnostics. If the error
2188 is ERROR: Unable to extract ... and you cannot reproduce it from multi‐
2189 ple countries, add --dump-pages (warning: this will yield a rather
2190 large output, redirect it to the file log.txt by adding >log.txt 2>&1
2191 to your command-line) or upload the .dump files you get when you add
2192 --write-pages somewhere (https://gist.github.com/).
2193
2194 Site support requests must contain an example URL. An example URL is a
2195 URL you might want to download, like
2196 https://www.youtube.com/watch?v=BaW_jenozKc. There should be an obvi‐
2197 ous video present. Except under very special circumstances, the main
2198 page of a video service (e.g. https://www.youtube.com/) is not an ex‐
2199 ample URL.
2200
2201 Is the issue already documented?
2202 Make sure that someone has not already opened the issue you're trying
2203 to open. Search at the top of the window or browse the GitHub Issues
2204 (https://github.com/ytdl-org/youtube-dl/search?type=Issues) of this
2205 repository. Initially, at least, use the search term -label:duplicate
2206 to focus on active issues. If there is an issue, feel free to write
2207 something along the lines of "This affects me as well, with version
2208 2015.01.01. Here is some more information on the issue: ...". While
2209 some issues may be old, a new post into them often spurs rapid activi‐
2210 ty.
2211
2212 Are you using the latest version?
2213 Before reporting any issue, type youtube-dl -U. This should report
2214 that you're up-to-date. About 20% of the reports we receive are al‐
2215 ready fixed, but people are using outdated versions. This goes for
2216 feature requests as well.
2217
2218 Why are existing options not enough?
2219 Before requesting a new feature, please have a quick peek at the list
2220 of supported options (https://github.com/ytdl-org/youtube-dl/blob/mas‐
2221 ter/README.md#options). Many feature requests are for features that
2222 actually exist already! Please, absolutely do show off your work in
2223 the issue report and detail how the existing similar options do not
2224 solve your problem.
2225
2226 Is there enough context in your bug report?
2227 People want to solve problems, and often think they do us a favor by
2228 breaking down their larger problems (e.g. wanting to skip already
2229 downloaded files) to a specific request (e.g. requesting us to look
2230 whether the file exists before downloading the info page). However,
2231 what often happens is that they break down the problem into two steps:
2232 One simple, and one impossible (or extremely complicated one).
2233
2234 We are then presented with a very complicated request when the original
2235 problem could be solved far easier, e.g. by recording the downloaded
2236 video IDs in a separate file. To avoid this, you must include the
2237 greater context where it is non-obvious. In particular, every feature
2238 request that does not consist of adding support for a new site should
2239 contain a use case scenario that explains in what situation the missing
2240 feature would be useful.
2241
2242 Does the issue involve one problem, and one problem only?
2243 Some of our users seem to think there is a limit of issues they can or
2244 should open. There is no limit of issues they can or should open.
2245 While it may seem appealing to be able to dump all your issues into one
2246 ticket, that means that someone who solves one of your issues cannot
2247 mark the issue as closed. Typically, reporting a bunch of issues leads
2248 to the ticket lingering since nobody wants to attack that behemoth, un‐
2249 til someone mercifully splits the issue into multiple ones.
2250
2251 In particular, every site support request issue should only pertain to
2252 services at one site (generally under a common domain, but always using
2253 the same backend technology). Do not request support for vimeo user
2254 videos, White house podcasts, and Google Plus pages in the same issue.
2255 Also, make sure that you don't post bug reports alongside feature re‐
2256 quests. As a rule of thumb, a feature request does not include outputs
2257 of youtube-dl that are not immediately related to the feature at hand.
2258 Do not post reports of a network error alongside the request for a new
2259 video service.
2260
2261 Is anyone going to need the feature?
2262 Only post features that you (or an incapacitated friend you can person‐
2263 ally talk to) require. Do not post features because they seem like a
2264 good idea. If they are really useful, they will be requested by some‐
2265 one who requires them.
2266
2267 Is your question about youtube-dl?
2268 It may sound strange, but some bug reports we receive are completely
2269 unrelated to youtube-dl and relate to a different, or even the re‐
2270 porter's own, application. Please make sure that you are actually us‐
2271 ing youtube-dl. If you are using a UI for youtube-dl, report the bug
2272 to the maintainer of the actual application providing the UI. On the
2273 other hand, if your UI for youtube-dl fails in some way you believe is
2274 related to youtube-dl, by all means, go ahead and report the bug.
2275
2277 youtube-dl is released into the public domain by the copyright holders.
2278
2279 This README file was originally written by Daniel Bolton
2280 (https://github.com/dbbolton) and is likewise released into the public
2281 domain.
2282
2283
2284
2285 YOUTUBE-DL(1)