Monday, November 18, 2019

Automated Scheduling of Facebook Live Video via Google Apps Script

Currently Facebook allows users to schedule a live video broadcast only a week in advance. If you broadcast weekly this can get tedious, so with a little bit of coding we can automate the process.

This will require a Facebook account (with admin rights to a page if you broadcast through that page) as well as a Google account. We are going to create a Google Spreadsheet with an associated Google Apps Script that will run every week to schedule your live video.
  1. Create a Google Spreadsheet
  2. Under the Tools menu, click Script editor
  3. Into that new script paste the contents of this file
  4. Create a new Facebook App under the My Apps menu on developers.facebook.com
  5. Under Settings click on Basic and copy your App ID and App Secret (click Show) into the appropriate places back in your Google Script editor
  6. Setup gsuitedevs' OAuth2 library for Google Apps Script by following the four steps there
  7. Run the logRedirectUri function in your Google Script, then under the View menu click Logs, copy the Redirect URL (starting with http)
  8. On the Facebook developer page, set up Facebook Login for your app
  9. Under the Facebook Login Settings, paste in the OAuth Redirect URI that you copied earlier
  10. In your Google Script, run the scheduleLivestream function, this won't actually schedule anything yet but instead will log a URL for you to paste into your browser to authorize the script (under the View menu click Logs, or look at the original spreadsheet)
  11. Using the Facebook Graph API Explorer, add the following permissions to your app: pages_show_list, manage_pages, publish_pages, publish_video
  12. Run the Google Script function scheduleLivestream again and watch for any errors, if it successfully schedules a broadcast then you'll see a new line in your spreadsheet
  13. Add triggers to your Google Script: under the Edit menu click Current project's triggers
    1. Click Add Trigger and set the options:
      1. scheduleLivestream
      2. Head
      3. Time-driven
      4. Week timer
      5. Every Wednesday (or whatever you prefer)
      6. 1pm to 2pm (or whatever)
      7. then click Save
    2. Click Add Trigger and set the options:
      1. onOpen
      2. Head
      3. From spreadsheet
      4. On open
      5. then click Save
  14. In your Google Script, change the following lines:
    1. var status = 'SCHEDULED_UNPUBLISHED';  to  var status = 'SCHEDULED_LIVE';
    2. var day = dateNow.getDate() + ((7dateNow.getDay()) % 7);  to var day = dateNow.getDate() + ((9dateNow.getDay()) % 7);  // for Tuesday
    3. var newDate = new Date(year, month, day, 10, 25); to the time you'd like to start the broadcast
    4. you can also change the var title line to whatever you'd like
  15. Run the scheduleLivestream function again to test, and to make sure everything has been authorized
  16. Check at some point after the Trigger time you set to make sure that the broadcast has been scheduled
Hopefully all of that worked, let me know if I've missed any steps or if this needs more detail.

Thursday, November 7, 2019

The Benefits of Small Conferences

In the last few weeks I have been to quite a few conferences around Alberta, and have been reflecting on the ideal conference size. A conference should involve information sharing and discussions or networking, the latter may be less possible at larger conferences.

Events like the annual ISTE Conference with about 20,000 attendees are impressive, and you may meet someone like Mayim Bialik, but it feels like the odds of meeting someone with whom you can have sustained and ongoing discussions are decreased. There is an ocean of information available, but I'd argue that through the internet we already have that available.

So perhaps the ideal conference size is between 150 and 500 participants. Large enough for a diversity of perspectives, but small enough to be able to meaningfully share those perspectives and get to know people. We tend to value growth as a measure of success, but perhaps we need other metrics.

Thoughts?

Monday, November 4, 2019

Colab Git Puller Bookmarklet

Similar to the Callysto nbgitpuller bookmarklet, here's the code for a bookmarklet to open a Jupyter notebook from GitHub in Google Colab. Drag the following link to your bookmark bar/menu:

ColabGitPuller

Click that bookmarklet when you are viewing a Jupyter notebook on GitHub, it will pop up a window with a link. Copy that link and you can use it to open the notebook in Colab.

If you prefer a bookmarklet that just opens the notebook in Colab (rather than giving you a link to paste somewhere) then use this one:

ColabGitOpener

As always, comment if you encounter any issues or have any suggestions.

Wednesday, October 16, 2019

nbgitpuller bookmarklet

We use nbgitpuller with JupyterHub to distribute notebooks from GitHub. Nbgitpuller is a tool for copying a code repository from GitHub to your own Jupyter server.

Instead of manually formatting the nbgitpuller URLs or using a link generator, I wanted to automate the process. So here's a basic bookmarklet that automatically generates nbgitpuller links for our Callysto Hub:

javascript:(function(){var url=location.href;var res=url.split("/");var site=res[2];var user=res[3];var repo=res[4];var treeBlob=res[5];var branch=res[6];var nbgitputllerUrl="https://hub.callysto.ca/jupyter/hub/user-redirect/git-pull?repo=";if(site=="github.com"){if(treeBlob){var subPath=url.substring(url.indexOf(branch)+branch.length+1);nbgitputllerUrl+=encodeURIComponent("https://github.com/"+user+"/")+repo+"&branch="+branch+"&subPath="+subPath+"&depth=1";}else{nbgitputllerUrl+=url;}}window.prompt("Callysto nbgitpuller link",nbgitputllerUrl);})();

If you're not familiar with bookmarklets, they're basically bits of Javascript in the URL portion of a browser bookmark. To set one up, drag this link to your bookmark bar/menu:

CallystoGitPuller

Then when you are on a GitHub page you can click that bookmark and it will pop up a prompt with an nbgitpuller link to open that GitHub notebook or repository in CallystoHub.

Here is the code as a GitHub gist if you'd like to make your own and perhaps use JavaScript Cruncher to condense it to a single URL-encoded link.

Edit:

I've also posted about a similar bookmarklet to open notebooks in Colab.

Sunday, October 13, 2019

SRT vs NDI

I've previously posted about both NDI and SRT, they are great video transmission protocols. Both are unicast by default, but can support multiple clients or players. There are some differences that might make you choose one over the other, here are a few that I can think of:

SRT is open source, NDI is royalty-free
SRT is low latency, NDI is very low latency
SRT can work over WiFi or across public internet, NDI works best over gigabit LAN
SRT support is coming to OBS, NDI is available in OBS via a plugin
SRT seems to be supported by more digital signage players
NDI seems to be supported by more cameras

For myself, I'll continue to implement both for different use cases.

Please comment below about missing information or errors.

Thursday, October 3, 2019

Low Latency Streaming from OBS to BrightSign Using SRT

There are a few free video streaming services that support low-latency streaming over the internet, notably Mixer and YouTube ultra-low latency. However if you prefer local streaming (perhaps to conserve bandwidth) or prefer open source, let's take a look at how you can stream from OBS Studio to BrightSign players (not open source) or other devices that support SRT streaming protocol such as VLC.

Edit: OBS supports SRT as of version 25, but I'll leave this post up for historical reasons.

--- 

Hopefully at some point soon OBS will support SRT, but for now we'll need to run a separate application. Assuming that you are already using OBS for streaming to an external destination, we'll use the "recording" feature to send to Haivision's srt-live-transmit application.

There's some work required to compile srt-live-transmit, and I'll admit I haven't gotten it to work on Windows yet, but it's easy on Linux (including Windows Subsystem for Linux) and Mac.

SRT for Mac

Getting SRT on Mac just involves launching the "Terminal" program and running two commands:

brew update
brew install srt

This will install srt-live-transmit at:

/usr/local/Cellar/srt/1.4.0/bin/srt-live-transmit

SRT for Linux or WSL

If you have Ubuntu installed under Windows 10 through Windows Subsystem for Linux, you can run the following commands in the terminal:

sudo apt update
sudo apt upgrade
sudo apt install tclsh pkg-config cmake libssl-dev build-essential git
git clone https://github.com/Haivision/srt.git
cd srt
./configure
make

After the compilation process, you should have:

~/srt/srt-live-transmit

Sending from OBS to srt-live-transmit

From the terminal (on Mac, Linux, or WSL), run the following command:

./srt-live-transmit udp://:1234 srt://:5678 -v

On your Mac you may first need to change to the right directory:
cd /usr/local/Cellar/srt/1.4.0/bin/

That command listens for a UDP stream (that we'll send from OBS) and listens for a request to unicast it as an SRT stream. The -v means verbose mode, which allows us to read what it is doing.

In OBS we need to go into Settings, click on Output, switch the Output Mode to Advanced and click on the Recording tab. Switch the Type to Custom Output (FFmpeg) and the FFmepeg Output Type to Output to URL.

The File path or URL should be set to udp://127.0.0.1:1234?pkt_size=1316 (127.0.0.1 means sending to the same computer that OBS is running on) and the Container Format should be changed to mpegts. I haven't done any testing, but I'm assuming that decreasing the Keyframe interval should decrease latency, and decreasing the Audio Bitrate is probably fine to decrease bandwidth usage.



Click OK, then the Start Recording button. Have a look at the terminal window where srt-live-transmit is running. You should see information about the stream.

Add the SRT source to BrightSign or play it as a network source in VLC (if your sending computer is at 10.0.0.200 then srt://10.0.0.200:5678). You should see your stream that is being transmitted from OBS and relayed by srt-live-transmit.

Hopefully this works for you, feel free to comment if you encounter issues.

Using Git from the Command Line

This post is more for my future self, but others may find it useful. Feel free to comment if I've made any errors or missed anything important.

Assuming that Git is already installed, to start using it with terminal commands we need to set up a couple of things:

git config --global user.email "INSERT_EMAIL_ADDRESS_HERE"
git config --global user.name "MisterHay"
git config --global core.editor nano

It's also a good idea to set up SSH keys.

and then clone the appropriate repository:

git clone https://github.com/callysto/curriculum-notebooks.git

or with ssh:

git clone git@github.com:callysto/curriculum-notebooks.git

and some useful commands:

list branches:
git branch -a

get files from GitHub:
git checkout origin/staging

create branch from staging:
git checkout origin/staging -b NameOfNewBranch

change to branch (if not already there):
git checkout --track origin/NameOfBranch

edit files, then (stage changes):
git add changed_file.ipynb
or
git add ./*

check with:
git status

discard all local changes to all files permanently:
git reset --hard

commit to local:
git commit

push to remote:
git push -u origin NameOfBranch

then create a pull request to staging from that_branch using GitHub.com interface

To see what has been happening, check the top of
git log

Hopefully that's enough to get you (future me back) up to speed.

Wednesday, September 11, 2019

My new job: Callysto Ambassador

Since I haven't written a blog post in a while, perhaps I can talk briefly about my new job. Funding has been officially announced for PIMS and Cybera's CanCode project entitled "Callysto: Building Tomorrow's Digital Leaders". I'm taking a year off from teaching to help with resource development and teacher training for the Callysto project.

Callysto aims to foster computational thinking and data science skills in students and for teachers. There are some curriculum-related notebooks, a Jupyter Hub, online courses (being developed), supports for teacher to develop notebooks, as well as opportunities to offer (call for proposals coming soon) or attend professional learning activities, or participate in educational research.

Everything through the Callysto project is available for free (gratis and libre).

Let us know if you're interested.