<commit_before># SRT [![Build Status](https://travis-ci.org/cpetersen/srt.png?branch=master)](https://travis-ci.org/cpetersen/srt)

SRT stands for SubRip text file format, which is a file for storing subtitles. This is a Ruby library for manipulating SRT files. 

## Installation

Add this line to your application's Gemfile:

    gem 'srt'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install srt

## Usage

You can parse an SRT file with the following code:

```ruby
  file = SRT::File.parse(File.new("MY_SRT_FILENAME.srt"))
  file.lines.each do |line|
    puts line.text.join(" ")
  end
```

`timeshift` offers multiple ways to fix subtitle synchronization issues

# timeshift(instructions)
#
# constantly shift all subtitles
# e.g. { :all => "-3.4s" }
#      { :all => "1.5m" }
#      { :all => "+700mil" }
#
# framerate conversion
# e.g. { "25fps" => "23.99999fps" }
# note: this implements a naive approach of what framerate conversion does or should do;
#       it probably won't statisfy what video professionals expect - but it's a start :)    
#
# linear progressive timeshift
# e.g. { 12 => "+10s", 569 => "+2.34m" }
#      { 23 => "00:02:12,400", 843 => "01:38:06,000" }
#      { "00:01:10,000" => "55s", "01:33:07,200" => "2.3m" } 
#      { "00:01:10,000" => "00:02:12,400", "01:33:07,200" => "01:38:06,000" }
#      { 57 => "00:02:12,400", "01:33:07,200" => "+13s" }

```ruby
  file.timeshift({ :all => "-2.5s" }) # resynchronize subtitles so they show up 2.5 seconds earlier 
```

`linear_progressive_timeshift` allows progressive timeshifting, e.g. to account for time-drift  
caused by subtitles that were created for a video version with a different framerate:

```ruby
  file.linear_progressive_timeshift(60, 70, 2700, 2760) 
 ```

This applies a timeshift of 10 seconds at minute #1 (60 => 70),  
then progressively more towards a 60 second shift by minute #45 (2700 => 2760)


## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request<commit_msg>Properly integrate new timeshift API into readme<commit_after># SRT [![Build Status](https://travis-ci.org/cpetersen/srt.png?branch=master)](https://travis-ci.org/cpetersen/srt)

SRT stands for SubRip text file format, which is a file for storing subtitles. This is a Ruby library for manipulating SRT files. 

## Installation

Add this line to your application's Gemfile:

    gem 'srt'

And then execute:

    $ bundle
    
Or install it yourself as:

    $ gem install srt

## Usage

You can parse an SRT file with the following code:

```ruby
  file = SRT::File.parse(File.new("MY_SRT_FILENAME.srt"))
  file.lines.each do |line|
    puts line.text.join(" ")
  end
```

`timeshift` offers multiple ways to fix subtitle synchronization issues;  

Pass it a hash of the form `:all => "[+/-][amount][h|m|s|mil]"` for a constant shift:

```ruby
  # Shift all subtitles so they show up ...
  file.timeshift({ :all => "-2.5s" }) # 2.5 seconds earlier
  file.timeshift({ :all => "1.5m" }) # 1.5 minutes later  
  file.timeshift({ :all => "+700mil" }) # 700 milliseconds later    
```
Pass it a hash of the form `"[old]fps" => "[new]fps"` for a framerate based shift:

```ruby
  file.timeshift({ "25fps" => "23.976fps" }) # scale timecodes from 25fps to 23.976fps
```
Pass it a hash in any of the following forms for a linear progressive shift , e.g. to account for time-drift caused by subtitles that were created for a video version with a different framerate:

```ruby
  file.timeshift({ 12 => "+10s", 569 => "+2.34m" })
  file.timeshift({ 23 => "00:02:12,400", 843 => "01:38:06,000" }) 
  file.timeshift({ "00:01:10,000" => "55s", "01:33:07,200" => "2.3m" })
  file.timeshift({ "00:01:10,000" => "00:02:12,400", "01:33:07,200" => "01:38:06,000" })
  file.timeshift({ 57 => "00:02:12,400", "01:33:07,200" => "+13s" })
```

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
{'fraction_non_alphanumeric': 0.153918791312559, 'fraction_numerical': 0.07436260623229461, 'mean_word_length': 3.7984144960362403, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 36, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2574388', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1484, 'n_words': 491}