2017 © Pedro Peláez
 

project srt-parser

Easily Parse SRT Subtitle Files

image

benlipp/srt-parser

Easily Parse SRT Subtitle Files

  • Saturday, June 24, 2017
  • by benlipp
  • Repository
  • 1 Watchers
  • 3 Stars
  • 488 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 7 Versions
  • 84 % Grown

The README.md

SRT Parser

Build Status, (*1)

A PHP library to parse SRT files.
Built by Ben Lippincott for LiveTech, (*2)

Installation / Requirements

Run composer require "benlipp/srt-parser" and let Composer do the work., (*3)

PHP 7+ is REQUIRED! This isn't amateur hour., (*4)

Usage

Import the Parser class: use Benlipp\SrtParser\Parser;, (*5)

Use it:, (*6)

$parser = new Parser();

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

$captions = $parser->parse();

or, (*7)

$parser = new Parser();

$parser->loadString($formatted_caption_input);

$captions = $parser->parse();

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

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., (*9)

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:, (*10)

$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:, (*11)

$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., (*12)

The Versions

24/06 2017

dev-master

9999999-dev

Easily Parse SRT Subtitle Files

  Sources   Download

dbad

The Requires

  • php >=7.0

 

The Development Requires

by Ben Lippincott

parser subtitles srt

24/06 2017

v1.1.1

1.1.1.0

Easily Parse SRT Subtitle Files

  Sources   Download

dbad

The Requires

  • php >=7.0

 

The Development Requires

by Ben Lippincott

parser subtitles srt

20/04 2017

dev-benlipp-patch-1

dev-benlipp-patch-1

Easily Parse SRT Subtitle Files

  Sources   Download

dbad

The Requires

  • php >=7.0

 

The Development Requires

by Ben Lippincott

parser subtitles srt

02/04 2017

v1.1.0

1.1.0.0

Easily Parse SRT Subtitle Files

  Sources   Download

dbad

The Requires

  • php >=7.0

 

The Development Requires

by Ben Lippincott

parser subtitles srt

30/03 2017

v1.0.2

1.0.2.0

Easily Parse SRT Subtitle Files

  Sources   Download

dbad

The Requires

  • php >=7.0

 

The Development Requires

by Ben Lippincott

parser subtitles srt

29/03 2017

v1.0.1

1.0.1.0

Easily Parse SRT Subtitle Files

  Sources   Download

dbad

The Requires

  • php >=7.0

 

The Development Requires

by Ben Lippincott

parser subtitles srt

29/03 2017

v1.0.0

1.0.0.0

Easily Parse SRT Subtitle Files

  Sources   Download

dbad

The Requires

  • php >=7.0

 

The Development Requires

by Ben Lippincott

template composer package