README.md

Introduction to SRTtools

CRAN_Status_Badge CRAN_Status_Badge

SRTtools is a R package that can simply adjst subtitles time, style and position for srt file.

Package Setup

install.packages("SRTtools")
library(SRTtools)

Examples

Read srt file

srt_path <- system.file("extdata", "movie.srt", package="SRTtools")
srt <- srt.read(srt_path)
> srt
   [1] "1"                                                   "00:00:25,525 --> 00:00:29,904"                      
   [3] "<i>This is the Asgardian"                            "refugee vessel </i>Statesman<i>.</i>"               
   [5] ""                                                    "2"                                                  
   [7] "00:00:32,657 --> 00:00:36,119"                       "<i>We are under assault."                           

Postpone subtitles 0.5 seconds later

srt_later <- srt.shift(srt, time_shifted = 0.5)
> srt_later
   [1] "1"                                                   "00:00:26,025 --> 00:00:30,404"                      
   [3] "<i>This is the Asgardian"                            "refugee vessel </i>Statesman<i>.</i>"               
   [5] ""                                                    "2"                                                  
   [7] "00:00:33,157 --> 00:00:36,618"                       "<i>We are under assault."                           

Expedite subtitles 0.5 seconds earlier

srt_earlier <- srt.shift(srt, time_shifted = -0.5)
> srt_earlier
   [1] "1"                                                   "00:00:25,025 --> 00:00:29,404"                      
   [3] "<i>This is the Asgardian"                            "refugee vessel </i>Statesman<i>.</i>"               
   [5] ""                                                    "2"                                                  
   [7] "00:00:32,157 --> 00:00:35,618"                       "<i>We are under assault."                           

Save as 'movie_new.srt' file

srt.write(srt_earlier, filename = "movie_new.srt")

Retrieve subtitle content only

> srt.content(srt)
   [1] "<i>This is the Asgardian"                            "refugee vessel </i>Statesman<i>.</i>"               
   [3] "<i>We are under assault."                            "I repeat, we are under assault.</i>"                
   [5] "<i>The engines are dead, life support failing.</i>"  "<i>Requesting aid from any vessel within range.</i>"
   [7] "<i>We are 22 jump points out of Asgard.</i>"         "<i>Our crew is made up of Asgardian families."  

Change color and position of subtitles which contains 'Wow'

> srt.style(srt, line = srt.search(srt,"Wow"), pos = 'middle-center', style = c('b','i'), col = 'red')
 [418] "791"                                                                              
 [419] "01:00:28,545 --> 01:00:29,379"                                                    
 [420] "the stone."                                                                       
 [421] ""                                                                                 
 [422] "792"                                                                              
 [423] "01:00:41,975 --> 01:00:44,394"                                                    
 [424] "{\\an5}<b><i><font color='red'>Wow, you're a seriously loyal piece</b></i></font>"
 [425] "{\\an5}<b><i><font color='red'>of outerwear, aren't you?</b></i></font>"          
 [426] ""                                                                                 
 [427] "793"                                                                              
 [428] "01:00:44,561 --> 01:00:46,563"                                                    
 [429] "Yeah, speaking of loyalty..."    

Insert a new dialog as the first dialog

> srt.insert(srt, index = 1, time = "00:00:00,000 --> 00:00:30,000", text = "Added by SRTtools!")
   [1] "1"                                                             "00:00:00,000 --> 00:00:30,000"                                
   [3] "Added by SRTtools!"                                             ""                                                             
   [5] "2"                                                             "00:00:26,360 --> 00:00:28,192"                                
   [7] "This is the Asgardian"                                         ""                                                             
   [9] "3"                                                             "00:00:28,278 --> 00:00:30,736"                                
   [11] "refugee vessel Statesman."                                     ""                                                             

Remove the second dialog

> srt
   [1] "1"                               "00:00:26,360 --> 00:00:28,192"   "This is the Asgardian"           ""                               
   [5] "2"                               "00:00:28,278 --> 00:00:30,736"   "refugee vessel Statesman."       ""                               
   [9] "3"                               "00:00:33,492 --> 00:00:34,778"   "We are under assault."           ""                               
   [13] "4"                               "00:00:34,868 --> 00:00:36,951"   "I repeat, we are under assault."
> srt.remove(srt, index = 2)
   [1] "1"                               "00:00:26,360 --> 00:00:28,192"   "This is the Asgardian"           ""                     
   [5] "2"                               "00:00:33,492 --> 00:00:34,778"   "We are under assault."           ""            
   [9] "3"                               "00:00:34,868 --> 00:00:36,951"   "I repeat, we are under assault." ""                                

Image

Developers

Dependencies

It is highly recommended that you use the RStudio IDE to develop this package. In addition to an R installation, you'll also need to install Rtools and a TeX distribution. TeX Live is a comprehensive distribution that seems to work well.

Once you have cloned this repository, you'll need to download the build package dependencies. These dependencies are managed with packrat and can be restored by running

if (!require(packrat)) install.packages("packrat")
packrat::on()
packrat::restore()

Documentation

The roxygen2 R package is used to manage SRTtools's documentation. Do not edit any of the files that have a warning comment at the top about manually editing those files!

You can regenerate package documentation with the RStudio shortcut Ctrl+Shift+Enter, or by running

roxygen2::roxygenize()

The project is set up to do this whenever building and testing the package.

Other



ChiHangChen/SRTtools documentation built on July 20, 2019, 3:50 p.m.