承接 benlipp/srt-parser 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

benlipp/srt-parser

最新稳定版本:v1.1.1

Composer 安装命令:

composer create-project benlipp/srt-parser

包简介

Easily Parse SRT Subtitle Files

README 文档

README

Build Status

A PHP library to parse SRT files.
Built by Ben Lippincott for LiveTech

Installation / Requirements

Run composer require "benlipp/srt-parser" and let Composer do the work.

PHP 7+ is REQUIRED! This isn't amateur hour.

Usage

Import the Parser class: use Benlipp\SrtParser\Parser;

Use it:

$parser = new Parser();

$parser->loadFile('/path/to/srtfile.srt');

$captions = $parser->parse();

or

$parser = new Parser();

$parser->loadString($formatted_caption_input);

$captions = $parser->parse();

parse() returns an array of captions. Use them like so:

foreach($captions as $caption){
    echo "Start Time: " . $caption->startTime;
    echo "End Time: " . $caption->endTime;
    echo "Text: " . $caption->text;
}

A caption can be returned as an array instead of an object, if you prefer. The array is snake_case for compatibility with Laravel's attributes.

foreach($captions as $caption){
    $caption = $caption->toArray();
    echo "Start Time: " . $caption['start_time'];
    echo "End Time: " . $caption['end_time'];
    echo "Text: " . $caption['text'];
}

For Laravel usage with a model:

$url = "https://youtu.be/dQw4w9WgXcQ";
$video = new Video($url);
foreach ($captions as $caption) {
    $data = new VideoMetadata($caption->toArray());
    $video->videoMetadata()->save($data);
}

You can also chain the parse() method:

$parser = new Parser();
$captions = $parser->loadFile($srtPath)->parse();

Contributing

Run PHPUnit on your changes, pretty please. If you add a new feature, add tests for that feature.

统计信息

  • 总下载量: 113.55k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 22
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 22
  • Watchers: 2
  • Forks: 14
  • 开发语言: PHP

其他信息

  • 授权协议: DBAD
  • 更新时间: 2017-03-29