Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
youtube dl python库文档_Python_Youtube Dl - Fatal编程技术网

youtube dl python库文档

youtube dl python库文档,python,youtube-dl,Python,Youtube Dl,是否有任何文档可以在项目中将youtube dl用作python库 我知道我可以使用主类,但是我找不到任何文档或示例 import youtube_dl ydl = youtube_dl.YoutubeDL(params) ... ? 如果您从下载一个版本,您可以生成sphinx文档,这对开发非常有用。然后,使用pythons帮助函数通常可以了解函数的用途 >>> import youtube_dl as yt >>> help(yt) 此外,我发现i

是否有任何文档可以在项目中将youtube dl用作python库

我知道我可以使用主类,但是我找不到任何文档或示例

import youtube_dl

ydl = youtube_dl.YoutubeDL(params)

... ?

如果您从下载一个版本,您可以生成sphinx文档,这对开发非常有用。然后,使用pythons帮助函数通常可以了解函数的用途

>>> import youtube_dl as yt
>>> help(yt)
此外,我发现ipython是一个有用的工具,可以使用
%edit
magic来探索代码

%edit yt.main 
将直接带您到主函数的源代码

类似问题:

在源中检查此文件:

您需要选项dict(最初使用从命令行接收的参数生成):

然后创建
YoutubeDL
实例,并使用自述名称调用一些方法:

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
将YoutubeDL(ydl_选项)作为ydl:
ydl.print_debug_头()
ydl.add_default_info_提取器()
#后处理器
#首先添加元数据pp,其他pp将复制它
如果选择opts.addmetadata:
ydl.add_post_处理器(FFmpegMetadataPP())
如果选择提取音频:
ydl.add_post_处理器(ffmpegextractadiopp(preferredcodec=opts.audioformat,preferredquality=opts.audioquality,nopostoverwrites=opts.nopostoverwrites))
如果选择重新记录设备:
ydl.add_post_处理器(ffmpegvideoconverter(preferedformat=opts.recodevideo))
如果选择嵌入字幕:
ydl.add_post_处理器(ffmpegembestubtitlepp(subtitleformat=opts.subtitleformat))
如果opts.xattrs:
ydl.add_post_处理器(XAttrMetadataPP())
如果选择“嵌入缩略图”:
如果不选择opts.addmetadata:
ydl.add_post_处理器(FFmpegAudioFixPP())
ydl.add_post_处理器(AtomicParsleyPP())
#请将ExecAfterDownload放在底部,因为它允许用户以任何方式修改最终文件。
#因此,如果用户能够在后处理器运行之前删除该文件,则可能会导致一些问题。
如果opts.exec\u cmd:
ydl.add_post_处理器(execafterdownloadp(
verboseOutput=opts.verbose,exec_cmd=opts.exec_cmd))
#更新版本
如果选择“更新自身”:
更新自身(ydl.to_屏幕,opts.verbose)
#删除缓存目录
如果opts.rm_cachedir:
ydl.cache.remove()
#也许什么也不做
如果(len(所有URL)<1)和(opts.load\u info\u文件名为None):
如果不是(opts.update\u self或opts.rm\u cachedir):
parser.error(您必须至少提供一个URL)
其他:
sys.exit()
尝试:
如果opts.load\u info\u文件名不是None:
retcode=ydl.download_与_info_文件(opts.load_info_文件名)
其他:
retcode=ydl.download(所有URL)
除MaxDownloads外,已获取:
ydl.to_屏幕(u'--达到最大下载限制,正在中止)
retcode=101
关于嵌入youtube dl。你在正确的轨道上

import youtube_dl

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

是一个很好的最小程序。

您可以使用


请不要复制所有的
\uuuu init\uuuu.py
;大部分都没有什么用处。相反,请按照官方文件的说明进行操作。遗憾的是,YoutubeDL.py仍然没有文档
import youtube_dl

with youtube_dl.YoutubeDL({}) as ydl:
    ydl.download(['http://www.youtube.com/watch?v=BaW_jenozKc'])
   ydl_opts = {
        'usenetrc': opts.usenetrc,
        'username': opts.username,
        'password': opts.password,
        'twofactor': opts.twofactor,
        'videopassword': opts.videopassword,
        'ap_mso': opts.ap_mso,
        'ap_username': opts.ap_username,
        'ap_password': opts.ap_password,
        'quiet': (opts.quiet or any_getting or any_printing),
        'no_warnings': opts.no_warnings,
        'forceurl': opts.geturl,
        'forcetitle': opts.gettitle,
        'forceid': opts.getid,
        'forcethumbnail': opts.getthumbnail,
        'forcedescription': opts.getdescription,
        'forceduration': opts.getduration,
        'forcefilename': opts.getfilename,
        'forceformat': opts.getformat,
        'forcejson': opts.dumpjson or opts.print_json,
        'dump_single_json': opts.dump_single_json,
        'simulate': opts.simulate or any_getting,
        'skip_download': opts.skip_download,
        'format': opts.format,
        'listformats': opts.listformats,
        'outtmpl': outtmpl,
        'outtmpl_na_placeholder': opts.outtmpl_na_placeholder,
        'autonumber_size': opts.autonumber_size,
        'autonumber_start': opts.autonumber_start,
        'restrictfilenames': opts.restrictfilenames,
        'ignoreerrors': opts.ignoreerrors,
        'force_generic_extractor': opts.force_generic_extractor,
        'ratelimit': opts.ratelimit,
        'nooverwrites': opts.nooverwrites,
        'retries': opts.retries,
        'fragment_retries': opts.fragment_retries,
        'skip_unavailable_fragments': opts.skip_unavailable_fragments,
        'keep_fragments': opts.keep_fragments,
        'buffersize': opts.buffersize,
        'noresizebuffer': opts.noresizebuffer,
        'http_chunk_size': opts.http_chunk_size,
        'continuedl': opts.continue_dl,
        'noprogress': opts.noprogress,
        'progress_with_newline': opts.progress_with_newline,
        'playliststart': opts.playliststart,
        'playlistend': opts.playlistend,
        'playlistreverse': opts.playlist_reverse,
        'playlistrandom': opts.playlist_random,
        'noplaylist': opts.noplaylist,
        'logtostderr': opts.outtmpl == '-',
        'consoletitle': opts.consoletitle,
        'nopart': opts.nopart,
        'updatetime': opts.updatetime,
        'writedescription': opts.writedescription,
        'writeannotations': opts.writeannotations,
        'writeinfojson': opts.writeinfojson,
        'writethumbnail': opts.writethumbnail,
        'write_all_thumbnails': opts.write_all_thumbnails,
        'writesubtitles': opts.writesubtitles,
        'writeautomaticsub': opts.writeautomaticsub,
        'allsubtitles': opts.allsubtitles,
        'listsubtitles': opts.listsubtitles,
        'subtitlesformat': opts.subtitlesformat,
        'subtitleslangs': opts.subtitleslangs,
        'matchtitle': decodeOption(opts.matchtitle),
        'rejecttitle': decodeOption(opts.rejecttitle),
        'max_downloads': opts.max_downloads,
        'prefer_free_formats': opts.prefer_free_formats,
        'verbose': opts.verbose,
        'dump_intermediate_pages': opts.dump_intermediate_pages,
        'write_pages': opts.write_pages,
        'test': opts.test,
        'keepvideo': opts.keepvideo,
        'min_filesize': opts.min_filesize,
        'max_filesize': opts.max_filesize,
        'min_views': opts.min_views,
        'max_views': opts.max_views,
        'daterange': date,
        'cachedir': opts.cachedir,
        'youtube_print_sig_code': opts.youtube_print_sig_code,
        'age_limit': opts.age_limit,
        'download_archive': download_archive_fn,
        'cookiefile': opts.cookiefile,
        'nocheckcertificate': opts.no_check_certificate,
        'prefer_insecure': opts.prefer_insecure,
        'proxy': opts.proxy,
        'socket_timeout': opts.socket_timeout,
        'bidi_workaround': opts.bidi_workaround,
        'debug_printtraffic': opts.debug_printtraffic,
        'prefer_ffmpeg': opts.prefer_ffmpeg,
        'include_ads': opts.include_ads,
        'default_search': opts.default_search,
        'youtube_include_dash_manifest': opts.youtube_include_dash_manifest,
        'encoding': opts.encoding,
        'extract_flat': opts.extract_flat,
        'mark_watched': opts.mark_watched,
        'merge_output_format': opts.merge_output_format,
        'postprocessors': postprocessors,
        'fixup': opts.fixup,
        'source_address': opts.source_address,
        'call_home': opts.call_home,
        'sleep_interval': opts.sleep_interval,
        'max_sleep_interval': opts.max_sleep_interval,
        'external_downloader': opts.external_downloader,
        'list_thumbnails': opts.list_thumbnails,
        'playlist_items': opts.playlist_items,
        'xattr_set_filesize': opts.xattr_set_filesize,
        'match_filter': match_filter,
        'no_color': opts.no_color,
        'ffmpeg_location': opts.ffmpeg_location,
        'hls_prefer_native': opts.hls_prefer_native,
        'hls_use_mpegts': opts.hls_use_mpegts,
        'external_downloader_args': external_downloader_args,
        'postprocessor_args': postprocessor_args,
        'cn_verification_proxy': opts.cn_verification_proxy,
        'geo_verification_proxy': opts.geo_verification_proxy,
        'config_location': opts.config_location,
        'geo_bypass': opts.geo_bypass,
        'geo_bypass_country': opts.geo_bypass_country,
        'geo_bypass_ip_block': opts.geo_bypass_ip_block,
        # just for deprecation check
        'autonumber': opts.autonumber if opts.autonumber is True else None,
        'usetitle': opts.usetitle if opts.usetitle is True else None,
    }