来自WEBVTT的RDF / JSON的Javascript解析器 [英] Javascript parser for RDF/JSON from WEBVTT

查看:116
本文介绍了来自WEBVTT的RDF / JSON的Javascript解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚上好。

直截了当 - 我需要一个在WEBVTT文件中从特定时间间隔抓取RDF / JSON结构的脚本。这样的事情是否存在?

Straight to the point - I would need a script that grabs RDF/JSON structure from specific time interval in WEBVTT file. Does such a thing exist?

RDF / JSON是Talis指定的文件结构,如下所示:

RDF/JSON is Talis specified file structure that looks like this:

{ "S" : { "P" : [ O ] } }

WEBVTT实现了这样的结构:

WEBVTT implements mentioned structure like this:

0
00:00:00,000 --> 00:00:46,119
{ "S" : { "P" : [ O ] } }

1
00:00:48,000 --> 00:00:50,211
{ "S" : { "P" : [ O ] } }

...

我会在查看视频文件时使用这样的文件,当我点击时间轴的某些部分时,脚本会获取相应的RDF / JSON代码(我是现在能够执行此操作,已经有一个WEBVTT解析器),然后解析器从RDF / JSON结构中获取对象中的请求信息。

And I would use such file while viewing the video files in such way that when I click on some part of the timeline, script fetches corresponding RDF/JSON code (I'm able to do this now, there is a WEBVTT parser already), and then parser fetches requested information in the object from the RDF/JSON structure.

我真的很开心我看到jQuery实现了getJson,但它只适用于普通json文件。

I was really happy when I saw that jQuery has getJson implemented, but it works only for "normal" json files.

最好的办法可能只是编写脚本,但我的时机和知识非常有限,所以我想听听任何人可能知道的任何建议或解决方案。

The best thing would probably be to just write the script, but my timing and knowledge are very limited, so I would like to hear any suggestion or solution that anybody might know.

推荐答案

我写过一篇文章我的< track> / HTML5视频字幕polyfill 的WebVTT解析器Captionator

I've written a WebVTT parser for my <track>/HTML5 video captioning polyfill Captionator.

随意挑选除了开发分支的源代码(它具有最佳的WebVTT兼容性,所以最好看一下它而不是稳定的分支。)

Feel free to pick apart the source of the development branch (which has the best WebVTT compliance, so it's probably better to look at that rather than the stable branch.)

解析器代码从这里开始:
https://github.com/cgiffard/ Captionator / blob / captioncrunch / js / captionator.js#L1686

The parser code starts here: https://github.com/cgiffard/Captionator/blob/captioncrunch/js/captionator.js#L1686

最终,您所描述的内容似乎大致符合预期的用例元数据跟踪类型(如 WHATWG的TimedTextTrack规范。)你可以使用Captionator (我也很乐意向你推荐另一个图书馆,但是我'我不知道其他任何未与整个视频播放器捆绑在一起,或者实现你需要的TimedTextTrack JS API 来提供支持rt for it - TextTrack.oncuechange 事件和 TextTrack.activeCues 列表使您能够在监听时监听对提示的更改用户在视频时间轴内寻找。然后,您可以获取每个提示的文本(减去提示元数据和标题)并将其解析为JSON。只需设置如下所示的字幕轨道:

Ultimately though, what you're describing seems to roughly match the intended use case for the metadata track type (as described in the WHATWG's TimedTextTrack spec.) You can use Captionator (I'd love to recommend to you another library as well, but I'm not aware of anything else that doesn't come bundled with an entire video player, or that implements the TimedTextTrack JS API you'll need) to provide support for it - the TextTrack.oncuechange event and TextTrack.activeCues list enable you to listen for changes to cues when the user seeks within the video timeline. You can then get the text of each cue (less the cue metadata and header) and parse it as JSON. Just set up a caption track like below:

<video src="myvideo.webm" poster="poster.jpg" width="512" height="288">
    <track kind="metadata" src="meta.webvtt" type="text/webvtt" srclang="en" label="Metadata Track" default />
</video>

然后,包括captionator库,根据文档,选择您的曲目并设置一个事件处理程序。您可以像这样访问单个提示的文本:

Then, include the captionator library, initialise it as per the documentation, select your track and set up an event handler. You can access the text of an individual cue like so:

var cueText = document.getElementById("video").tracks[0].activeCues[0].getCueAsSource();

然后只需:

var RDFData = JSON.parse(cueText);

祝你好运:)

这篇关于来自WEBVTT的RDF / JSON的Javascript解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆