Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style and add basic checks here #35

Merged
merged 1 commit into from
Mar 4, 2022
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
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature Request
about: Suggest an idea for the course templates
title: ''
labels: ''
assignees: cansavvy

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
30 changes: 30 additions & 0 deletions .github/ISSUE_TEMPLATE/problem-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: Problem Report
about: Create a report to help improve ottrpal and its documentation
title: problem
labels: bug
assignees: cansavvy

---

**Describe what is not working with the template or is unclear in the documentation**
A clear and concise description of what the bug is.

**Please link to the specific course repository you are working on**

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.
What does the render look like versus what did you write and supply to `ottrpal`?

**Additional context**
Add any other context about the problem here.
17 changes: 17 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!--This PR Template was modified from https://github.com/AlexsLemonade/OpenPBTA-analysis/blob/master/.github/PULL_REQUEST_TEMPLATE.md-->

### Purpose/implementation Section

#### What changes are being implemented in this Pull Request?



#### What was your approach?



#### What GitHub issue does your pull request address?



### Tell potential reviewers what kind of feedback you are soliciting.
86 changes: 86 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v1
with:
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-pandoc@v1

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Restore R package cache
if: runner.os != 'Windows'
uses: actions/cache@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')

- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: |
options(crayon.enabled = TRUE)
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), check_dir = "check")
shell: Rscript {0}

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
21 changes: 11 additions & 10 deletions R/ari_burn_subtitles.R
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
#' Burn Subtitles into a video
#'
#' @note This needs \code{ffmpeg} that was compiled with
#' \code{--enable-libass} as per
#'
#' @note This needs \code{ffmpeg} that was compiled with
#' \code{--enable-libass} as per
#' \url{https://trac.ffmpeg.org/wiki/HowToBurnSubtitlesIntoVideo}
#'
#' @param video Video in \code{mp4} format
#' @param srt Subtitle file in \code{srt} format
#' @param verbose print diagnostic messages. If > 1,
#' @param verbose print diagnostic messages. If > 1,
#' then more are printed
#'
#' @return Name of output video
ari_burn_subtitles = function(video, srt, verbose = FALSE) {
ffmpeg = ffmpeg_exec(quote = TRUE)
ari_burn_subtitles <- function(video, srt, verbose = FALSE) {
ffmpeg <- ffmpeg_exec(quote = TRUE)
if (verbose > 0) {
message("Burning in Subtitles")
}
command <- paste(
ffmpeg, "-y -i", video, paste0("-vf subtitles=", srt),
video)
video
)

if (verbose > 0) {
message(command)
}
res = system(command)
res <- system(command)
if (res != 0) {
warning("Result was non-zero for ffmpeg")
}

return(video)
}
}
8 changes: 4 additions & 4 deletions R/ari_example.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
#'
#' @param path The name of the file. If no argument is provided then
#' all of the example files will be listed.
#'
#'
#' @return A character string
#' @export
#' @examples
#' ari_example("ari_intro.Rmd")
ari_example <- function(path = NULL){
if(is.null(path)) {
ari_example <- function(path = NULL) {
if (is.null(path)) {
list.files(system.file("test", package = "ari"))
} else {
system.file("test", path, package = "ari", mustWork = TRUE)
}
}
}
104 changes: 57 additions & 47 deletions R/ari_narrate.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#' Create a video from slides and a script
#'
#'
#' \code{ari_narrate} creates a video from a script written in markdown and HTML
#' slides created with \code{\link[rmarkdown]{rmarkdown}} or a similar package.
#' This function uses \href{https://aws.amazon.com/polly/}{Amazon Polly}
#' This function uses \href{https://aws.amazon.com/polly/}{Amazon Polly}
#' via \code{\link{ari_spin}}.
#'
#' @param script Either a markdown file where every paragraph will be read over
#' a corresponding slide, or an \code{.Rmd} file where each HTML comment will
#' be used for narration.
#' @param slides A path or URL for an HTML slideshow created with
#' \code{\link[rmarkdown]{rmarkdown}}, \code{xaringan}, or a
#' @param slides A path or URL for an HTML slideshow created with
#' \code{\link[rmarkdown]{rmarkdown}}, \code{xaringan}, or a
#' similar package.
#' @param output The path to the video file which will be created.
#' @param voice The voice you want to use. See
#' \code{\link[text2speech]{tts_voices}} for more information
#' @param voice The voice you want to use. See
#' \code{\link[text2speech]{tts_voices}} for more information
#' about what voices are available.
#' @param service speech synthesis service to use,
#' passed to \code{\link[text2speech]{tts}}.
#' passed to \code{\link[text2speech]{tts}}.
#' Either \code{"amazon"} or \code{"google"}.
#' @param capture_method Either \code{"vectorized"} or \code{"iterative"}.
#' The vectorized mode is faster though it can cause screens to repeat. If
Expand All @@ -33,7 +33,7 @@
#' @param video_codec The video encoder for the splicing. If this
#' fails, see \code{ffmpeg -codecs}
#' @param cleanup If \code{TRUE}, interim files are deleted
#'
#'
#' @return The output from \code{\link{ari_spin}}
#' @importFrom xml2 read_html
#' @importFrom rvest html_nodes html_text
Expand All @@ -42,48 +42,48 @@
#' @importFrom webshot webshot
#' @importFrom tools file_ext
#' @export
#' @examples
#' @examples
#' \dontrun{
#'
#' #
#'
#' #
#' ari_narrate(system.file("test", "ari_intro_script.md", package = "ari"),
#' system.file("test", "ari_intro.html", package = "ari"),
#' voice = "Joey")
#'
#' system.file("test", "ari_intro.html", package = "ari"),
#' voice = "Joey"
#' )
#' }
ari_narrate <- function(script, slides,
ari_narrate <- function(script, slides,
output = tempfile(fileext = ".mp4"),
voice = text2speech::tts_default_voice(service = service),
voice = text2speech::tts_default_voice(service = service),
service = "amazon",
capture_method = c("vectorized", "iterative"),
subtitles = FALSE, ...,
verbose = FALSE,
audio_codec = get_audio_codec(),
video_codec = get_video_codec(),
cleanup = TRUE){

auth = text2speech::tts_auth(service = service)
cleanup = TRUE) {
auth <- text2speech::tts_auth(service = service)
if (!auth) {
stop(paste0("It appears you're not authenticated with ",
service, ". Make sure you've ",
"set the appropriate environmental variables ",
"before you proceed.")
)
stop(paste0(
"It appears you're not authenticated with ",
service, ". Make sure you've ",
"set the appropriate environmental variables ",
"before you proceed."
))
}
capture_method = match.arg(capture_method)


capture_method <- match.arg(capture_method)
if (!(capture_method %in% c("vectorized", "iterative"))) {
stop('capture_method must be either "vectorized" or "iterative"')
}

output_dir <- normalizePath(dirname(output))
script <- normalizePath(script)
if (file_ext(script) %in% c("Rmd", "rmd") & missing(slides)) {
tfile = tempfile(fileext = ".html")
slides = rmarkdown::render(input = script, output_file = tfile)
}
tfile <- tempfile(fileext = ".html")
slides <- rmarkdown::render(input = script, output_file = tfile)
}

if (file.exists(slides)) {
slides <- normalizePath(slides)
if (.Platform$OS.type == "windows") {
Expand All @@ -96,7 +96,7 @@ ari_narrate <- function(script, slides,
file.exists(script),
dir.exists(output_dir)
)

if (file_ext(script) %in% c("Rmd", "rmd")) {
paragraphs <- parse_html_comments(script)
} else {
Expand All @@ -105,29 +105,39 @@ ari_narrate <- function(script, slides,
on.exit(unlink(html_path, force = TRUE), add = TRUE)
}
render(script, output_format = html_document(), output_file = html_path)
paragraphs <- map_chr(html_text(html_nodes(read_html(html_path), "p")),
function(x){gsub("\u2019", "'", x)})
paragraphs <- map_chr(
html_text(html_nodes(read_html(html_path), "p")),
function(x) {
gsub("\u2019", "'", x)
}
)
}

slide_nums <- seq_along(paragraphs)
img_paths <- file.path(output_dir,
paste0("ari_img_",
slide_nums, "_",
grs(), ".jpeg"))

img_paths <- file.path(
output_dir,
paste0(
"ari_img_",
slide_nums, "_",
grs(), ".jpeg"
)
)

if (capture_method == "vectorized") {
webshot(url = paste0(slides, "#", slide_nums), file = img_paths, ...)
} else {
for (i in slide_nums) {
webshot(url = paste0(slides, "#", i), file = img_paths[i], ...)
}
}

if (cleanup) {
on.exit(walk(img_paths, unlink, force = TRUE), add = TRUE)
}
ari_spin(images = img_paths, paragraphs = paragraphs,
output = output, voice = voice,
service = service, subtitles = subtitles,
verbose = verbose, cleanup = cleanup)
}
ari_spin(
images = img_paths, paragraphs = paragraphs,
output = output, voice = voice,
service = service, subtitles = subtitles,
verbose = verbose, cleanup = cleanup
)
}
Loading