diff --git a/README.md b/README.md index 04272adc3ce131222f4357ab65eefe1dcc13e182..59e26959970fd004725b2f7b0e327a50187d2279 100644 --- a/README.md +++ b/README.md @@ -1,100 +1,105 @@ -[//]: # "#to make links in gitlab: example with racon https://github.com/isovic/racon" -[//]: # "tricks in markdown: https://openclassrooms.com/fr/courses/1304236-redigez-en-markdown" - -| usage | R dependencies | -| --- | --- | -| [](https://cran.r-project.org/mirrors.html) | [](https://cran.r-project.org/mirrors.html) | -| [-green?style=plastic)](https://www.gnu.org/licenses) | [](https://cran.r-project.org/web/packages/car/index.html) | - - - -## TABLE OF CONTENTS - - - [AIM](#aim) - - [CONTENT](#content) - - [HOW TO RUN](#how-to-run) - - [OUTPUT](#output) - - [VERSIONS](#versions) - - [LICENCE](#licence) - - [CITATION](#citation) - - [CREDITS](#credits) - - [WHAT'S NEW IN](#what's-new-in) - - -## AIM - -Shift the time of .srt subtitle files - - -## CONTENT - -**sub_shift.R** file that can be executed using a CLI (command line interface) or sourced in R or RStudio. - -**dataset** folder containing some datasets than can be used as examples (from https://en.wikipedia.org/wiki/SubRip) - -**example_of_result** folder containing an example of result obtained with the Internatilzation dataset - - -## HOW TO RUN - -### Using a R GUI (graphic user interface, i.e., R or RStudio windows) - -1) Open the sub_shift.R file and set the parameters (2 first lines) - -2) Open R or RStudio - -3) Source the anova_contrasts.R file, for instance using the following instruction: - - ` source("C:/Users/Gael/Desktop/sub_shift.R") ` - - -### Using a R CLI (command line interface) - -1) Open the sub_shift.R file and set the parameters (2 first lines) - -2) Open a shell windows - -3) run sub_shift.R, for instance using the following instruction: - - ` Rscript sub_shift.R ` - -For cygwin, use something like: - -` /cygdrive/c/Program\ Files/R/R-4.0.2/bin/Rscript sub_shift.R ` - - -## OUTPUT - -The same file in the same directory but with time shifted - - -## VERSIONS - -The different releases are tagged [here](https://gitlab.pasteur.fr/gmillot/sub_shift/-/tags) - - -## LICENCE - -This package of scripts can be redistributed and/or modified under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -Distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchandability or fitness for a particular purpose. -See the GNU General Public License for more details at https://www.gnu.org/licenses. - - -## CITATION - -Not yet published - - -## CREDITS - -[Gael A. Millot](https://gitlab.pasteur.fr/gmillot), Hub-CBD, Institut Pasteur, USR 3756 IP CNRS, Paris, France - - -## WHAT'S NEW IN - -### v1.0.0 - -Everything - - - +[//]: # "#to make links in gitlab: example with racon https://github.com/isovic/racon" +[//]: # "tricks in markdown: https://openclassrooms.com/fr/courses/1304236-redigez-en-markdown" + +| usage | R dependencies | +| --- | --- | +| [](https://cran.r-project.org/mirrors.html) | [](https://cran.r-project.org/mirrors.html) | +| [-green?style=plastic)](https://www.gnu.org/licenses) | [](https://cran.r-project.org/web/packages/car/index.html) | + + + +## TABLE OF CONTENTS + + - [AIM](#aim) + - [CONTENT](#content) + - [HOW TO RUN](#how-to-run) + - [OUTPUT](#output) + - [VERSIONS](#versions) + - [LICENCE](#licence) + - [CITATION](#citation) + - [CREDITS](#credits) + - [WHAT'S NEW IN](#what's-new-in) + + +## AIM + +Shift the time of .srt subtitle files + + +## CONTENT + +**subtitle_time_shift.R** file that can be executed using a CLI (command line interface) or sourced in R or RStudio. + +**dataset** folder containing some datasets than can be used as examples (from https://en.wikipedia.org/wiki/SubRip) + +**example_of_result** folder containing an example of result obtained + + +## HOW TO RUN + +### Using a R GUI (graphic user interface, i.e., R or RStudio windows) + +1) Open the subtitle_time_shift.R file and set the parameters (2 first lines) + +2) Open R or RStudio + +3) Source the subtitle_time_shift.R file, for instance using the following instruction: + + ` source("C:/Users/Gael/Desktop/subtitle_time_shift.R") ` + + +### Using a R CLI (command line interface) + +1) Open the subtitle_time_shift.R file and set the parameters (2 first lines) + +2) Open a shell windows + +3) run subtitle_time_shift.R, for instance using the following instruction: + + ` Rscript subtitle_time_shift.R ` + +For cygwin, use something like: + + ` /cygdrive/c/Program\ Files/R/R-4.0.2/bin/Rscript subtitle_time_shift.R ` + + +## OUTPUT + +The same file in the same directory but with time shifted + + +## VERSIONS + +The different releases are tagged [here](https://gitlab.pasteur.fr/gmillot/sub_shift/-/tags) + + +## LICENCE + +This package of scripts can be redistributed and/or modified under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +Distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchandability or fitness for a particular purpose. +See the GNU General Public License for more details at https://www.gnu.org/licenses. + + +## CITATION + +Not yet published + + +## CREDITS + +[Gael A. Millot](https://gitlab.pasteur.fr/gmillot), Hub-CBD, Institut Pasteur, USR 3756 IP CNRS, Paris, France + + +## WHAT'S NEW IN + +### v1.1 + +README file improved. + + +### v1.0 + +Everything. + + + diff --git a/dataset/movie.srt b/dataset/movie.srt index fd418dba2760ffce1382cfdf05c39bfe7493d7f0..ec7288aeea3689b057bd5a3d2463bbbb1be61db3 100644 --- a/dataset/movie.srt +++ b/dataset/movie.srt @@ -1,20 +1,20 @@ -1 -00:02:16,612 --> 00:02:19,376 -Senator, we're making -our final approach into Coruscant. - -2 -00:02:19,482 --> 00:02:21,609 -Very good, Lieutenant. - -3 -00:03:13,336 --> 00:03:15,167 -We made it. - -4 -00:03:18,608 --> 00:03:20,371 -I guess I was wrong. - -5 -00:03:20,476 --> 00:03:22,671 +1 +00:02:16,612 --> 00:02:19,376 +Senator, we're making +our final approach into Coruscant. + +2 +00:02:19,482 --> 00:02:21,609 +Very good, Lieutenant. + +3 +00:03:13,336 --> 00:03:15,167 +We made it. + +4 +00:03:18,608 --> 00:03:20,371 +I guess I was wrong. + +5 +00:03:20,476 --> 00:03:22,671 There was no danger at all. \ No newline at end of file diff --git a/example_of_results/movie_shift.srt b/example_of_results/movie_shift.srt index 850a4c9fca8648b31cb09cecb7eed3ded4af087d..ee5eeb3348c4656c9bd53cd6f679ba39759e6de1 100644 --- a/example_of_results/movie_shift.srt +++ b/example_of_results/movie_shift.srt @@ -1,20 +1,20 @@ -1 -00:02:15,612 --> 00:02:18,376 -Senator, we're making -our final approach into Coruscant. - -2 -00:02:18,482 --> 00:02:20,609 -Very good, Lieutenant. - -3 -00:03:12,336 --> 00:03:14,167 -We made it. - -4 -00:03:17,608 --> 00:03:19,371 -I guess I was wrong. - -5 -00:03:19,476 --> 00:03:21,671 -There was no danger at all. +1 +00:02:15,612 --> 00:02:18,376 +Senator, we're making +our final approach into Coruscant. + +2 +00:02:18,482 --> 00:02:20,609 +Very good, Lieutenant. + +3 +00:03:12,336 --> 00:03:14,167 +We made it. + +4 +00:03:17,608 --> 00:03:19,371 +I guess I was wrong. + +5 +00:03:19,476 --> 00:03:21,671 +There was no danger at all. diff --git a/subtitle_time_shift.R b/subtitle_time_shift.R index 003236b87fdac29ac4e40b4e30167009b1c8295b..dd03f7a58fc1e157ddbfdcd6870e26d9123b7820 100644 --- a/subtitle_time_shift.R +++ b/subtitle_time_shift.R @@ -1,21 +1,21 @@ - -shift <- -1 # in seconds -in.path <- "C:/Users/Gael/Documents/Git_projects/subtitle_time_shift/dataset/movie.srt" # absolute path of the input file - - -a <- read.table(in.path, sep = "\t", check.names = FALSE, quote = "", comment.char = "", blank.lines.skip = FALSE) -out.path <- paste0(sub(x = in.path, pattern = "\\.srt$", replacement = ""), "_shift.srt") -tempo.log <- grepl(x = a[, 1], pattern = "-->") -b <- a[tempo.log, ] -d <- strsplit(x = b, split = " --> ") # "01:00:15,602" -e <- lapply(X = d, FUN = function(x = X){ - x <- lubridate::period_to_seconds(lubridate::hms(x) + lubridate::seconds(shift)) # hms(x) convert into hms object and lubridate::hms(x) + lubridate::seconds(shift) shifts the time and lubridate::period_to_seconds() convert to seconds - x <- as.character(hms::as_hms(x)) # "01:00:17.102" - sub(x = x, pattern = "\\.", replacement = ",") -}) -f <- a -f[tempo.log, ] <- sapply(X = e, FUN = function(x = X){paste0(x, collapse = " --> ")}) -write.table(f, file = out.path, row.names = FALSE, col.names = FALSE, append = FALSE, quote = FALSE, sep = "\t") - - - + +shift <- -1 # in seconds +in.path <- "C:/Users/Gael/Documents/Git_projects/subtitle_time_shift/dataset/movie.srt" # absolute path of the input file + + +a <- read.table(in.path, sep = "\t", check.names = FALSE, quote = "", comment.char = "", blank.lines.skip = FALSE) +out.path <- paste0(sub(x = in.path, pattern = "\\.srt$", replacement = ""), "_shift.srt") +tempo.log <- grepl(x = a[, 1], pattern = "-->") +b <- a[tempo.log, ] +d <- strsplit(x = b, split = " --> ") # "01:00:15,602" +e <- lapply(X = d, FUN = function(x = X){ + x <- lubridate::period_to_seconds(lubridate::hms(x) + lubridate::seconds(shift)) # hms(x) convert into hms object and lubridate::hms(x) + lubridate::seconds(shift) shifts the time and lubridate::period_to_seconds() convert to seconds + x <- as.character(hms::as_hms(x)) # "01:00:17.102" + sub(x = x, pattern = "\\.", replacement = ",") +}) +f <- a +f[tempo.log, ] <- sapply(X = e, FUN = function(x = X){paste0(x, collapse = " --> ")}) +write.table(f, file = out.path, row.names = FALSE, col.names = FALSE, append = FALSE, quote = FALSE, sep = "\t") + + +