Skip to content

Commit

Permalink
Add Microsoft Stream (#46)
Browse files Browse the repository at this point in the history
* bump version, add to news

* add regex to get_service()

* get parse-method working

* get code working for msstream

* - reanme s3 classes for url-parsing
- add msstream to meta documentation
  • Loading branch information
ijlyttle authored Oct 4, 2020
1 parent 3a3b396 commit 7191149
Show file tree
Hide file tree
Showing 24 changed files with 236 additions and 31 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: vembedr
Title: Embed Video in HTML
Version: 0.1.3.9002
Version: 0.1.3.9003
Authors@R: c(
person(
given = "Ian",
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ S3method(set_iframe,vembedr_embed)
S3method(use_start_time,default)
S3method(use_start_time,vembedr_embed_box)
S3method(use_start_time,vembedr_embed_channel9)
S3method(use_start_time,vembedr_embed_msstream)
S3method(use_start_time,vembedr_embed_vimeo)
S3method(use_start_time,vembedr_embed_youtube)
export("%>%")
export(embed_box)
export(embed_channel9)
export(embed_msstream)
export(embed_url)
export(embed_user2016)
export(embed_user2017)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## vembedr 0.1.3.9000

- add support for [Microsoft Stream](https://www.microsoft.com/en-us/microsoft-365/microsoft-stream), which offers an enterprise video service; this will likely be for use internal to an organization. (#38)
- if you have a recent version of [usethis](https://usethis.r-lib.org) installed, `suggest_embed()` will copy the suggested code to your clipboard. (#32)
- sets the default `height` to 300 pixels, and introduces an argument `ratio`, to set the aspect ratio; legal values are `"16by9"` or `"4by3"`. If you set the `width` and `height`, `ratio` is ignored. If you specify only one of `width` or `height`, `ratio` is used to calculate the other. (#33)
- adds three functions to help with formatting; they are all pipeable with `embed_*()` functions:
Expand Down
4 changes: 3 additions & 1 deletion R/embed.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
#' \describe{
#' \item{YouTube}{<https://developers.google.com/youtube/player_parameters>}
#' \item{Vimeo}{<https://developer.vimeo.com/player/embedding>}
#' \item{Channel 9}{<https://channel9.msdn.com/Events/useR-international-R-User-conference/useR2016/Forty-years-of-S>
#' \item{Microsoft Channel 9}{<https://channel9.msdn.com/Events/useR-international-R-User-conference/useR2016/Forty-years-of-S>
#' (click the *Embed* tab)}
#' \item{Box}{<https://developer.box.com/docs/box-embed#section-build-box-embed-programatically>}
#' \item{Microsoft Stream}{<https://docs.microsoft.com/en-us/stream/portal-embed-video>}
#' }
#'
#' @param id `character`, identifier provided by the service
Expand All @@ -40,6 +41,7 @@
#' embed_user2016("Literate-Programming")
#' embed_user2017("Room-202-Lightning-Talks") %>% use_start_time("26m35s")
#' embed_box("m5do45hvzw32iv2aors3urf5pgkxxazx")
#' embed_msstream("ae21b0ac-4a2b-41f4-b3fc-f1720dd20f48")
#'
NULL

Expand Down
5 changes: 3 additions & 2 deletions R/parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ get_service <- function(url) {
youtube = "^www\\.youtube\\.com$",
youtube_short = "^youtu\\.be$",
vimeo = "^vimeo\\.com$",
box = "app\\.box\\.com$"
box = "app\\.box\\.com$",
msstream = "web\\.microsoftstream\\.com$"
)

# str_detect is vectorized over the patters
Expand Down Expand Up @@ -176,7 +177,7 @@ parse_video_url <- function(url) {
service <- get_service(url)

url_parsed <- httr::parse_url(url)
class(url_parsed) <- c(glue::glue("vembedr_{service}"))
class(url_parsed) <- c(glue::glue("vembedr_url_{service}"))

.parse(url_parsed)
}
Expand Down
22 changes: 21 additions & 1 deletion R/s3-classes.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
#' vembedr S3 Classes
#'
#' We use S3 classes to distinguish an embed object, and to denote which service it uses.
#' Knowledge of these classes is not needed for day-to-day use. Rather,
#' it is a bookkeeping device used to make it clearer to add a new service
#' in development.
#'
#' We use S3 classes to distinguish an embed object, and to denote which
#' service it uses. Objects of these classes are created by [embed_url()]
#' and each service's embed function.
#'
#' **`vembedr_embed`**
#'
#' - base class for all services
#' - HTML `<div>`
#' - contains the embed code
#'
#' There is an additional class attached according to the service:
#'
#' **`vembedr_embed_youtube`**
#' **`vembedr_embed_youtube_short`**
#' **`vembedr_embed_vimeo`**
#' **`vembedr_embed_channel9`**
#' **`vembedr_embed_box`**
#' **`vembedr_embed_msstream`**
#'
#' To support parsing, there is an internal S3 class attached to the URL
#' being processed. It is named according to the service:
#'
#' **`vembedr_url_youtube`**
#' **`vembedr_url_youtube_short`**
#' **`vembedr_url_vimeo`**
#' **`vembedr_url_channel9`**
#' **`vembedr_url_box`**
#' **`vembedr_url_msstream`**
#'
#' @name vembedr-s3-classes
#'
NULL


2 changes: 1 addition & 1 deletion R/service-box.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use_start_time.vembedr_embed_box <- function(embed, ...) {
}


.parse.vembedr_box <- function(url_parsed, ...) {
.parse.vembedr_url_box <- function(url_parsed, ...) {

# determine custom-domain by taking apart hostname
hostname_split <- stringr::str_split(url_parsed$hostname, "\\.")[[1]]
Expand Down
2 changes: 1 addition & 1 deletion R/service-channel9.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use_start_time.vembedr_embed_channel9 <- function(embed, start_time, is_paused =
embed
}

.parse.vembedr_channel9 <- function(url_parsed, ...){
.parse.vembedr_url_channel9 <- function(url_parsed, ...){

path_split <-
url_parsed$path %>%
Expand Down
64 changes: 64 additions & 0 deletions R/service-msstream.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#' @rdname embed
#' @export
#
embed_msstream <- function(id, width = NULL, height = 300,
ratio = c("16by9", "4by3"), query = NULL){

ratio <- match.arg(ratio)
dim <- get_width_height(width, height, ratio)

url <- httr::parse_url("https://web.microsoftstream.com/embed/video")

url$path <- glue::glue("{url$path}/{id}")
url$query <- c(list(autoplay = "false", showinfo = "true"), query)

iframe <- htmltools::tags$iframe(
src = httr::build_url(url),
width = dim$width,
height = dim$height,
allowfullscreen = NULL,
style = "border:none;"
)

embed <- create_embed(iframe, "vembedr_embed_msstream", ratio)

embed
}

#' @rdname use_start_time
#' @export
#'
use_start_time.vembedr_embed_msstream <- function(embed, start_time, ...){

# get the iframe
iframe <- get_iframe(embed)

# get the src from the iframe
src <- htmltools::tagGetAttribute(iframe, "src")

# parse the url
url <- httr::parse_url(src)

# set the time in url$query
url$query$st <- .secs(start_time)

# set the url in the iframe
# == need to ask about a public API for this in htmltools ==
iframe$attribs$src <- httr::build_url(url)

# set the iframe in the embed
embed <- set_iframe(embed, iframe)

embed
}

.parse.vembedr_url_msstream <- function(url_parsed, ...) {

path_split <- stringr::str_split(url_parsed$path, "/")[[1]]

list(
service = "msstream",
id = path_split[[2]],
start_time = url_parsed$query$st
)
}
2 changes: 1 addition & 1 deletion R/service-vimeo.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use_start_time.vembedr_embed_vimeo <- function(embed, start_time, ...){
embed
}

.parse.vembedr_vimeo <- function(url_parsed, ...){
.parse.vembedr_url_vimeo <- function(url_parsed, ...){

start_time <- NULL
if (!is.null(url_parsed$fragment)){
Expand Down
4 changes: 2 additions & 2 deletions R/service-youtube.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ use_start_time.vembedr_embed_youtube <- function(embed, start_time, ...){
embed
}

.parse.vembedr_youtube <- function(url_parsed, ...) {
.parse.vembedr_url_youtube <- function(url_parsed, ...) {
list(
service = "youtube",
id = url_parsed$query$v,
start_time = url_parsed$query$t
)
}

.parse.vembedr_youtube_short <- function(url_parsed, ...) {
.parse.vembedr_url_youtube_short <- function(url_parsed, ...) {
list(
service = "youtube",
id = url_parsed$path,
Expand Down
1 change: 1 addition & 0 deletions R/vembedr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' - Vimeo
#' - Microsoft Channel 9
#' - Box
#' - Microsoft Stream
#'
#' It provides two categories of functions:
#'
Expand Down
6 changes: 4 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ The goal of the vembedr package is to make it a little bit easier for you to emb

## New to version 0.1.3.9000

- functions to help you format: `use_rounded()`, `use_align()`, and `use_bs_responsive()`.
- you can embed videos hosted on Box, using `embed_box()`.
- new functions to help you format: `use_rounded()`, `use_align()`, and `use_bs_responsive()`.
- new services supported:
- Box, using `embed_box()`
- Microsoft Stream, using `embed_msstream()`

## Installation

Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ apps. Four services are currently supported:

## New to version 0.1.3.9000

- functions to help you format: `use_rounded()`, `use_align()`, and
`use_bs_responsive()`.
- you can embed videos hosted on Box, using `embed_box()`.
- new functions to help you format: `use_rounded()`, `use_align()`,
and `use_bs_responsive()`.
- new services supported:
- Box, using `embed_box()`
- Microsoft Stream, using `embed_msstream()`

## Installation

Expand Down
4 changes: 3 additions & 1 deletion checklist-new-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ When adding a new service, say TikTok, we need to make sure that we add it every

Maybe split up be service so that we can just add the file.

To determine service:
To determine service, add to regex list:

- `get_service()`: `R/parse.R`

Expand All @@ -19,9 +19,11 @@ Methods based on service:

- `R/s3-classes.R`
- `R/vembedr-package.R`
- `R/embed.R`
- `vignettes/vembedr.Rmd`
- `vignettes/embed.Rmd`
- `README.Rmd`
- `NEWS.md`

## Other videos

Expand Down
16 changes: 14 additions & 2 deletions man/embed.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/use_start_time.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/vembedr-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion man/vembedr-s3-classes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7191149

Please sign in to comment.