Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions R/utils_regexes.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@
return(x)
}

#' Extract season number from file paths
#'
#' Parses the file name component of each path and attempts to detect the season
#' number using four common naming conventions:
#' \code{S01}, \code{SEASON.2}, \code{S03E05}, and \code{2X05}.
#' Returns \code{NA} for paths where no convention matches.
#'
#' @param x a character vector of file or directory paths.
#'
#' @returns A numeric vector of season numbers, the same length as \code{x}.
#'
#' @noRd
# Guess subtitle format from subtitle content when no file extension is
# available, e.g. when parsing literal text.
.guess_subtitle_format <- function(x) {
Expand Down
8 changes: 2 additions & 6 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (coverage >= 90) {

[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![R-CMD-check](https://github.com/fkeck/subtools/actions/workflows/check-standard.yml/badge.svg)](https://github.com/fkeck/subtools/actions/workflows/check-standard.yml)
[![Code Coverage: `r coverage`%](https://img.shields.io/badge/code_coverage-`r coverage`%25-`r colour`)](https://img.shields.io/badge/code_coverage-`r coverage`%25-`r colour`)
![Code Coverage: `r coverage`%](https://img.shields.io/badge/code_coverage-`r coverage`%25-`r colour`)

### Read, write and manipulate subtitles in R

Expand All @@ -48,11 +48,7 @@ Subtools is a R package to read, write and manipulate subtitles in R. This then
### Install
You can install the package directly from CRAN with `install.packages("subtools")` or get the latest, in development, version with:
```{r, eval = FALSE}
remotes::install_github(
repo = "fkeck/subtools@dev",
build_manual = TRUE,
build_vignettes = TRUE
)
pak::pkg_install("fkeck/subtools@dev")
```

```{r}
Expand Down
74 changes: 54 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
state and is being actively
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![R-CMD-check](https://github.com/fkeck/subtools/actions/workflows/check-standard.yml/badge.svg)](https://github.com/fkeck/subtools/actions/workflows/check-standard.yml)
[![Code Coverage:
82%](https://img.shields.io/badge/code_coverage-82%25-green)](https://img.shields.io/badge/code_coverage-82%25-green)
![Code Coverage:
82%](https://img.shields.io/badge/code_coverage-82%25-green)

### Read, write and manipulate subtitles in R

Expand All @@ -30,11 +30,7 @@ You can install the package directly from CRAN with
version with:

``` r
remotes::install_github(
repo = "fkeck/subtools@dev",
build_manual = TRUE,
build_vignettes = TRUE
)
pak::pkg_install("fkeck/subtools@dev")
```

``` r
Expand Down Expand Up @@ -242,18 +238,56 @@ rushmore_sub
unnest_tokens(rushmore_sub)
#> # A tibble: 49 × 4
#> ID Timecode_in Timecode_out Text_content
#> <chr> <time> <time> <chr>
#> 1 180 20'40.9700" 20'41.4858" rushmore
#> 2 180 20'41.4868" 20'42.0026" deserves
#> 3 180 20'42.0036" 20'42.1318" an
#> 4 180 20'42.1328" 20'42.6486" aquarium
#> 5 180 20'42.6496" 20'42.7132" a
#> 6 180 20'42.7142" 20'43.0363" first
#> 7 180 20'43.0373" 20'43.3593" class
#> 8 180 20'43.3603" 20'43.8761" aquarium
#> 9 180 20'43.8771" 20'44.1991" where
#> 10 180 20'44.2001" 20'44.8451" scientists
#> # ℹ 39 more rows
#> <chr> <time> <time> <chr>
#> 1 180 20'40.9700" 20'41.4858" rushmore
#> 2 180 20'41.4868" 20'42.0026" deserves
#> 3 180 20'42.0036" 20'42.1318" an
#> 4 180 20'42.1328" 20'42.6486" aquarium
#> 5 180 20'42.6496" 20'42.7132" a
#> 6 180 20'42.7142" 20'43.0363" first
#> 7 180 20'43.0373" 20'43.3593" class
#> 8 180 20'43.3603" 20'43.8761" aquarium
#> 9 180 20'43.8771" 20'44.1991" where
#> 10 180 20'44.2001" 20'44.8451" scientists
#> 11 180 20'44.8461" 20'45.0389" can
#> 12 180 20'45.0399" 20'45.4911" lecture
#> 13 180 20'45.4921" 20'45.6849" and
#> 14 180 20'45.6859" 20'46.2017" students
#> 15 180 20'46.2027" 20'46.3955" can
#> 16 180 20'46.3965" 20'46.8478" observe
#> 17 180 20'46.8488" 20'47.2354" marine
#> 18 180 20'47.2364" 20'47.4938" life
#> 19 180 20'47.4948" 20'47.6230" in
#> 20 180 20'47.6240" 20'47.8168" its
#> 21 180 20'47.8178" 20'48.2690" natural
#> 22 181 20'48.2700" 20'48.3393" i
#> 23 181 20'48.3403" 20'48.6908" don't
#> 24 181 20'48.6918" 20'48.9720" know
#> 25 181 20'48.9730" 20'49.2532" what
#> 26 181 20'49.2542" 20'49.3938" do
#> 27 181 20'49.3948" 20'49.6046" you
#> 28 181 20'49.6056" 20'49.9561" think
#> 29 181 20'49.9571" 20'50.3076" ernie
#> 30 181 20'50.3086" 20'50.8700" aquarium
#> 31 182 20'50.9470" 20'51.4402" what
#> 32 182 20'51.4412" 20'51.9343" kind
#> 33 182 20'51.9353" 20'52.1814" of
#> 34 182 20'52.1824" 20'52.6755" fish
#> 35 182 20'52.6765" 20'53.9109" barracudas
#> 36 182 20'53.9119" 20'55.0228" stingrays
#> 37 182 20'55.0238" 20'56.3817" hammerheads
#> 38 182 20'56.3827" 20'57.3700" piranhas
#> 39 183 20'58.0520" 20'58.6840" piranhas
#> 40 183 20'58.6850" 20'59.1588" really
#> 41 183 20'59.1598" 20'59.3962" yes
#> 42 183 20'59.3972" 20'59.6336" i'm
#> 43 183 20'59.6346" 21'00.1874" talking
#> 44 183 21'00.1884" 21'00.3457" to
#> 45 183 21'00.3467" 21'00.4248" a
#> 46 183 21'00.4258" 21'00.6622" guy
#> 47 183 21'00.6632" 21'00.8205" in
#> 48 183 21'00.8215" 21'01.2161" south
#> 49 183 21'01.2171" 21'01.7700" america

unnest_tokens(bb_sub_clean, token = "sentences")
#> # A tibble: 8 × 7
Expand Down Expand Up @@ -286,7 +320,7 @@ Note that these project used the branch 0.x of `subtools`. The API is
totally different from `subtools 1.0`.

[*You beautiful, naïve, sophisticated newborn
series*](https://www.masalmon.eu/2017/11/05/newborn-serie/) by
series*](https://masalmon.eu/2017/11/05/newborn-serie/) by
[ma_salmon](https://x.com/ma_salmon)

[*A tidy text analysis of Rick and
Expand Down
51 changes: 38 additions & 13 deletions tests/testthat/_snaps/unnest_tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,42 @@
unnest_tokens(tbl = s)
Output
# A tibble: 36 x 5
ID Timecode_in Timecode_out Text_content test
<chr> <time> <time> <chr> <chr>
1 1 00'01.0010" 00'01.6250" never Test
2 1 00'01.6260" 00'02.2500" drink Test
3 1 00'02.2510" 00'03.0000" liquid Test
4 1 00'03.0010" 00'04.0000" nitrogen Test
5 2 00'05.0010" 00'05.2162" it Test
6 2 00'05.2172" 00'05.6486" will Test
7 2 00'05.6496" 00'06.6216" perforate Test
8 2 00'06.6226" 00'07.0541" your Test
9 2 00'07.0551" 00'07.8108" stomach Test
10 2 00'07.8118" 00'08.1351" you Test
# i 26 more rows
ID Timecode_in Timecode_out Text_content test
<chr> <time> <time> <chr> <chr>
1 1 00'01.0010" 00'01.6250" never Test
2 1 00'01.6260" 00'02.2500" drink Test
3 1 00'02.2510" 00'03.0000" liquid Test
4 1 00'03.0010" 00'04.0000" nitrogen Test
5 2 00'05.0010" 00'05.2162" it Test
6 2 00'05.2172" 00'05.6486" will Test
7 2 00'05.6496" 00'06.6216" perforate Test
8 2 00'06.6226" 00'07.0541" your Test
9 2 00'07.0551" 00'07.8108" stomach Test
10 2 00'07.8118" 00'08.1351" you Test
11 2 00'08.1361" 00'08.6757" could Test
12 2 00'08.6767" 00'09.0000" die Test
13 A dangerous cue 00'11.0010" 00'11.0989" dès Test
14 A dangerous cue 00'11.0999" 00'11.2308" noël Test
15 A dangerous cue 00'11.2318" 00'11.2967" où Test
16 A dangerous cue 00'11.2977" 00'11.3626" un Test
17 A dangerous cue 00'11.3636" 00'11.5604" zéphyr Test
18 A dangerous cue 00'11.5614" 00'11.6593" haï Test
19 A dangerous cue 00'11.6603" 00'11.7253" me Test
20 A dangerous cue 00'11.7263" 00'11.8242" vêt Test
21 A dangerous cue 00'11.8252" 00'11.8901" de Test
22 A dangerous cue 00'11.8911" 00'12.1209" glaçons Test
23 A dangerous cue 00'12.1219" 00'12.3846" würmiens Test
24 A dangerous cue 00'12.3856" 00'12.4505" je Test
25 A dangerous cue 00'12.4515" 00'12.5824" dîne Test
26 A dangerous cue 00'12.5834" 00'12.8462" d’exquis Test
27 A dangerous cue 00'12.8472" 00'13.0110" rôtis Test
28 A dangerous cue 00'13.0120" 00'13.0769" de Test
29 A dangerous cue 00'13.0779" 00'13.2088" bœuf Test
30 A dangerous cue 00'13.2098" 00'13.2747" au Test
31 A dangerous cue 00'13.2757" 00'13.3736" kir Test
32 A dangerous cue 00'13.3746" 00'13.4066" à Test
33 A dangerous cue 00'13.4076" 00'13.5385" l’aÿ Test
34 A dangerous cue 00'13.5395" 00'13.7033" d’âge Test
35 A dangerous cue 00'13.7043" 00'13.8022" mûr Test
36 A dangerous cue 00'13.8032" 00'14.0000" cætera Test

Loading