• Stars
    star
    135
  • Rank 269,297 (Top 6 %)
  • Language
    JavaScript
  • Created almost 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Channel Two: Run your own television network in the browser.

Channel Two

Channel Two is a JavaScript/HTML5 application for running your own television network in the browser. It's called Channel Two because I use a RF modulator to broadcast it on channel 2 in my house.

All you have to do is define the schedule in the cron-style schedule.txt file, run a PHP script to process the schedule and generate some JavaScript, and then open the channel-two.html in a browser window. It will play your scheduled programming as long as you let it.

Requirements

You'll need:

  • A computer with all of your programming (video files) available to it locally (or a list of all of your video files' URLs, assuming you're OK with the bandwidth required to stream them over the Internet).
  • PHP, for generating the schedule file.
  • Optionally (but ideally) ffmpeg so that Channel Two can cache the video durations.

How to Schedule Programming

The programming schedule is set in schedule.txt via cron-style rules.

You can either schedule specific videos to play at specific times, or you can schedule a folder of videos to be played in a given time slot. For example, if I wanted to play the file good-morning.mp4 every morning at 7am, I would add this rule to schedule.txt:

0 7 * * * /path/to/good-morning.mp4

(/path/to/good-morning.mp4 could also be the URL of a video file.)

And if I wanted to play an episode of Bonanza every day at noon (high noon), I'd add this line:

0 12 * * * /path/to/Bonanza/

Every day at noon, Channel Two will play the episode of Bonanza that comes after the last episode of Bonanza that was played (as determined by alphabetical order of the filenames).

"But what if I just want Channel Two to play random videos all day long?"

Sure, do this:

* * * * * /path/to/videos/

This will continuously loop through the videos in that folder, beginning a new one every time a video ends.

If you'd like to play the videos in random order, add the shuffle flag like this:

shuffle=true
* * * * * /path/to/videos/
shuffle=false

Programming Blocks

You can also schedule a block of time where videos should be played from a specific folder:

* 7-10 * * * /path/to/kids-videos/

This would play through all of the files in kids-videos/ every morning between 7 and 10am. The final video will play until it finishes unless something else is scheduled to play at a specific time that interferes.

More Examples

You can also schedule programming for specific dates:

0 12 25 12 * /path/to/a-christmas-story.mp4

This will play "A Christmas Story" at noon on Christmas.

When there is no programming to be played, Channel Two will display assets/right-back.gif, which you can of course customize to your liking.

Commercials!

Like any good network executive, you can also program ads to play around your content.

To turn on commercials for a portion of your schedule, add a line like this:

ads=/path/to/Ads/

where /path/to/Ads/ is a folder containing many short video files (in the folder or in subfolders), each ideally under a minute long. Tip: You can find many many many TV commercials on Internet video sites, and tools exist to download them to your own computer.

When ads are enabled, Channel Two will insert ad breaks inside of programming by monitoring when the video fades to black. It will play up to five ads and then resume the show where it left off. If there is time left at the end of the episode before the next half hour, it will play additional ads to fill that time too.

To turn ads back off, add this line:

ads=false

So in this example, ads will play after Friends and Seinfeld but not Sesame Street.

ads=/path/to/Ads/

0 12 * * * /path/to/TV Shows/Friends/
30 12 * * * /path/to/TV Shows/Seinfeld/

ads=false

0 13 * * * /path/to/TV Shows/Sesame Street/

Priority

Subsequent schedule entries take priority over previous entries. So if your schedule looks like this:

0 7 * * * /path/to/good-morning.mp4
0 7 15 * * /path/to/special-message.mp4

good-morning-household.mp4 will play at 7am, but on the 15th of the month, special-message.mp4 will play instead.

But if your schedule looks like this:

0 7 15 * * /path/to/special-message.mp4
0 7 * * * /path/to/good-morning.mp4

then good-morning.mp4 will play every day, even the 15th. It takes priority because it came after the entry for special-message.mp4.

However, if the cron schedules are exactly the same, the entries are combined into a single schedule. This set of rules:

0 7 * * * /path/to/good-morning.mp4
0 7 * * * /path/to/bad-morning.mp4

will cause Channel Two to play good-morning.mp4 the first day at 7am, then bad-morning.mp4 the second day, then good-morning.mp4 the third day, etc.

Closed Captions

If you have WebVTT caption files for your videos, you can force them to be used as closed captions by adding the captions=true flag to a scheduling block:

captions=true
0 9 * * * /path/to/play-me-with-captions.mp4

captions=false
0 11 * * * /path/to/no-captions-please.mp4

Channel Two will looks for a caption file in the same directory that is either the full filename plus ".vtt", or the filename with ".vtt" replacing the original file extension. For the example above, it would look for either /path/to/play-me-with-captions.mp4.vtt or /path/to/play-me-with-captions.vtt.

While a program is playing, you can press the "c" to force captions to be turned on if they are not already enabled.

Note that because of browser security policies, in order to use caption files, you must be running Channel Two through a Web server as described in the "Caveats" section below.

Generating the JavaScript programming file

Any time you modify schedule.txt, you'll need to re-generate the JavaScript schedule file. Do this:

$ php parse-schedule.php --schedule schedule.txt

It will read schedule.txt and save the appropriate JavaScript to programming.js for Channel Two to function.

You should also re-generate programming.js any time you add new files to any directory listed in schedule.txt. You could just set up a cron job to run $ php parse-schedule.php --schedule schedule.txt every hour; Channel Two will reload programming.js regularly in order to refresh the programming schedule.

Naming Your Files

Channel Two will use the video filenames to display a "You're watching..." chyron at the beginning of any new programming:

It takes the filename, removes the extension, and strips out anything in parentheses. For example, /path/to/Dallas/A House Divided (Commentary).mp4 would have the chyron "You're watching A House Divided".

Caveats

Due to browser limitations, you'll have to click the Channel Two "Click to start" image after loading channel-two.html in order to allow video playback and fullscreen.

If you want to run Channel Two via a Web server instead of a file:// URL, you'll need to make a few changes:

  1. Create a symlink in your Web server's document root to your media folder, using the same name as media folder name. For example, if your video files are stored in /path/to/myvideos/, then you should create a symlink called myvideos in your document root:

$ ln -s /path/to/myvideos /Library/WebServer/Documents/myvideos

  1. Then in schedule.txt, make sure that you start all of your video paths with /myvideos instead of /path/to/myvideos.

  2. Add a base directive to the top of schedule.txt so that the schedule parser knows where to find the files, as the paths in schedule.txt will be relative to your Web server root, not necessarily to the directory Channel Two is stored in:

base=/Library/WebServer/Documents/

I developed this using the latest versions of Firefox and Chrome, so if your copies are at all out of date, I can't guarantee everything works. Have fun, and email me at [email protected] with any questions.

More Repositories

1

Typo.js

A client-side JavaScript spellchecker that uses Hunspell-style dictionaries.
JavaScript
507
star
2

LEGO.scad

An OpenSCAD LEGO-compatible brick generator.
OpenSCAD
219
star
3

OSX-Messages-Exporter

Exports iMessages and SMS's to files.
PHP
174
star
4

OpenSCAD-Dovetails

A library for generating dovetail tails and pins in OpenSCAD.
OpenSCAD
44
star
5

3D-Prints

Miscelleneous 3D prints and models.
OpenSCAD
34
star
6

Retweet

A script that republishes any tweets that start with "@username", where “username” is an arbitrary username that you supply.
Python
15
star
7

Garbage-Cabinet

A customizable tilt-out garbage cabinet.
OpenSCAD
14
star
8

Blog-Helper

Blog Helper is a Alexa skill that provides a voice interface for WordPress.com blogs
PHP
13
star
9

Keyring-Facebook-Importer

A Facebook importer for use with the Keyring and Keyring Social Importers WordPress plugins.
PHP
13
star
10

PHP-GEDCOM-Tools

PHP scripts for interacting with GEDCOM files.
PHP
12
star
11

RSS-Ticker

RSS Ticker loads your Firefox Live Bookmarks and scrolls their entries across your screen while you surf.
JavaScript
7
star
12

Comment-Snob

Comment Snob is a browser extension that filters out undesirable comments from comment threads on the Web.
JavaScript
6
star
13

AutoAuth

JavaScript
6
star
14

Clockback

Clockback is the Web frontend and upload script for a basic open-source Timehop replacement.
PHP
6
star
15

Dropseeker

Transcribe podcasts to make them searchable, and then extract audio clips based on search terms.
PHP
5
star
16

googlecode2github

A script to import support issues from a Google Code project to a Github project.
Python
5
star
17

Feed-Sidebar

The Feed Sidebar is an extension for Firefox that displays the items from your Live Bookmarks in the sidebar.
JavaScript
5
star
18

ChroSh

The Google Chrome Shell
5
star
19

Telegraph.js

Telegraph.js is a JavaScript library that enables Morse code input on text fields.
JavaScript
5
star
20

Formategory

A WordPress plugin that formats posts based on their categories.
PHP
4
star
21

anyMail

anyMail was an IMAP Web e-mail client I wrote during an independent study course in college. I'm publishing the code for posterity; you really shouldn't use it.
PHP
4
star
22

Better-Omnibox

Better Omnibox improves the relevance of Chrome's Omnibox results.
4
star
23

Rite-Track-Compatible-Hardware

3D models of a drawer component socket and case runner guide compatible with the Kenlin Rite-Trak drawer track system.
OpenSCAD
4
star
24

iPhoto-Disc-Export

Export your iPhoto library as a browseable website that can be burned to a disc and remain completely functional offline or uploaded and served from a website.
PHP
4
star
25

Keyring-Reddit-Importer

Import Reddit posts and comments.
PHP
3
star
26

Keyring-River

WordPress theme based on David Hariri's 'river' project.
PHP
3
star
27

Name-Exchange

3
star
28

pyTiVo-Utilities

Python
3
star
29

Tab-History-Redux

Causes links opened in a new tab in Firefox retain their history.
JavaScript
3
star
30

OPML-Support

OPML Support is a Firefox extension that adds support for importing and exporting bookmarks in OPML format.
JavaScript
3
star
31

New-Tabs-At-End

Makes new tabs open at the end of the tab strip in Chrome.
2
star
32

Facebook-Email-Links

Converts plain-text email addresses in Facebook profiles to mailto: links.
JavaScript
2
star
33

Ryuki

A child theme of the Ryu WordPress theme that modifies the front page to show content from featured categories.
PHP
2
star
34

Reenact

An app for reenacting photos.
JavaScript
2
star
35

URL-Fixer

URL Fixer is a Firefox extension that automatically corrects typographical errors in URLs typed in the Firefox Location Bar.
JavaScript
2
star
36

TwitterBar

TwitterBar allows you to post to Twitter from Firefox's address bar.
JavaScript
2
star
37

Clean-and-Sober

A clean (and sober) WordPress theme.
PHP
2
star
38

Translate

Small extension that either translates: web pages (via toolbar button) or selected text (via context menu) from several foreign languages into English, as well as 12 other languages.
JavaScript
2
star
39

BeardTracker

A webapp to track your beard's progress from peach fuzz to man fur.
1
star
40

anyInventory

anyInventory was the Web's most flexible inventory system in 2004.
PHP
1
star
41

YouTube-Comment-Snob

An intelligence filter for YouTube's comment section.
JavaScript
1
star
42

scribefire-chrome

Automatically exported from code.google.com/p/scribefire-chrome
JavaScript
1
star
43

StopMotion

Stops the auto-play of DailyMotion videos.
JavaScript
1
star
44

GlotPress-Chrome-Extension-Support

Extend GlotPress to support Chrome-style messages.json locales.
PHP
1
star
45

Facebook-Image-to-Email

A Firefox extension that decoded the images that Facebook used to use to display email addresses.
JavaScript
1
star
46

Akisbot

Akisbot is alive.
OpenSCAD
1
star
47

Farmhouse-Table

Customizable plans for a farmhouse-style table.
OpenSCAD
1
star
48

Do-Today

A lightweight chore-tracking web app.
PHP
1
star
49

Deepgram-PHP

An unofficial PHP SDK for Deepgram's API.
PHP
1
star
50

Solar-System

An OpenSCAD animation of the solar system.
OpenSCAD
1
star
51

Slashdotter

Slashdotter is a Firefox extension that makes it easier (and more fun!) to use Slashdot.org.
JavaScript
1
star
52

Tapsure

A browser extension that allows you to tap your passwords.
JavaScript
1
star
53

True-Colors

True Colors is a Firefox extension that bleeds the colors from the web page you're viewing into the tab bar and status bar. Think of it as Ambilight for your browser.
JavaScript
1
star
54

Interpr.it

Interpr.it is a collaborative tool for browser extension developers and bi-lingual extension users.
PHP
1
star
55

Plain-Text-Links

Plain Text Links is a Firefox extension that allows you to open plain-text URLs as links via the context menu.
JavaScript
1
star
56

iPhoto-WordPress-Export

Export your iPhoto library to a WordPress website.
PHP
1
star
57

Halftone

Halftone is an app for making halftone-style carves with Inventables's Easel CNC design platform.
JavaScript
1
star
58

Inline-Preview

Inline Preview is a plugin for WordPress that adds a zoomed out preview of the current post next to the post editor when the user clicks Preview instead of opening in a new tab.
JavaScript
1
star
59

WATE

WATE (Web Advanced Text Editor) is a Web-based text editor for use in instances when X-forwarding is not feasible (or possible), and a terminal editor hinders code production.
JavaScript
1
star
60

Speedlapse

Speed up videos with ffmpeg according to a curve (or any function).
PHP
1
star
61

Twitter-Filter

A browser extension that allows you to filter out Twitter updates based on their source.
JavaScript
1
star
62

Links-Like-This

Links Like This is a Firefox extension that helps you to open sets of similar links in tabs at once.
JavaScript
1
star
63

Photos-Only

A WordPress plugin that automatically shows all of your uploaded images as published posts, no extra steps required. Just upload to the media library.
PHP
1
star
64

TubeStop

TubeStop is a Firefox extension that prevents YouTube videos from playing automatically, whether you are viewing them on YouTube.com or via a third-party site that is embedding them.
JavaScript
1
star
65

Alexa-Rock-Jar

This skill allows you to keep virtual voice-controlled rock jars. A rock jar is a method for tracking children's behavior. Rocks are added for good behavior and removed for bad behavior. When the jar is full (or reaches a certain number of rocks), the child can exchange the rocks for a reward.
PHP
1
star
66

Alexa-Bored

This is an Alexa skill that gives you (or your kids) ideas for things to do when you (or your kids) are bored.
PHP
1
star