Skip to content

Commit

Permalink
Merge pull request #613 from calzoneman/videojs-hls
Browse files Browse the repository at this point in the history
Add HLS support (and upgrade Video.JS)
  • Loading branch information
calzoneman authored Aug 10, 2016
2 parents 96a5d65 + e99bfcd commit f9ccb15
Show file tree
Hide file tree
Showing 11 changed files with 6,971 additions and 2,141 deletions.
1 change: 1 addition & 0 deletions build-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var order = [
'ustream.coffee',
'imgur.coffee',
'gdrive-youtube.coffee',
'hls.coffee',
'update.coffee'
];

Expand Down
23 changes: 23 additions & 0 deletions player/hls.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
window.HLSPlayer = class HLSPlayer extends VideoJSPlayer
constructor: (data) ->
if not (this instanceof HLSPlayer)
return new HLSPlayer(data)

@setupMeta(data)
super(data)

load: (data) ->
@setupMeta(data)
super(data)

setupMeta: (data) ->
data.meta.direct =
# Quality is required for data.meta.direct processing but doesn't
# matter here because it's dictated by the stream. Arbitrarily
# choose 480.
480: [
{
link: data.id
contentType: 'application/x-mpegURL'
}
]
1 change: 1 addition & 0 deletions player/update.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ TYPE_MAP =
us: UstreamPlayer
im: ImgurPlayer
vm: VideoJSPlayer
hl: HLSPlayer
sb: VideoJSPlayer

window.loadMediaPlayer = (data) ->
Expand Down
7 changes: 7 additions & 0 deletions src/get-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,13 @@ var Getters = {
callback(false, media);
},

/* HLS stream */
hl: function (id, callback) {
var title = "Livestream";
var media = new Media(id, title, "--:--", "hl");
callback(false, media);
},

/* imgur.com albums */
im: function (id, callback) {
/**
Expand Down
5 changes: 4 additions & 1 deletion src/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
});
}

return result.join(":");
return result.join(":");
},

root.formatTime = function (sec) {
Expand Down Expand Up @@ -242,6 +242,8 @@
return id;
case "hb":
return "http://hitbox.tv/" + id;
case "hl":
return id;
case "sb":
return "https://streamable.com/" + id;
default:
Expand All @@ -259,6 +261,7 @@
case "im":
case "jw":
case "hb":
case "hl":
return true;
default:
return false;
Expand Down
1 change: 1 addition & 0 deletions templates/channel.pug
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,4 @@ html(lang="en")
script(defer, src="/js/sc.js")
script(defer, src="/js/froogaloop.min.js")
script(defer, src="/js/video.js")
script(defer, src="/js/videojs-contrib-hls.min.js")
555 changes: 320 additions & 235 deletions www/css/video-js.css

Large diffs are not rendered by default.

34 changes: 33 additions & 1 deletion www/js/player.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function() {
var CUSTOM_EMBED_WARNING, CustomEmbedPlayer, DEFAULT_ERROR, DailymotionPlayer, EmbedPlayer, FilePlayer, GoogleDriveYouTubePlayer, HITBOX_ERROR, HitboxPlayer, ImgurPlayer, LivestreamPlayer, Player, RTMPPlayer, SoundCloudPlayer, TYPE_MAP, TwitchPlayer, USTREAM_ERROR, UstreamPlayer, VideoJSPlayer, VimeoPlayer, YouTubePlayer, codecToMimeType, genParam, sortSources,
var CUSTOM_EMBED_WARNING, CustomEmbedPlayer, DEFAULT_ERROR, DailymotionPlayer, EmbedPlayer, FilePlayer, GoogleDriveYouTubePlayer, HITBOX_ERROR, HLSPlayer, HitboxPlayer, ImgurPlayer, LivestreamPlayer, Player, RTMPPlayer, SoundCloudPlayer, TYPE_MAP, TwitchPlayer, USTREAM_ERROR, UstreamPlayer, VideoJSPlayer, VimeoPlayer, YouTubePlayer, codecToMimeType, genParam, sortSources,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;

Expand Down Expand Up @@ -1257,6 +1257,37 @@

})(Player);

window.HLSPlayer = HLSPlayer = (function(superClass) {
extend(HLSPlayer, superClass);

function HLSPlayer(data) {
if (!(this instanceof HLSPlayer)) {
return new HLSPlayer(data);
}
this.setupMeta(data);
HLSPlayer.__super__.constructor.call(this, data);
}

HLSPlayer.prototype.load = function(data) {
this.setupMeta(data);
return HLSPlayer.__super__.load.call(this, data);
};

HLSPlayer.prototype.setupMeta = function(data) {
return data.meta.direct = {
480: [
{
link: data.id,
contentType: 'application/x-mpegURL'
}
]
};
};

return HLSPlayer;

})(VideoJSPlayer);

TYPE_MAP = {
yt: YouTubePlayer,
vi: VimeoPlayer,
Expand All @@ -1274,6 +1305,7 @@
us: UstreamPlayer,
im: ImgurPlayer,
vm: VideoJSPlayer,
hl: HLSPlayer,
sb: VideoJSPlayer
};

Expand Down
11 changes: 10 additions & 1 deletion www/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ function formatURL(data) {
return data.id;
case "hb":
return "http://hitbox.tv/" + data.id;
case "hl":
return data.id;
case "sb":
return "https://streamable.com/" + data.id;
default:
Expand Down Expand Up @@ -1368,6 +1370,13 @@ function parseMediaLink(url) {
};
}

if ((m = url.match(/(.*\.m3u8)/))) {
return {
id: m[1],
type: "hl"
};
}

if((m = url.match(/streamable\.com\/([\w-]+)/))) {
return {
id: m[1],
Expand Down Expand Up @@ -1450,7 +1459,7 @@ function stripImages(msg){
return msg;
}
return msg.replace(IMAGE_MATCH, function(match,img){
return CHANNEL.opts.enable_link_regex ?
return CHANNEL.opts.enable_link_regex ?
'<a target="_blank" href="'+img+'">'+img+'</a>' : img;
});
}
Expand Down
Loading

0 comments on commit f9ccb15

Please sign in to comment.