Doist/media-embed-server

语言: CoffeeScript

git: https://github.com/Doist/media-embed-server

在JavaScript中使用oEmbed代理,支持一些额外的非oEmbed源代码
oEmbed proxy in JavaScript that support a few additional non-oEmbed sources
README.md (中文)

轻松嵌入媒体

media-embed-server是一个节点服务器,可以解析内容,提取链接并返回有关它们的信息。信息可以是标题,缩略图,直接链接等(取决于服务)

对于某些服务,它使用oEmbed,而对于其他服务,它使用其他API。

它在很大程度上取决于媒体解析器。

部分

特征

  • 非阻塞并行获取数据
  • 适用于大量服务的统一API
  • 能够在memcached中缓存结果
  • 最小代码库(服务器大约100行)
  • 支持JSONP

安装服务

安装服务非常简单:

npm install media-server-embed -g

运行服务

运行服务的签名是:

media-server-embed -p <port> -c <memcached (optional)>

一个例子:

media-server-embed -p 8081 -c localhost:11211

API端点

/ parseContent

必需参数: * content:从中提取媒体信息的内容。

可选参数:  timeout = 5:我们应该等待外部服务超时多长时间?默认值为5秒。  min_tn_size = 100:最小缩略图大小。默认值为100.当资源具有不同大小的多个缩略图时,这非常有用。 * callback:将结果包装在JavaScript函数调用(JSONP)中。默认为none。

例:

解析请求的示例:

http://localhost:8080/parseContent?content=This+is+a+test+https://www.youtube.com/watch?v=lYHzdqGR9-U&min_tn_size=100

成功回归:

附加到URL的匹配URL和信息的JSON列表。例:

[
    {
        "url": "https://www.youtube.com/watch?v=lYHzdqGR9-U",
        "title": "[프로리그2014] 정우용(CJ) vs 김유진(진에어) 2세트 해비테이션...",
        "thumbnail": {
            "url": "...",
            "width": 100,
            "height": 100
        },
        "html": "..."
    }
]

错误返回

结果dict中的错误将作为具有错误属性的特殊JSON对象返回。

例:

[
    {
        "url": "https://www.youtube.com/watch?v=lYHzdqGR9-U",
        "error": "Service timeout"
    }
]

结果说明

永远存在:  url:资源的URL  title:资源的标题 * type:资源的类型,可以是网站,图片,视频或音频

可以出席:  错误:出了点问题  description:URL的描述  thumbnail:缩略图信息。将是一个包含网址,宽度和高度的对象  html:oEmbed HTML(在大多数情况下,它将是一个iFrame)

/供应商

返回受支持的提供程序列表,包括与media-embed-server支持的所有服务匹配的正则表达式。如果在本地存储此正则表达式,则可以在本地应答是否支持服务。

支持的服务

  • deviantart.com(oEmbed)
  • flickr.com(oEmbed)
  • hulu.com(oEmbed)
  • justin.tv(oEmbed)
  • rdio.com(oEmbed)
  • screenr.com(oEmbed)
  • slideshare.com(oEmbed)
  • soundcloud.com(oEmbed)
  • spotify.com(oEmbed)
  • ted.com(oEmbed)
  • vimeo.com(oEmbed)
  • youtube.com(oEmbed)
  • img.ly(自定义)
  • instagr.am(自定义)
  • twitpic.com(自定义)
  • yfrog.com(自定义)

作者

  • amirs阿里和粉底擦
  • GonçaloSilva

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

Embed media easily

media-embed-server is a node server that can parse content, extract links and return info about them. Info can be title, thumbnails, direct links etc. (depends on the service)

For some services it uses oEmbed, for others it uses other APIs.

It depends heavily on media-parser.

pars

Features

  • Non-blocking parallel fetching of data
  • Unified API for a lot of services
  • Ability to cache results in memcached
  • Minimal code base (around 100 lines for the server)
  • Support for JSONP

Installing the service

Installing the service is quite easy:

npm install media-server-embed -g

Running the service

The signature for running the service is:

media-server-embed -p <port> -c <memcached (optional)>

An example:

media-server-embed -p 8081 -c localhost:11211

API endpoints

/parseContent

Required arguments:
* content: Content to extract media information from.

Optional arguments:
timeout=5: How long should we wait for the external service a timeout? Default is 5 sec.
min_tn_size=100: Minimum thumbnail size. Default is 100. This is useful when a resource has multiple thumbnails in different sizes.
* callback: Wrap the result in a JavaScript function call (JSONP). Default is none.

Example:

An example of a parse request:

http://localhost:8080/parseContent?content=This+is+a+test+https://www.youtube.com/watch?v=lYHzdqGR9-U&min_tn_size=100

Successful return:

A JSON list of matched URLs and information attached to the URL. Example:

[
    {
        "url": "https://www.youtube.com/watch?v=lYHzdqGR9-U",
        "title": "[프로리그2014] 정우용(CJ) vs 김유진(진에어) 2세트 해비테이션...",
        "thumbnail": {
            "url": "...",
            "width": 100,
            "height": 100
        },
        "html": "..."
    }
]

Error Return

The errors are returned in the result dict as special JSON objects that have an error attribute.

Example:

[
    {
        "url": "https://www.youtube.com/watch?v=lYHzdqGR9-U",
        "error": "Service timeout"
    }
]

Result specification

Always present:
url: The URL of the resource
title: The title of the resource
* type: The type of the resource, can be website, image, video or audio

Can be present:
error: Something went wrong
description: The description of the URL
thumbnail: The thumbnail information. Will be an object that includes url, width and height
html: oEmbed HTML (in most cases it will be an iFrame)

/providers

Returns a list of providers that are supported, including a regular expressions that matches all the services that media-embed-server supports. If you store this regular expression locally you can answer locally if a service is supported or not.

Supported services

  • deviantart.com (oEmbed)
  • flickr.com (oEmbed)
  • hulu.com (oEmbed)
  • justin.tv (oEmbed)
  • rdio.com (oEmbed)
  • screenr.com (oEmbed)
  • slideshare.com (oEmbed)
  • soundcloud.com (oEmbed)
  • spotify.com (oEmbed)
  • ted.com (oEmbed)
  • vimeo.com (oEmbed)
  • youtube.com (oEmbed)
  • img.ly (custom)
  • instagr.am (custom)
  • twitpic.com (custom)
  • yfrog.com (custom)

Authors