用于oembed的python库,支持自动发现和手动包含的提供程序。

pyoembed的Python项目详细描述


https://ci.rgm.io/buildStatus/icon?job=pyoembed

用于oembed的python库,支持自动发现和手动 包括供应商。

安装

$ pip install pyoembed

用法

库提供了一个函数,应该调用该函数来自动嵌入 url内容,称为oEmbed

frompyoembedimportoEmbed,PyOembedExceptiontry:# maxwidth and maxheight are optional.data=oEmbed('http://www.youtube.com/watch?v=_PEdPBEpQfY',maxwidth=640,maxheight=480)exceptPyOembedException,e:print'An error was ocurred: %s'%e# data is a dict with keys that will depends on the media type. You should# choose how to display the content based on the data['type'] value and# the oEmbed spec ( http://oembed.com/ ).ifdata['type']=='video':printdata['html']# and it goes... Someday we will provide default renderes for each media# type.

新增供应商

pyoembed试图覆盖主要的oembed提供者,并且应该为任何 支持oEmbed自动发现的提供程序,但是 可能还不支持收藏夹提供程序:(

要添加它,请在pyoembed.providers包中创建一个文件,基于 以下示例:

frompyoembed.providersimportBaseProviderclassInstagramProvider(BaseProvider):# priority of the provider. Increase it if the provider isn't well knownpriority=10# url schemas that are supported by the provider.# re.compile'd regex are allowed.oembed_schemas=['http://instagram.com/p/*','http://instagr.am/p/*']# api endpoint that answers to oEmbed requests for the provider.oembed_endpoint='http://api.instagram.com/oembed'

您还需要向 integration_test.py文件,运行它以查看是否一切正常。

如果一切正常,请发送请求以添加提供商:

https://github.com/rafaelmartins/pyoembed/pulls

就这样!

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为什么这段代码要打印空字符串?   java未知错误:由于标签页崩溃,会话被删除   布尔型上的java函数if-else   java最佳蚂蚁教程/快速入门?   JAVAutil。java中的扫描程序跳过do while循环中的扫描程序输入   java我们可以在selenium中使用ExpectedConditions和FluentWait来实现通用等待方法吗?   java如何使用gson库解析JSONObject   java GWT模拟Android LinearLayout的布局重量属性?   Java正则表达式重写日期表达式   java MediaPlayer播放我的MP3文件,但非常安静   java背景不显示javaFX   用于CLI的java quarkus开发模式,如何重新启动应用程序   websphere WSJdbcDataSource的java Jar文件   java Spring 4对象不会自动连接变量   java从Dbpedia定制本体/RDF图