kandi background
Explore Kits

youtube-dl | line program to download videos | Machine Learning library

 by   ytdl-org Python Version: 2021.12.17 License: Unlicense

 by   ytdl-org Python Version: 2021.12.17 License: Unlicense

Download this library from

kandi X-RAY | youtube-dl Summary

youtube-dl is a Python library typically used in Telecommunications, Media, Media, Entertainment, Artificial Intelligence, Machine Learning applications. youtube-dl has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. You can install using 'pip install youtube-dl' or download it from GitHub, PyPI.
youtube-dl is a command-line program to download videos from YouTube.com and a few more sites. It requires the Python interpreter, version 2.6, 2.7, or 3.2+, and it is not platform specific. It should work on your Unix box, on Windows or on macOS. It is released to the public domain, which means you can modify it, redistribute it or use it however you like.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • youtube-dl has a highly active ecosystem.
  • It has 108335 star(s) with 7581 fork(s). There are 2215 watchers for this library.
  • There were 1 major release(s) in the last 12 months.
  • There are 4050 open issues and 20793 have been closed. On average issues are closed in 23 days. There are 905 open pull requests and 0 closed requests.
  • It has a negative sentiment in the developer community.
  • The latest version of youtube-dl is 2021.12.17
youtube-dl Support
Best in #Machine Learning
Average in #Machine Learning
youtube-dl Support
Best in #Machine Learning
Average in #Machine Learning

quality kandi Quality

  • youtube-dl has 0 bugs and 0 code smells.
youtube-dl Quality
Best in #Machine Learning
Average in #Machine Learning
youtube-dl Quality
Best in #Machine Learning
Average in #Machine Learning

securitySecurity

  • youtube-dl has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • youtube-dl code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
youtube-dl Security
Best in #Machine Learning
Average in #Machine Learning
youtube-dl Security
Best in #Machine Learning
Average in #Machine Learning

license License

  • youtube-dl is licensed under the Unlicense License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
youtube-dl License
Best in #Machine Learning
Average in #Machine Learning
youtube-dl License
Best in #Machine Learning
Average in #Machine Learning

buildReuse

  • youtube-dl releases are available to install and integrate.
  • Deployable package is available in PyPI.
  • Build file is available. You can build the component from source.
  • Installation instructions, examples and code snippets are available.
  • It has 129798 lines of code, 3522 functions and 888 files.
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
youtube-dl Reuse
Best in #Machine Learning
Average in #Machine Learning
youtube-dl Reuse
Best in #Machine Learning
Average in #Machine Learning
Top functions reviewed by kandi - BETA

kandi has reviewed youtube-dl and discovered the below as its top functions. This is intended to give you an instant insight into youtube-dl implemented functionality, and help decide if they suit your requirements.

  • Return random user agent .
  • Parse options .
  • Main function .
  • Parse an expression .
  • Extract video data from url .
  • Process info_dict .
  • Parse MPD format .
  • Extract mvpd auth data .
  • Login .
  • Get information about a video .

youtube-dl Key Features

Command-line program to download videos from YouTube.com and other video sites

INSTALLATION

copy iconCopydownload iconDownload
sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

DESCRIPTION

copy iconCopydownload iconDownload
youtube-dl [OPTIONS] URL [URL...]

OPTIONS

copy iconCopydownload iconDownload
-h, --help                           Print this help text and exit
--version                            Print program version and exit
-U, --update                         Update this program to latest version.
                                     Make sure that you have sufficient
                                     permissions (run with sudo if needed)
-i, --ignore-errors                  Continue on download errors, for
                                     example to skip unavailable videos in a
                                     playlist
--abort-on-error                     Abort downloading of further videos (in
                                     the playlist or the command line) if an
                                     error occurs
--dump-user-agent                    Display the current browser
                                     identification
--list-extractors                    List all supported extractors
--extractor-descriptions             Output descriptions of all supported
                                     extractors
--force-generic-extractor            Force extraction to use the generic
                                     extractor
--default-search PREFIX              Use this prefix for unqualified URLs.
                                     For example "gvsearch2:" downloads two
                                     videos from google videos for youtube-
                                     dl "large apple". Use the value "auto"
                                     to let youtube-dl guess ("auto_warning"
                                     to emit a warning when guessing).
                                     "error" just throws an error. The
                                     default value "fixup_error" repairs
                                     broken URLs, but emits an error if this
                                     is not possible instead of searching.
--ignore-config                      Do not read configuration files. When
                                     given in the global configuration file
                                     /etc/youtube-dl.conf: Do not read the
                                     user configuration in
                                     ~/.config/youtube-dl/config
                                     (%APPDATA%/youtube-dl/config.txt on
                                     Windows)
--config-location PATH               Location of the configuration file;
                                     either the path to the config or its
                                     containing directory.
--flat-playlist                      Do not extract the videos of a
                                     playlist, only list them.
--mark-watched                       Mark videos watched (YouTube only)
--no-mark-watched                    Do not mark videos watched (YouTube
                                     only)
--no-color                           Do not emit color codes in output

Network Options:

copy iconCopydownload iconDownload
--proxy URL                          Use the specified HTTP/HTTPS/SOCKS
                                     proxy. To enable SOCKS proxy, specify a
                                     proper scheme. For example
                                     socks5://127.0.0.1:1080/. Pass in an
                                     empty string (--proxy "") for direct
                                     connection
--socket-timeout SECONDS             Time to wait before giving up, in
                                     seconds
--source-address IP                  Client-side IP address to bind to
-4, --force-ipv4                     Make all connections via IPv4
-6, --force-ipv6                     Make all connections via IPv6

Geo Restriction:

copy iconCopydownload iconDownload
--geo-verification-proxy URL         Use this proxy to verify the IP address
                                     for some geo-restricted sites. The
                                     default proxy specified by --proxy (or
                                     none, if the option is not present) is
                                     used for the actual downloading.
--geo-bypass                         Bypass geographic restriction via
                                     faking X-Forwarded-For HTTP header
--no-geo-bypass                      Do not bypass geographic restriction
                                     via faking X-Forwarded-For HTTP header
--geo-bypass-country CODE            Force bypass geographic restriction
                                     with explicitly provided two-letter ISO
                                     3166-2 country code
--geo-bypass-ip-block IP_BLOCK       Force bypass geographic restriction
                                     with explicitly provided IP block in
                                     CIDR notation

Video Selection:

copy iconCopydownload iconDownload
--playlist-start NUMBER              Playlist video to start at (default is
                                     1)
--playlist-end NUMBER                Playlist video to end at (default is
                                     last)
--playlist-items ITEM_SPEC           Playlist video items to download.
                                     Specify indices of the videos in the
                                     playlist separated by commas like: "--
                                     playlist-items 1,2,5,8" if you want to
                                     download videos indexed 1, 2, 5, 8 in
                                     the playlist. You can specify range: "
                                     --playlist-items 1-3,7,10-13", it will
                                     download the videos at index 1, 2, 3,
                                     7, 10, 11, 12 and 13.
--match-title REGEX                  Download only matching titles (regex or
                                     caseless sub-string)
--reject-title REGEX                 Skip download for matching titles
                                     (regex or caseless sub-string)
--max-downloads NUMBER               Abort after downloading NUMBER files
--min-filesize SIZE                  Do not download any videos smaller than
                                     SIZE (e.g. 50k or 44.6m)
--max-filesize SIZE                  Do not download any videos larger than
                                     SIZE (e.g. 50k or 44.6m)
--date DATE                          Download only videos uploaded in this
                                     date
--datebefore DATE                    Download only videos uploaded on or
                                     before this date (i.e. inclusive)
--dateafter DATE                     Download only videos uploaded on or
                                     after this date (i.e. inclusive)
--min-views COUNT                    Do not download any videos with less
                                     than COUNT views
--max-views COUNT                    Do not download any videos with more
                                     than COUNT views
--match-filter FILTER                Generic video filter. Specify any key
                                     (see the "OUTPUT TEMPLATE" for a list
                                     of available keys) to match if the key
                                     is present, !key to check if the key is
                                     not present, key > NUMBER (like
                                     "comment_count > 12", also works with
                                     >=, <, <=, !=, =) to compare against a
                                     number, key = 'LITERAL' (like "uploader
                                     = 'Mike Smith'", also works with !=) to
                                     match against a string literal and & to
                                     require multiple matches. Values which
                                     are not known are excluded unless you
                                     put a question mark (?) after the
                                     operator. For example, to only match
                                     videos that have been liked more than
                                     100 times and disliked less than 50
                                     times (or the dislike functionality is
                                     not available at the given service),
                                     but who also have a description, use
                                     --match-filter "like_count > 100 &
                                     dislike_count <? 50 & description" .
--no-playlist                        Download only the video, if the URL
                                     refers to a video and a playlist.
--yes-playlist                       Download the playlist, if the URL
                                     refers to a video and a playlist.
--age-limit YEARS                    Download only videos suitable for the
                                     given age
--download-archive FILE              Download only videos not listed in the
                                     archive file. Record the IDs of all
                                     downloaded videos in it.
--include-ads                        Download advertisements as well
                                     (experimental)

Download Options:

copy iconCopydownload iconDownload
-r, --limit-rate RATE                Maximum download rate in bytes per
                                     second (e.g. 50K or 4.2M)
-R, --retries RETRIES                Number of retries (default is 10), or
                                     "infinite".
--fragment-retries RETRIES           Number of retries for a fragment
                                     (default is 10), or "infinite" (DASH,
                                     hlsnative and ISM)
--skip-unavailable-fragments         Skip unavailable fragments (DASH,
                                     hlsnative and ISM)
--abort-on-unavailable-fragment      Abort downloading when some fragment is
                                     not available
--keep-fragments                     Keep downloaded fragments on disk after
                                     downloading is finished; fragments are
                                     erased by default
--buffer-size SIZE                   Size of download buffer (e.g. 1024 or
                                     16K) (default is 1024)
--no-resize-buffer                   Do not automatically adjust the buffer
                                     size. By default, the buffer size is
                                     automatically resized from an initial
                                     value of SIZE.
--http-chunk-size SIZE               Size of a chunk for chunk-based HTTP
                                     downloading (e.g. 10485760 or 10M)
                                     (default is disabled). May be useful
                                     for bypassing bandwidth throttling
                                     imposed by a webserver (experimental)
--playlist-reverse                   Download playlist videos in reverse
                                     order
--playlist-random                    Download playlist videos in random
                                     order
--xattr-set-filesize                 Set file xattribute ytdl.filesize with
                                     expected file size
--hls-prefer-native                  Use the native HLS downloader instead
                                     of ffmpeg
--hls-prefer-ffmpeg                  Use ffmpeg instead of the native HLS
                                     downloader
--hls-use-mpegts                     Use the mpegts container for HLS
                                     videos, allowing to play the video
                                     while downloading (some players may not
                                     be able to play it)
--external-downloader COMMAND        Use the specified external downloader.
                                     Currently supports aria2c,avconv,axel,c
                                     url,ffmpeg,httpie,wget
--external-downloader-args ARGS      Give these arguments to the external
                                     downloader

Filesystem Options:

copy iconCopydownload iconDownload
-a, --batch-file FILE                File containing URLs to download ('-'
                                     for stdin), one URL per line. Lines
                                     starting with '#', ';' or ']' are
                                     considered as comments and ignored.
--id                                 Use only video ID in file name
-o, --output TEMPLATE                Output filename template, see the
                                     "OUTPUT TEMPLATE" for all the info
--output-na-placeholder PLACEHOLDER  Placeholder value for unavailable meta
                                     fields in output filename template
                                     (default is "NA")
--autonumber-start NUMBER            Specify the start value for
                                     %(autonumber)s (default is 1)
--restrict-filenames                 Restrict filenames to only ASCII
                                     characters, and avoid "&" and spaces in
                                     filenames
-w, --no-overwrites                  Do not overwrite files
-c, --continue                       Force resume of partially downloaded
                                     files. By default, youtube-dl will
                                     resume downloads if possible.
--no-continue                        Do not resume partially downloaded
                                     files (restart from beginning)
--no-part                            Do not use .part files - write directly
                                     into output file
--no-mtime                           Do not use the Last-modified header to
                                     set the file modification time
--write-description                  Write video description to a
                                     .description file
--write-info-json                    Write video metadata to a .info.json
                                     file
--write-annotations                  Write video annotations to a
                                     .annotations.xml file
--load-info-json FILE                JSON file containing the video
                                     information (created with the "--write-
                                     info-json" option)
--cookies FILE                       File to read cookies from and dump
                                     cookie jar in
--cache-dir DIR                      Location in the filesystem where
                                     youtube-dl can store some downloaded
                                     information permanently. By default
                                     $XDG_CACHE_HOME/youtube-dl or
                                     ~/.cache/youtube-dl . At the moment,
                                     only YouTube player files (for videos
                                     with obfuscated signatures) are cached,
                                     but that may change.
--no-cache-dir                       Disable filesystem caching
--rm-cache-dir                       Delete all filesystem cache files

Thumbnail Options:

copy iconCopydownload iconDownload
--write-thumbnail                    Write thumbnail image to disk
--write-all-thumbnails               Write all thumbnail image formats to
                                     disk
--list-thumbnails                    Simulate and list all available
                                     thumbnail formats

Verbosity / Simulation Options:

copy iconCopydownload iconDownload
-q, --quiet                          Activate quiet mode
--no-warnings                        Ignore warnings
-s, --simulate                       Do not download the video and do not
                                     write anything to disk
--skip-download                      Do not download the video
-g, --get-url                        Simulate, quiet but print URL
-e, --get-title                      Simulate, quiet but print title
--get-id                             Simulate, quiet but print id
--get-thumbnail                      Simulate, quiet but print thumbnail URL
--get-description                    Simulate, quiet but print video
                                     description
--get-duration                       Simulate, quiet but print video length
--get-filename                       Simulate, quiet but print output
                                     filename
--get-format                         Simulate, quiet but print output format
-j, --dump-json                      Simulate, quiet but print JSON
                                     information. See the "OUTPUT TEMPLATE"
                                     for a description of available keys.
-J, --dump-single-json               Simulate, quiet but print JSON
                                     information for each command-line
                                     argument. If the URL refers to a
                                     playlist, dump the whole playlist
                                     information in a single line.
--print-json                         Be quiet and print the video
                                     information as JSON (video is still
                                     being downloaded).
--newline                            Output progress bar as new lines
--no-progress                        Do not print progress bar
--console-title                      Display progress in console titlebar
-v, --verbose                        Print various debugging information
--dump-pages                         Print downloaded pages encoded using
                                     base64 to debug problems (very verbose)
--write-pages                        Write downloaded intermediary pages to
                                     files in the current directory to debug
                                     problems
--print-traffic                      Display sent and read HTTP traffic
-C, --call-home                      Contact the youtube-dl server for
                                     debugging
--no-call-home                       Do NOT contact the youtube-dl server
                                     for debugging

Workarounds:

copy iconCopydownload iconDownload
--encoding ENCODING                  Force the specified encoding
                                     (experimental)
--no-check-certificate               Suppress HTTPS certificate validation
--prefer-insecure                    Use an unencrypted connection to
                                     retrieve information about the video.
                                     (Currently supported only for YouTube)
--user-agent UA                      Specify a custom user agent
--referer URL                        Specify a custom referer, use if the
                                     video access is restricted to one
                                     domain
--add-header FIELD:VALUE             Specify a custom HTTP header and its
                                     value, separated by a colon ':'. You
                                     can use this option multiple times
--bidi-workaround                    Work around terminals that lack
                                     bidirectional text support. Requires
                                     bidiv or fribidi executable in PATH
--sleep-interval SECONDS             Number of seconds to sleep before each
                                     download when used alone or a lower
                                     bound of a range for randomized sleep
                                     before each download (minimum possible
                                     number of seconds to sleep) when used
                                     along with --max-sleep-interval.
--max-sleep-interval SECONDS         Upper bound of a range for randomized
                                     sleep before each download (maximum
                                     possible number of seconds to sleep).
                                     Must only be used along with --min-
                                     sleep-interval.

Video Format Options:

copy iconCopydownload iconDownload
-f, --format FORMAT                  Video format code, see the "FORMAT
                                     SELECTION" for all the info
--all-formats                        Download all available video formats
--prefer-free-formats                Prefer free video formats unless a
                                     specific one is requested
-F, --list-formats                   List all available formats of requested
                                     videos
--youtube-skip-dash-manifest         Do not download the DASH manifests and
                                     related data on YouTube videos
--merge-output-format FORMAT         If a merge is required (e.g.
                                     bestvideo+bestaudio), output to given
                                     container format. One of mkv, mp4, ogg,
                                     webm, flv. Ignored if no merge is
                                     required

Subtitle Options:

copy iconCopydownload iconDownload
--write-sub                          Write subtitle file
--write-auto-sub                     Write automatically generated subtitle
                                     file (YouTube only)
--all-subs                           Download all the available subtitles of
                                     the video
--list-subs                          List all available subtitles for the
                                     video
--sub-format FORMAT                  Subtitle format, accepts formats
                                     preference, for example: "srt" or
                                     "ass/srt/best"
--sub-lang LANGS                     Languages of the subtitles to download
                                     (optional) separated by commas, use
                                     --list-subs for available language tags

Authentication Options:

copy iconCopydownload iconDownload
-u, --username USERNAME              Login with this account ID
-p, --password PASSWORD              Account password. If this option is
                                     left out, youtube-dl will ask
                                     interactively.
-2, --twofactor TWOFACTOR            Two-factor authentication code
-n, --netrc                          Use .netrc authentication data
--video-password PASSWORD            Video password (vimeo, youku)

Adobe Pass Options:

copy iconCopydownload iconDownload
--ap-mso MSO                         Adobe Pass multiple-system operator (TV
                                     provider) identifier, use --ap-list-mso
                                     for a list of available MSOs
--ap-username USERNAME               Multiple-system operator account login
--ap-password PASSWORD               Multiple-system operator account
                                     password. If this option is left out,
                                     youtube-dl will ask interactively.
--ap-list-mso                        List all supported multiple-system
                                     operators

Post-processing Options:

copy iconCopydownload iconDownload
-x, --extract-audio                  Convert video files to audio-only files
                                     (requires ffmpeg/avconv and
                                     ffprobe/avprobe)
--audio-format FORMAT                Specify audio format: "best", "aac",
                                     "flac", "mp3", "m4a", "opus", "vorbis",
                                     or "wav"; "best" by default; No effect
                                     without -x
--audio-quality QUALITY              Specify ffmpeg/avconv audio quality,
                                     insert a value between 0 (better) and 9
                                     (worse) for VBR or a specific bitrate
                                     like 128K (default 5)
--recode-video FORMAT                Encode the video to another format if
                                     necessary (currently supported:
                                     mp4|flv|ogg|webm|mkv|avi)
--postprocessor-args ARGS            Give these arguments to the
                                     postprocessor
-k, --keep-video                     Keep the video file on disk after the
                                     post-processing; the video is erased by
                                     default
--no-post-overwrites                 Do not overwrite post-processed files;
                                     the post-processed files are
                                     overwritten by default
--embed-subs                         Embed subtitles in the video (only for
                                     mp4, webm and mkv videos)
--embed-thumbnail                    Embed thumbnail in the audio as cover
                                     art
--add-metadata                       Write metadata to the video file
--metadata-from-title FORMAT         Parse additional metadata like song
                                     title / artist from the video title.
                                     The format syntax is the same as
                                     --output. Regular expression with named
                                     capture groups may also be used. The
                                     parsed parameters replace existing
                                     values. Example: --metadata-from-title
                                     "%(artist)s - %(title)s" matches a
                                     title like "Coldplay - Paradise".
                                     Example (regex): --metadata-from-title
                                     "(?P<artist>.+?) - (?P<title>.+)"
--xattrs                             Write metadata to the video file's
                                     xattrs (using dublin core and xdg
                                     standards)
--fixup POLICY                       Automatically correct known faults of
                                     the file. One of never (do nothing),
                                     warn (only emit a warning),
                                     detect_or_warn (the default; fix file
                                     if we can, warn otherwise)
--prefer-avconv                      Prefer avconv over ffmpeg for running
                                     the postprocessors
--prefer-ffmpeg                      Prefer ffmpeg over avconv for running
                                     the postprocessors (default)
--ffmpeg-location PATH               Location of the ffmpeg/avconv binary;
                                     either the path to the binary or its
                                     containing directory.
--exec CMD                           Execute a command on the file after
                                     downloading and post-processing,
                                     similar to find's -exec syntax.
                                     Example: --exec 'adb push {}
                                     /sdcard/Music/ && rm {}'
--convert-subs FORMAT                Convert the subtitles to other format
                                     (currently supported: srt|ass|vtt|lrc)

CONFIGURATION

copy iconCopydownload iconDownload
# Lines starting with # are comments

# Always extract audio
-x

# Do not copy the mtime
--no-mtime

# Use this proxy
--proxy 127.0.0.1:3128

# Save all videos under Movies directory in your home directory
-o ~/Movies/%(title)s.%(ext)s

Authentication with

copy iconCopydownload iconDownload
touch $HOME/.netrc
chmod a-rwx,u+rw $HOME/.netrc

OUTPUT TEMPLATE

copy iconCopydownload iconDownload
$ youtube-dl --get-filename -o '%(title)s.%(ext)s' BaW_jenozKc
youtube-dl test video ''_ä↭𝕐.mp4    # All kinds of weird characters

$ youtube-dl --get-filename -o '%(title)s.%(ext)s' BaW_jenozKc --restrict-filenames
youtube-dl_test_video_.mp4          # A simple file name

# Download YouTube playlist videos in separate directory indexed by video order in a playlist
$ youtube-dl -o '%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s' https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re

# Download all playlists of YouTube channel/user keeping each playlist in separate directory:
$ youtube-dl -o '%(uploader)s/%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s' https://www.youtube.com/user/TheLinuxFoundation/playlists

# Download Udemy course keeping each chapter in separate directory under MyVideos directory in your home
$ 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/

# Download entire series season keeping each series and each season in separate directory under C:/MyVideos
$ 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

# Stream the video being downloaded to stdout
$ youtube-dl -o - BaW_jenozKc

FORMAT SELECTION

copy iconCopydownload iconDownload
# Download best mp4 format available or any other best if no mp4 available
$ youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'

# Download best format available but no better than 480p
$ youtube-dl -f 'bestvideo[height<=480]+bestaudio/best[height<=480]'

# Download best video only format but no bigger than 50 MB
$ youtube-dl -f 'best[filesize<50M]'

# Download best format available via direct link over HTTP/HTTPS protocol
$ youtube-dl -f '(bestvideo+bestaudio/best)[protocol^=http]'

# Download the best video format and the best audio format without merging them
$ youtube-dl -f 'bestvideo,bestaudio' -o '%(title)s.f%(format_id)s.%(ext)s'

VIDEO SELECTION

copy iconCopydownload iconDownload
# Download only the videos uploaded in the last 6 months
$ youtube-dl --dateafter now-6months

# Download only the videos uploaded on January 1, 1970
$ youtube-dl --date 19700101

$ # Download only the videos uploaded in the 200x decade
$ youtube-dl --dateafter 20000101 --datebefore 20091231

How do I update youtube-dl?

copy iconCopydownload iconDownload
sudo apt-get remove -y youtube-dl

SyntaxError: Non-ASCII character

copy iconCopydownload iconDownload
File "youtube-dl", line 2
SyntaxError: Non-ASCII character '\x93' ...

How do I download a video starting with a

copy iconCopydownload iconDownload
youtube-dl -- -wNyEUrxzFU
youtube-dl "https://www.youtube.com/watch?v=-wNyEUrxzFU"

How do I stream directly to media player?

copy iconCopydownload iconDownload
youtube-dl -o - "https://www.youtube.com/watch?v=BaW_jenozKcj" | vlc -

How do I download only new videos from a playlist?

copy iconCopydownload iconDownload
youtube-dl --download-archive archive.txt "https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re"

DEVELOPER INSTRUCTIONS

copy iconCopydownload iconDownload
python -m youtube_dl

Adding support for a new site

copy iconCopydownload iconDownload
 git clone git@github.com:YOUR_GITHUB_USERNAME/youtube-dl.git

Mandatory and optional metafields

copy iconCopydownload iconDownload
meta = self._download_json(url, video_id)

Provide fallbacks

copy iconCopydownload iconDownload
title = meta['title']

Regular expressions

copy iconCopydownload iconDownload
r'(?:id|ID)=(?P<id>\d+)'

Long lines policy

copy iconCopydownload iconDownload
'https://www.youtube.com/watch?v=FqZTN594JQw&list=PLMYEtVRpaqY00V9W81Cwmzp6N6vZqfUKD4'

Inline values

copy iconCopydownload iconDownload
title = self._html_search_regex(r'<title>([^<]+)</title>', webpage, 'title')

Collapse fallbacks

copy iconCopydownload iconDownload
description = self._html_search_meta(
    ['og:description', 'description', 'twitter:description'],
    webpage, 'description', default=None)

Trailing parentheses

copy iconCopydownload iconDownload
    lambda x: x['ResultSet']['Result'][0]['VideoUrlSet']['VideoUrl'],
    list)

Use convenience conversion and parsing functions

copy iconCopydownload iconDownload
description = try_get(response, lambda x: x['result']['video'][0]['summary'], compat_str)

EMBEDDING YOUTUBE-DL

copy iconCopydownload iconDownload
from __future__ import unicode_literals
import youtube_dl

ydl_opts = {}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=BaW_jenozKc'])

BUGS

copy iconCopydownload iconDownload
$ youtube-dl -v <your command line>
[debug] System config: []
[debug] User config: []
[debug] Command-line args: [u'-v', u'https://www.youtube.com/watch?v=BaW_jenozKcj']
[debug] Encodings: locale cp1251, fs mbcs, out cp866, pref cp1251
[debug] youtube-dl version 2015.12.06
[debug] Git HEAD: 135392e
[debug] Python version 2.6.6 - Windows-2003Server-5.2.3790-SP2
[debug] exe versions: ffmpeg N-75573-g1d0487f, ffprobe N-75573-g1d0487f, rtmpdump 2.4
[debug] Proxy map: {}
...

python modules ffmpeg and ffprobe are installed but youtube-dl not able to find

copy iconCopydownload iconDownload
pip3 install ffprobe
pip3 install ffmpeg

Passing configs from `.txt` file into argparse? (Similar to youtube-dl's `--config-location`)

copy iconCopydownload iconDownload
parser = ArgumentParser(fromfile_prefix_chars='@')
parser.parse_args()
--config_1
This is the first config
--config_2
2nd Config
--config_3
3
...
-----------------------
parser = ArgumentParser(fromfile_prefix_chars='@')
parser.parse_args()
--config_1
This is the first config
--config_2
2nd Config
--config_3
3
...
-----------------------
config_1 = 'This is the first config'
config_2 = '2nd config'
config_3 = 3
import config

print(config.config_1)
print(config.config_2)
print(config.config_3)
This is the first config
2nd config
3
[DEFAULT]
config_1 = 'This is the first config'
config_2 = '2nd config'
config_3 = 3
import configparser

config = configparser.ConfigParser()
config.read('config.ini')
print(config['DEFAULT']['config_1'])
print(config['DEFAULT']['config_2'])
print(config['DEFAULT']['config_3'])
This is the first config
2nd config
3
-----------------------
config_1 = 'This is the first config'
config_2 = '2nd config'
config_3 = 3
import config

print(config.config_1)
print(config.config_2)
print(config.config_3)
This is the first config
2nd config
3
[DEFAULT]
config_1 = 'This is the first config'
config_2 = '2nd config'
config_3 = 3
import configparser

config = configparser.ConfigParser()
config.read('config.ini')
print(config['DEFAULT']['config_1'])
print(config['DEFAULT']['config_2'])
print(config['DEFAULT']['config_3'])
This is the first config
2nd config
3
-----------------------
config_1 = 'This is the first config'
config_2 = '2nd config'
config_3 = 3
import config

print(config.config_1)
print(config.config_2)
print(config.config_3)
This is the first config
2nd config
3
[DEFAULT]
config_1 = 'This is the first config'
config_2 = '2nd config'
config_3 = 3
import configparser

config = configparser.ConfigParser()
config.read('config.ini')
print(config['DEFAULT']['config_1'])
print(config['DEFAULT']['config_2'])
print(config['DEFAULT']['config_3'])
This is the first config
2nd config
3
-----------------------
config_1 = 'This is the first config'
config_2 = '2nd config'
config_3 = 3
import config

print(config.config_1)
print(config.config_2)
print(config.config_3)
This is the first config
2nd config
3
[DEFAULT]
config_1 = 'This is the first config'
config_2 = '2nd config'
config_3 = 3
import configparser

config = configparser.ConfigParser()
config.read('config.ini')
print(config['DEFAULT']['config_1'])
print(config['DEFAULT']['config_2'])
print(config['DEFAULT']['config_3'])
This is the first config
2nd config
3
-----------------------
config_1 = 'This is the first config'
config_2 = '2nd config'
config_3 = 3
import config

print(config.config_1)
print(config.config_2)
print(config.config_3)
This is the first config
2nd config
3
[DEFAULT]
config_1 = 'This is the first config'
config_2 = '2nd config'
config_3 = 3
import configparser

config = configparser.ConfigParser()
config.read('config.ini')
print(config['DEFAULT']['config_1'])
print(config['DEFAULT']['config_2'])
print(config['DEFAULT']['config_3'])
This is the first config
2nd config
3
-----------------------
config_1 = 'This is the first config'
config_2 = '2nd config'
config_3 = 3
import config

print(config.config_1)
print(config.config_2)
print(config.config_3)
This is the first config
2nd config
3
[DEFAULT]
config_1 = 'This is the first config'
config_2 = '2nd config'
config_3 = 3
import configparser

config = configparser.ConfigParser()
config.read('config.ini')
print(config['DEFAULT']['config_1'])
print(config['DEFAULT']['config_2'])
print(config['DEFAULT']['config_3'])
This is the first config
2nd config
3

Change name of audio file downloaded from youtube-dl

copy iconCopydownload iconDownload
youtube-dl -f 'bestaudio[ext=m4a]' -o "$SONG" "$URL"

FFmpeg Minimize memory usage or add timeout to youtube-dl

copy iconCopydownload iconDownload
ffmpeg -y -loglevel verbose -headers 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.67 Safari/537.36\
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\
Accept-Encoding: gzip, deflate\
Accept-Language: en-us,en;q=0.5' \
 -i https://36-d4.divas.cloud/CHAN-3792/CHAN-3792_1.stream/chunklist_w70914220.m3u8 -c copy -f mp4 file:playlist-playlist.mp4.part

Convert variable string to time object

copy iconCopydownload iconDownload
n_colons = YT_Duration_str.count(":")

if n_colons == 0:
    d = dt.strptime(YT_Duration_str, "%S")
elif n_colons == 1:
    d = dt.strptime(YT_Duration_str, "%M:%S")
elif n_colons == 2:
    d = dt.strptime(YT_Duration_str, "%H:%M:%S")

d.strftime("%H:%M:%S")
delta = d - dt.strptime("0", "%S")
-----------------------
n_colons = YT_Duration_str.count(":")

if n_colons == 0:
    d = dt.strptime(YT_Duration_str, "%S")
elif n_colons == 1:
    d = dt.strptime(YT_Duration_str, "%M:%S")
elif n_colons == 2:
    d = dt.strptime(YT_Duration_str, "%H:%M:%S")

d.strftime("%H:%M:%S")
delta = d - dt.strptime("0", "%S")
-----------------------
*rest, hours, minutes, seconds = [0, 0, *map(int, YT_Duration_str.split(':'))]
>>> YT_Duration_str = '01:02:03'
>>> *rest, hours, minutes, seconds = [0, 0, *map(int, YT_Duration_str.split(':'))]
>>> td = datetime.timedelta(hours=hours, minutes=minutes, seconds=seconds)
>>> td
datetime.timedelta(seconds=3723)
>>> dt = datetime.datetime.now().replace(hour=hours, minute=minutes, second=seconds, microsecond=0)
>>> dt
datetime.datetime(2022, 2, 2, 1, 2, 3)
>>> dt.strftime('%H:%M:%S')
'01:02:03'
-----------------------
*rest, hours, minutes, seconds = [0, 0, *map(int, YT_Duration_str.split(':'))]
>>> YT_Duration_str = '01:02:03'
>>> *rest, hours, minutes, seconds = [0, 0, *map(int, YT_Duration_str.split(':'))]
>>> td = datetime.timedelta(hours=hours, minutes=minutes, seconds=seconds)
>>> td
datetime.timedelta(seconds=3723)
>>> dt = datetime.datetime.now().replace(hour=hours, minute=minutes, second=seconds, microsecond=0)
>>> dt
datetime.datetime(2022, 2, 2, 1, 2, 3)
>>> dt.strftime('%H:%M:%S')
'01:02:03'
-----------------------
*rest, hours, minutes, seconds = [0, 0, *map(int, YT_Duration_str.split(':'))]
>>> YT_Duration_str = '01:02:03'
>>> *rest, hours, minutes, seconds = [0, 0, *map(int, YT_Duration_str.split(':'))]
>>> td = datetime.timedelta(hours=hours, minutes=minutes, seconds=seconds)
>>> td
datetime.timedelta(seconds=3723)
>>> dt = datetime.datetime.now().replace(hour=hours, minute=minutes, second=seconds, microsecond=0)
>>> dt
datetime.datetime(2022, 2, 2, 1, 2, 3)
>>> dt.strftime('%H:%M:%S')
'01:02:03'

How to check if programm installed with cmd

copy iconCopydownload iconDownload
@echo off
(where choco.exe)>nul 2>&1
if errorlevel 1 (
    echo Choco not installed. Installing now..
    @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
)

choco install youtube-dl
set /p input="Enter Link For Playlist:" 
set /p index="Enter Index For videos Seprated by ',':"
mkdir playlist_videos
cd playlist_videos
youtube-dl --playlist-items %index% %input%

@echo off
(where choco.exe)>nul 2>&1 && goto :installed || goto :install
:install
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

:installed
choco install youtube-dl
set /p input="Enter Link For Playlist:" 
set /p index="Enter Index For videos Seprated by ',':"
mkdir playlist_videos
cd playlist_videos
youtube-dl --playlist-items %index% %input%
commandname 1>out.log 2>error.log
-----------------------
@echo off
(where choco.exe)>nul 2>&1
if errorlevel 1 (
    echo Choco not installed. Installing now..
    @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
)

choco install youtube-dl
set /p input="Enter Link For Playlist:" 
set /p index="Enter Index For videos Seprated by ',':"
mkdir playlist_videos
cd playlist_videos
youtube-dl --playlist-items %index% %input%

@echo off
(where choco.exe)>nul 2>&1 && goto :installed || goto :install
:install
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

:installed
choco install youtube-dl
set /p input="Enter Link For Playlist:" 
set /p index="Enter Index For videos Seprated by ',':"
mkdir playlist_videos
cd playlist_videos
youtube-dl --playlist-items %index% %input%
commandname 1>out.log 2>error.log
-----------------------
@echo off
(where choco.exe)>nul 2>&1
if errorlevel 1 (
    echo Choco not installed. Installing now..
    @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
)

choco install youtube-dl
set /p input="Enter Link For Playlist:" 
set /p index="Enter Index For videos Seprated by ',':"
mkdir playlist_videos
cd playlist_videos
youtube-dl --playlist-items %index% %input%

@echo off
(where choco.exe)>nul 2>&1 && goto :installed || goto :install
:install
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

:installed
choco install youtube-dl
set /p input="Enter Link For Playlist:" 
set /p index="Enter Index For videos Seprated by ',':"
mkdir playlist_videos
cd playlist_videos
youtube-dl --playlist-items %index% %input%
commandname 1>out.log 2>error.log

Django PIPE youtube-dl to view for download

copy iconCopydownload iconDownload
def download_clip(request, pk):
    ydl_opts = {
        'outtmpl': f"{pk}.mp4"
    }
    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        ydl.download([f"https://clips.twitch.tv/{pk}"])

    path = f"{pk}.mp4"
    file_path = os.path.join(path)
    if os.path.exists(file_path):
        with open(file_path, 'rb') as fh:
            response = HttpResponse(fh.read(), content_type="application/force-download")
            response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path)
            os.remove(file_path)
            return response
    raise Http404

Python buffered IO ending early streaming with multiple pipes [BOUNTY]

copy iconCopydownload iconDownload
from subprocess import Popen, PIPE, DEVNULL
import threading
import time

COPY_BUFSIZE = 65424

playlist = [
    {
        # 15 second video
        "url": "https://youtube.com/watch?v=QiInzFHIDp4"
    },
    {
        # 15 second video
        "url": "https://youtube.com/watch?v=QiInzFHIDp4"
    },
    {
        # 15 second video
        "url": "https://youtube.com/watch?v=QiInzFHIDp4"
    },
]



# Writer thread (read from yt-dlp and write to FFmpeg in chunks of COPY_BUFSIZE bytes).
def writer(yt_dlp_proc, encoder_proc):
    while True:
        yt_dlp_buf = yt_dlp_proc.stdout.read(COPY_BUFSIZE)
        print("READ: yt_dlp")
        if not yt_dlp_buf:
            print("yt-dlp buffer empty")
            break

        written = encoder_proc.stdin.write(yt_dlp_buf)
        print("WRITE: encoder. Bytes: " + str(written))
    
    encoder_proc.stdin.close()  # Close stdin pipe (closing stdin "pushes" the remaining data to stdout).
    encoder_proc.wait()  # Wait for sub-process finish execution.


if __name__ == "__main__":
    rtmp_url = "rtmp://127.0.0.1/live/H1P_x5WPF"

    ffplay_cmd = ['ffplay', '-listen', '1', '-i', rtmp_url] # Start the TCP server first, before the sending client.    
    ffplay_process = Popen(ffplay_cmd, stderr=DEVNULL)  # Use FFplay sub-process for receiving the RTMP video.

    stream_cmd = [
        "ffmpeg", "-loglevel", "error",
        "-hide_banner", "-re", "-i", "-",
        "-c:v", "libx264",
        "-f", "flv",
        "-b:v", "3000k", "-minrate", "3000k",
        "-maxrate", "3000k", "-bufsize", "3000k",
        "-r", "25", "-pix_fmt", "yuv420p",
        rtmp_url #"rtmp://127.0.0.1/live/H1P_x5WPF"
    ]
    print(f'Stream command:\n"{" ".join(stream_cmd)}"')

    encoder_cmd = [
        "ffmpeg", "-re", "-i", "-", "-f", "mpegts",
        "-c", "copy", "-"
    ]
    print(f'Encoder command:\n"{" ".join(encoder_cmd)}"')

    stream_p = Popen(stream_cmd, stdin=PIPE, stderr=DEVNULL)

    for video in playlist:
        yt_dlp_cmd = [
            "yt-dlp", "-q",
            video["url"],
            "-o", "-"
        ]

        print("Now playing: " + video["url"])

        with Popen(yt_dlp_cmd, stdout=PIPE) as yt_dlp_p:
            with Popen(encoder_cmd, stdin=PIPE, stdout=PIPE, stderr=DEVNULL) as encoder_p:

                thread = threading.Thread(target=writer, args=(yt_dlp_p, encoder_p))
                thread.start()  # Start writer thread.

                while True:
                    encoder_buf = encoder_p.stdout.read(COPY_BUFSIZE)

                    if not encoder_buf:
                        print("encoder_buf empty")
                        break

                    print("READ: encoder")

                    stream_bytes_written = stream_p.stdin.write(encoder_buf)
                    print("WRITE: stream, Bytes: " + str(stream_bytes_written))

        thread.join()  # Wait for writer thread to end.
        yt_dlp_p.wait()

    stream_p.stdin.close()  # Close stdin pipe (closing stdin "pushes" the remaining data to stdout).
    stream_p.wait()  # Wait for sub-process finish execution.


    time.sleep(3)  # Wait 3 seconds before closing FFplay
    ffplay_process.kill()  # Forcefully close FFplay sub-process
from pytube import YouTube
from subprocess import Popen, run, PIPE, DEVNULL
import time

playlist = [
    {
        # 15 second video
        "url": "https://youtube.com/watch?v=QiInzFHIDp4"
    },
    {
        # 15 second video
        "url": "https://youtube.com/watch?v=QiInzFHIDp4"
    },
    {
        # 15 second video
        "url": "https://youtube.com/watch?v=QiInzFHIDp4"
    },
]

n = len(playlist)

# Build string for concat demuxer https://video.stackexchange.com/a/18256/18277
filter_complex_str = ''
for i in range(n):
    filter_complex_str += f'[{i}:v]setpts=PTS-STARTPTS[v{i}];[{i}:a]asetpts=PTS-STARTPTS[a{i}];'   # "[0:v]setpts=PTS-STARTPTS[v0];[0:a]asetpts=PTS-STARTPTS[a0];[1:v]setpts=PTS-STARTPTS[v1];[1:a]asetpts=PTS-STARTPTS[a1];[2:v]setpts=PTS-STARTPTS[v2];[2:a]asetpts=PTS-STARTPTS[a2]"
for i in range(n):
    filter_complex_str += f'[v{i}][a{i}]'  # ";[v0][a0][v1][a1][v2][a2]"
filter_complex_str += f'concat=n={n}:v=1:a=1[v][a]'

# Get the video stream URL of every YouTube HTTP URL.
# Add -i before each URL (to be used as FFmpeg input).
playlist_url = []
for video in playlist:
    yt = YouTube(video["url"])
    # https://github.com/pytube/pytube/issues/301
    stream_url = yt.streams[0].url  # Get the URL of the video stream
    playlist_url.append('-i')
    playlist_url.append(stream_url)


rtmp_url = "rtmp://127.0.0.1/live/H1P_x5WPF"

ffplay_cmd = ['ffplay', '-listen', '1', '-i', rtmp_url]  # Start the TCP server first, before the sending client.
ffplay_process = Popen(ffplay_cmd, stderr=DEVNULL)  # Use FFplay sub-process for receiving the RTMP video.

stream_cmd = [
    "ffmpeg", "-loglevel", "error",
    "-hide_banner", "-re"] + playlist_url + ["-filter_complex",
    filter_complex_str,  # '[0:v][0:a][1:v][1:a][2:v][2:a]concat=n=3:v=1:a=1[v][a]'
    "-map", "[v]", "-map", "[a]",
    "-c:v", "libx264",
    "-f", "flv",
    "-b:v", "3000k", "-minrate", "3000k",
    "-maxrate", "3000k", "-bufsize", "3000k",
    "-r", "25", "-pix_fmt", "yuv420p",
    rtmp_url]

run(stream_cmd)

time.sleep(60)  # Wait 60 seconds before closing FFplay
ffplay_process.kill()  # Forcefully close FFplay sub-process
-----------------------
from subprocess import Popen, PIPE, DEVNULL
import threading
import time

COPY_BUFSIZE = 65424

playlist = [
    {
        # 15 second video
        "url": "https://youtube.com/watch?v=QiInzFHIDp4"
    },
    {
        # 15 second video
        "url": "https://youtube.com/watch?v=QiInzFHIDp4"
    },
    {
        # 15 second video
        "url": "https://youtube.com/watch?v=QiInzFHIDp4"
    },
]



# Writer thread (read from yt-dlp and write to FFmpeg in chunks of COPY_BUFSIZE bytes).
def writer(yt_dlp_proc, encoder_proc):
    while True:
        yt_dlp_buf = yt_dlp_proc.stdout.read(COPY_BUFSIZE)
        print("READ: yt_dlp")
        if not yt_dlp_buf:
            print("yt-dlp buffer empty")
            break

        written = encoder_proc.stdin.write(yt_dlp_buf)
        print("WRITE: encoder. Bytes: " + str(written))
    
    encoder_proc.stdin.close()  # Close stdin pipe (closing stdin "pushes" the remaining data to stdout).
    encoder_proc.wait()  # Wait for sub-process finish execution.


if __name__ == "__main__":
    rtmp_url = "rtmp://127.0.0.1/live/H1P_x5WPF"

    ffplay_cmd = ['ffplay', '-listen', '1', '-i', rtmp_url] # Start the TCP server first, before the sending client.    
    ffplay_process = Popen(ffplay_cmd, stderr=DEVNULL)  # Use FFplay sub-process for receiving the RTMP video.

    stream_cmd = [
        "ffmpeg", "-loglevel", "error",
        "-hide_banner", "-re", "-i", "-",
        "-c:v", "libx264",
        "-f", "flv",
        "-b:v", "3000k", "-minrate", "3000k",
        "-maxrate", "3000k", "-bufsize", "3000k",
        "-r", "25", "-pix_fmt", "yuv420p",
        rtmp_url #"rtmp://127.0.0.1/live/H1P_x5WPF"
    ]
    print(f'Stream command:\n"{" ".join(stream_cmd)}"')

    encoder_cmd = [
        "ffmpeg", "-re", "-i", "-", "-f", "mpegts",
        "-c", "copy", "-"
    ]
    print(f'Encoder command:\n"{" ".join(encoder_cmd)}"')

    stream_p = Popen(stream_cmd, stdin=PIPE, stderr=DEVNULL)

    for video in playlist:
        yt_dlp_cmd = [
            "yt-dlp", "-q",
            video["url"],
            "-o", "-"
        ]

        print("Now playing: " + video["url"])

        with Popen(yt_dlp_cmd, stdout=PIPE) as yt_dlp_p:
            with Popen(encoder_cmd, stdin=PIPE, stdout=PIPE, stderr=DEVNULL) as encoder_p:

                thread = threading.Thread(target=writer, args=(yt_dlp_p, encoder_p))
                thread.start()  # Start writer thread.

                while True:
                    encoder_buf = encoder_p.stdout.read(COPY_BUFSIZE)

                    if not encoder_buf:
                        print("encoder_buf empty")
                        break

                    print("READ: encoder")

                    stream_bytes_written = stream_p.stdin.write(encoder_buf)
                    print("WRITE: stream, Bytes: " + str(stream_bytes_written))

        thread.join()  # Wait for writer thread to end.
        yt_dlp_p.wait()

    stream_p.stdin.close()  # Close stdin pipe (closing stdin "pushes" the remaining data to stdout).
    stream_p.wait()  # Wait for sub-process finish execution.


    time.sleep(3)  # Wait 3 seconds before closing FFplay
    ffplay_process.kill()  # Forcefully close FFplay sub-process
from pytube import YouTube
from subprocess import Popen, run, PIPE, DEVNULL
import time

playlist = [
    {
        # 15 second video
        "url": "https://youtube.com/watch?v=QiInzFHIDp4"
    },
    {
        # 15 second video
        "url": "https://youtube.com/watch?v=QiInzFHIDp4"
    },
    {
        # 15 second video
        "url": "https://youtube.com/watch?v=QiInzFHIDp4"
    },
]

n = len(playlist)

# Build string for concat demuxer https://video.stackexchange.com/a/18256/18277
filter_complex_str = ''
for i in range(n):
    filter_complex_str += f'[{i}:v]setpts=PTS-STARTPTS[v{i}];[{i}:a]asetpts=PTS-STARTPTS[a{i}];'   # "[0:v]setpts=PTS-STARTPTS[v0];[0:a]asetpts=PTS-STARTPTS[a0];[1:v]setpts=PTS-STARTPTS[v1];[1:a]asetpts=PTS-STARTPTS[a1];[2:v]setpts=PTS-STARTPTS[v2];[2:a]asetpts=PTS-STARTPTS[a2]"
for i in range(n):
    filter_complex_str += f'[v{i}][a{i}]'  # ";[v0][a0][v1][a1][v2][a2]"
filter_complex_str += f'concat=n={n}:v=1:a=1[v][a]'

# Get the video stream URL of every YouTube HTTP URL.
# Add -i before each URL (to be used as FFmpeg input).
playlist_url = []
for video in playlist:
    yt = YouTube(video["url"])
    # https://github.com/pytube/pytube/issues/301
    stream_url = yt.streams[0].url  # Get the URL of the video stream
    playlist_url.append('-i')
    playlist_url.append(stream_url)


rtmp_url = "rtmp://127.0.0.1/live/H1P_x5WPF"

ffplay_cmd = ['ffplay', '-listen', '1', '-i', rtmp_url]  # Start the TCP server first, before the sending client.
ffplay_process = Popen(ffplay_cmd, stderr=DEVNULL)  # Use FFplay sub-process for receiving the RTMP video.

stream_cmd = [
    "ffmpeg", "-loglevel", "error",
    "-hide_banner", "-re"] + playlist_url + ["-filter_complex",
    filter_complex_str,  # '[0:v][0:a][1:v][1:a][2:v][2:a]concat=n=3:v=1:a=1[v][a]'
    "-map", "[v]", "-map", "[a]",
    "-c:v", "libx264",
    "-f", "flv",
    "-b:v", "3000k", "-minrate", "3000k",
    "-maxrate", "3000k", "-bufsize", "3000k",
    "-r", "25", "-pix_fmt", "yuv420p",
    rtmp_url]

run(stream_cmd)

time.sleep(60)  # Wait 60 seconds before closing FFplay
ffplay_process.kill()  # Forcefully close FFplay sub-process

How to set youtube-dl python to always pick 1080p

copy iconCopydownload iconDownload
youtube_dl_options = {
    "format": "mp4[height=1080]", # This will select the specific resolution typed here
    "outtmpl": "%(title)s-%(id)s.%(ext)s",
    "restrictfilenames": True,
    "nooverwrites": True,
    "writedescription": True,
    "writeinfojson": True,
    "writeannotations": True,
    "writethumbnail": True,
    "writesubtitles": True,
    "writeautomaticsub": True
}

How To Extract Value From List In Python

copy iconCopydownload iconDownload
import re
import youtube_dl
import pandas as pd

# Scrape Online Product
def run_scraper():
    ydl_opts = {}
    all_scrapes = []

    # Read CSV to List
    with open("single.csv", "r") as f:
        csv_reader = csv.reader(f)
        next(csv_reader)

        # Scrape Data From Store
        for csv_line_entry in csv_reader:

            with youtube_dl.YoutubeDL(ydl_opts) as ydl:
                meta = ydl.extract_info(csv_line_entry[0], download=False)
                channel = meta["channel"]
                title = meta["title"]
                description = meta["description"]
                twitter_list = get_links(description, "twitter.com")

                print("Channel        :", channel)
                print("Title          :", title)
                print("Twitter URLs   :", twitter_list)
                print("-" * 120)
                print()

            all_scrapes.append((channel, title, twitter_list))

    return all_scrapes


def get_links(description, link):
    out = []

    # Find URLs in description
    description_urls = re.findall(r"(https?://[^\s]+)", description)

    for item in description_urls:
        if link in item:
            out.append(item)

    return out


df = pd.DataFrame(run_scraper(), columns=["channel", "title", "twitter URLs"])
print(df)
[youtube] kqtD5dpn9C8: Downloading webpage
Channel        : Programming with Mosh
Title          : Python for Beginners - Learn Python in 1 Hour
Twitter URLs   : ['https://twitter.com/moshhamedani']
------------------------------------------------------------------------------------------------------------------------

[youtube] rfscVS0vtbw: Downloading webpage
Channel        : freeCodeCamp.org
Title          : Learn Python - Full Course for Beginners [Tutorial]
Twitter URLs   : ['https://twitter.com/mike_dane']
------------------------------------------------------------------------------------------------------------------------

                 channel                                                title                        twitter URLs
0  Programming with Mosh        Python for Beginners - Learn Python in 1 Hour  [https://twitter.com/moshhamedani]
1       freeCodeCamp.org  Learn Python - Full Course for Beginners [Tutorial]     [https://twitter.com/mike_dane]
-----------------------
import re
import youtube_dl
import pandas as pd

# Scrape Online Product
def run_scraper():
    ydl_opts = {}
    all_scrapes = []

    # Read CSV to List
    with open("single.csv", "r") as f:
        csv_reader = csv.reader(f)
        next(csv_reader)

        # Scrape Data From Store
        for csv_line_entry in csv_reader:

            with youtube_dl.YoutubeDL(ydl_opts) as ydl:
                meta = ydl.extract_info(csv_line_entry[0], download=False)
                channel = meta["channel"]
                title = meta["title"]
                description = meta["description"]
                twitter_list = get_links(description, "twitter.com")

                print("Channel        :", channel)
                print("Title          :", title)
                print("Twitter URLs   :", twitter_list)
                print("-" * 120)
                print()

            all_scrapes.append((channel, title, twitter_list))

    return all_scrapes


def get_links(description, link):
    out = []

    # Find URLs in description
    description_urls = re.findall(r"(https?://[^\s]+)", description)

    for item in description_urls:
        if link in item:
            out.append(item)

    return out


df = pd.DataFrame(run_scraper(), columns=["channel", "title", "twitter URLs"])
print(df)
[youtube] kqtD5dpn9C8: Downloading webpage
Channel        : Programming with Mosh
Title          : Python for Beginners - Learn Python in 1 Hour
Twitter URLs   : ['https://twitter.com/moshhamedani']
------------------------------------------------------------------------------------------------------------------------

[youtube] rfscVS0vtbw: Downloading webpage
Channel        : freeCodeCamp.org
Title          : Learn Python - Full Course for Beginners [Tutorial]
Twitter URLs   : ['https://twitter.com/mike_dane']
------------------------------------------------------------------------------------------------------------------------

                 channel                                                title                        twitter URLs
0  Programming with Mosh        Python for Beginners - Learn Python in 1 Hour  [https://twitter.com/moshhamedani]
1       freeCodeCamp.org  Learn Python - Full Course for Beginners [Tutorial]     [https://twitter.com/mike_dane]

Community Discussions

Trending Discussions on youtube-dl
  • python modules ffmpeg and ffprobe are installed but youtube-dl not able to find
  • Passing configs from `.txt` file into argparse? (Similar to youtube-dl's `--config-location`)
  • mpv doesn't recognise ytdl_path as a key
  • Change name of audio file downloaded from youtube-dl
  • FFmpeg Minimize memory usage or add timeout to youtube-dl
  • Pafy Youtube Error 403 when converting video
  • Convert variable string to time object
  • How to check if programm installed with cmd
  • Django PIPE youtube-dl to view for download
  • Python buffered IO ending early streaming with multiple pipes [BOUNTY]
Trending Discussions on youtube-dl

QUESTION

python modules ffmpeg and ffprobe are installed but youtube-dl not able to find

Asked 2022-Mar-31 at 23:30

I'm using python 3.8 on MacOS Big Sur

I installed python module package for youtube-dl with

pip3 install -upgrade youtube-dl

I wanted to do post processing on the content downloaded so I installed python packages ffprobe and ffmpeg.

pip3 install ffprobe
Collecting ffprobe
  Downloading https://files.pythonhosted.org/packages/95/9c/adf90d21108d41f611aa921defd2f2e56d3f92724e4b5aa41fae7a9972aa/ffprobe-0.5.zip
Installing collected packages: ffprobe
  Running setup.py install for ffprobe ... done
Successfully installed ffprobe-0.5

pip3 install ffmpeg
Collecting ffmpeg
  Downloading https://files.pythonhosted.org/packages/f0/cc/3b7408b8ecf7c1d20ad480c3eaed7619857bf1054b690226e906fdf14258/ffmpeg-1.4.tar.gz
Installing collected packages: ffmpeg
  Running setup.py install for ffmpeg ... done
Successfully installed ffmpeg-1.4
pip3 list 
Package    Version   
---------- ----------
ffmpeg     1.4       
ffprobe    0.5           
youtube-dl 2021.12.17 

Still it is complaining can't find ffprobe and ffmpeg:

youtube_dl.utils.DownloadError: ERROR: ffprobe/avprobe and ffmpeg/avconv not found. Please install one.

I see both packages in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/

Trying to figure out what am I doing wrong. Many other answers to similar questions on SFO are suggesting installing these packages in the OS using brew etc. but in my case "I want to do everything through python". So shouldn't just installing python modules be enough?

ANSWER

Answered 2021-Dec-31 at 04:07

Check the Path environment variable. It should contain an entry for the folder that ffprobe and ffmpeg are in.

EDIT: My bad, check this Reddit thread. https://www.reddit.com/r/learnpython/comments/gqhj14/comment/frsq2u3/?utm_source=share&utm_medium=web2x&context=3

It seems you might have to install the command-line tool.

Source https://stackoverflow.com/questions/70516022

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install youtube-dl

To install it right away for all UNIX users (Linux, macOS, etc.), type:.

Support

As a matter of policy (as well as legality), youtube-dl does not include support for services that specialize in infringing copyright. As a rule of thumb, if you cannot easily find a video that the service is quite obviously allowed to distribute (i.e. that has been uploaded by the creator, the creator's distributor, or is published under a free license), the service is probably unfit for inclusion to youtube-dl. A note on the service that they don't host the infringing content, but just link to those who do, is evidence that the service should not be included into youtube-dl. The same goes for any DMCA note when the whole front page of the service is filled with videos they are not allowed to distribute. A "fair use" note is equally unconvincing if the service shows copyright-protected videos in full without authorization. Support requests for services that do purchase the rights to distribute their content are perfectly fine though. If in doubt, you can simply include a source that mentions the legitimate purchase of content.

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Share this Page

share link
Compare Machine Learning Libraries with Highest Support
Compare Machine Learning Libraries with Highest Quality
Compare Machine Learning Libraries with Highest Security
Compare Machine Learning Libraries with Permissive License
Compare Machine Learning Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.