Skip to content

Instantly share code, notes, and snippets.

@jsta
Created January 4, 2017 14:25
Show Gist options
  • Save jsta/34ecc7bbe49f615e0d677724fa155d60 to your computer and use it in GitHub Desktop.
Save jsta/34ecc7bbe49f615e0d677724fa155d60 to your computer and use it in GitHub Desktop.
R script to interact with the handbrakeCLI program
# need to apt-get:
# * libdvdcsss2
# * handbrake-cli
handbrake_scan <- function(source){
cli <- paste0("HandBrakeCLI -i ", source, " --scan")
system(cli)
}
handbrake_scan("/media/user/disc")
handbrake_get <- function(source,
chapter_start, chapter_end, title, season, dest_folder){
chapter_seq <- chapter_start:chapter_end
dbl_pad <- function(x){
if(nchar(x) == 1){
paste0("0", x)
}else{
x
}
}
get_chapter <- function(chapter){
outpath <- paste0("'", dest_folder, title, " - ", "s",
dbl_pad(season), "e", dbl_pad(chapter), ".m4v", "'")
cli <- paste0("HandBrakeCLI -i ", source, " -t ", chapter, " -o ", outpath)
cli
}
lapply(chapter_seq, function(x) system(get_chapter(x)))
}
handbrake_get(source = "/media/user/disc",
chapter_start = 1,
chapter_end = 10,
title = "Disc Title",
season = 1,
dest_folder = "/videos-folder/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment