Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

youtube-dl python library documentation

is there any documentation for use youtube-dl as a python library in a project?

I know that I can use the main class, but I can't find any documentation or example...

import youtube_dl

ydl = youtube_dl.YoutubeDL(params)

... ?
like image 285
NaN Avatar asked Oct 21 '14 20:10

NaN


People also ask

Does youtube-dl need Python?

youtube-dl is a command-line program to download videos from YouTube.com and a few more sites. It requires the Python interpreter (2.6, 2.7, or 3.2+), and it is not platform-specific.

Where do youtube-dl files go?

On Windows, the user wide configuration file locations are %APPDATA%\youtube-dl\config. txt or C:\Users\<user name>\youtube-dl. conf . Note that by default configuration file may not exist so you may need to create it yourself.

Is youtube-dl legit?

youtube-dl is a free and open source download manager for video and audio from YouTube and over 1,000 other video hosting websites. It is released under the Unlicense software license. As of September 2021, youtube-dl is one of the most starred projects on GitHub, with over 100,000 stars.

How do you use YT DL?

Download a video: Enter the following command in the Terminal or Command Line and press Enter to download the video: Type youtube-dl <url_to_video> and press Enter. To paste the video URL, press Ctrl + V on Windows, Command + V on Mac, or Shift + Ctrl + V on Linux.


2 Answers

If you download a version from github you can generate sphinx-docs which is useful for developement. Then using pythons help function usually gives some idea what the purpose of a function is

>>> import youtube_dl as yt
>>> help(yt)

Furthermore I find ipython a useful tool to explore code using the %edit magic.

%edit yt.main 

would bring you directly to the source of the main function.

like image 183
greole Avatar answered Sep 20 '22 09:09

greole


similar question: How to use youtube-dl from a python program

Check this file in sources: https://github.com/rg3/youtube-dl/blob/master/youtube_dl/__init__.py

You need options dict (originally generated using parameters received from command line):

ydl_opts = {
    'usenetrc': opts.usenetrc,
    'username': opts.username,
    'password': opts.password,
    # ... all options list available in sources
    'exec_cmd': opts.exec_cmd,
}

and then create YoutubeDL instance and call some methods with self-described names:

with YoutubeDL(ydl_opts) as ydl:
    ydl.print_debug_header()
    ydl.add_default_info_extractors()

    # PostProcessors
    # Add the metadata pp first, the other pps will copy it
    if opts.addmetadata:
        ydl.add_post_processor(FFmpegMetadataPP())
    if opts.extractaudio:
        ydl.add_post_processor(FFmpegExtractAudioPP(preferredcodec=opts.audioformat, preferredquality=opts.audioquality, nopostoverwrites=opts.nopostoverwrites))
    if opts.recodevideo:
        ydl.add_post_processor(FFmpegVideoConvertor(preferedformat=opts.recodevideo))
    if opts.embedsubtitles:
        ydl.add_post_processor(FFmpegEmbedSubtitlePP(subtitlesformat=opts.subtitlesformat))
    if opts.xattrs:
        ydl.add_post_processor(XAttrMetadataPP())
    if opts.embedthumbnail:
        if not opts.addmetadata:
            ydl.add_post_processor(FFmpegAudioFixPP())
        ydl.add_post_processor(AtomicParsleyPP())


    # Please keep ExecAfterDownload towards the bottom as it allows the user to modify the final file in any way.
    # So if the user is able to remove the file before your postprocessor runs it might cause a few problems.
    if opts.exec_cmd:
        ydl.add_post_processor(ExecAfterDownloadPP(
            verboseOutput=opts.verbose, exec_cmd=opts.exec_cmd))

    # Update version
    if opts.update_self:
        update_self(ydl.to_screen, opts.verbose)

    # Remove cache dir
    if opts.rm_cachedir:
        ydl.cache.remove()

    # Maybe do nothing
    if (len(all_urls) < 1) and (opts.load_info_filename is None):
        if not (opts.update_self or opts.rm_cachedir):
            parser.error(u'you must provide at least one URL')
        else:
            sys.exit()

    try:
        if opts.load_info_filename is not None:
            retcode = ydl.download_with_info_file(opts.load_info_filename)
        else:
            retcode = ydl.download(all_urls)
    except MaxDownloadsReached:
        ydl.to_screen(u'--max-download limit reached, aborting.')
        retcode = 101
like image 31
ndpu Avatar answered Sep 18 '22 09:09

ndpu