-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
113 lines (90 loc) · 2.91 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
warning = FALSE,
message = FALSE,
error = FALSE,
comment = "#>",
fig.path = "man/figures/README-",
fig.height = 4,
fig.width = 9,
out.width = "100%",
dpi = 300
)
if (!interactive()) {
options(width = 95)
}
```
# srt <img src='man/figures/logo.png' align="right" height="139" />
<!-- badges: start -->
[![Lifecycle: experimental][life_badge]][life_link]
[![CRAN status][cran_badge]][cran_link]
![Downloads][dl_badge]
[![Codecov test coverage][cov_badge]][cov_link]
[![R build status][ga_badge]][ga_link]
<!-- badges: end -->
The goal of srt is to read [SubRip][wiki] text files as tabular data for easy
analysis and manipulation.
## Installation
You can install the development version of srt from [GitHub][gh] with:
```{r install, eval=FALSE}
# install.packages("remotes")
remotes::install_github("k5cents/srt")
```
## Example
The `.srt` standard is used to identify the subtitle components for the columns
of a data frame:
1. A numeric counter identifying each sequential subtitle
2. The time that the subtitle should appear followed by `-->` and the time it
should disappear
3. Subtitle text itself on one or more lines
4. A blank line containing no text, indicating the end of this subtitle
```{r library}
library(srt)
library(tidyverse)
library(tidytext)
srt <- srt_example()
```
```{r lines, echo=FALSE}
cat(readLines(srt, n = 11), sep = "\n")
```
These subtitle files are parsed as data frames with separate columns.
```{r tabular}
(wonderful_life <- read_srt(path = srt, collapse = " "))
```
This makes it easy to perform various text analysis on the subtitles.
```{r analysis}
wonderful_life %>%
unnest_tokens(word, subtitle) %>%
count(word, sort = TRUE) %>%
anti_join(stop_words)
```
Or uniformly manipulate the _numeric_ time stamps:
```{r shift}
wonderful_life <- srt_shift(wonderful_life, seconds = 9.99)
```
The subtitle data frames can be easily re-written as valid SubRip files.
```{r write}
tmp <- tempfile(fileext = ".srt")
write_srt(wonderful_life, tmp, wrap = FALSE)
```
```{r post, echo=FALSE}
cat(readLines(tmp, n = 11), sep = "\n")
```
<!-- refs: start -->
[life_badge]: https://img.shields.io/badge/lifecycle-experimental-orange.svg
[life_link]: https://lifecycle.r-lib.org/articles/stages.html
[cran_badge]: https://www.r-pkg.org/badges/version/srt
[cran_link]: https://CRAN.R-project.org/package=srt
[dl_badge]: https://cranlogs.r-pkg.org/badges/grand-total/srt
[ga_badge]: https://github.com/k5cents/srt/workflows/R-CMD-check/badge.svg
[ga_link]: https://github.com/k5cents/srt/actions
[cov_badge]: https://codecov.io/gh/k5cents/srt/graph/badge.svg?token=CMz6DIxJdH
[cov_link]: https://app.codecov.io/gh/k5cents/srt?branch=master
[gh]: https://github.com/k5cents/srt
[wiki]: https://en.wikipedia.org/wiki/SubRip
<!-- refs: end -->