forked from clkao/hlsjs-p2p-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_demo.rb
executable file
·43 lines (27 loc) · 1.32 KB
/
update_demo.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env ruby
require 'json'
# Updates the Hls.js demo based on the supported version
CURRENT_FOLDER = File.expand_path(File.dirname(__FILE__))
PACKAGE = File.read(File.join(CURRENT_FOLDER, 'package.json'))
PACKAGE_HASH = JSON.parse(PACKAGE)
VERSION = PACKAGE_HASH['dependencies']['hls.js'].sub('^', '');
FILENAME = "v#{VERSION}.tar.gz"
DEMO_DIR = File.join(CURRENT_FOLDER, "demo-hls.js")
Dir.chdir(CURRENT_FOLDER)
`mkdir -p "#{DEMO_DIR}"`
Dir.chdir(DEMO_DIR)
`rm -Rf *`
`wget https://github.com/dailymotion/hls.js/archive/#{FILENAME}`
`tar -xzvf #{FILENAME}`
`cp hls.js-#{VERSION}/demo/* .`
`rm -Rf hls.js-#{VERSION}`
`rm #{FILENAME}`
# In case this conflicts the patch script has to be updated coherently!
DEMO_INDEX = "#{DEMO_DIR}/index.html"
OLD_CONSTRUCTOR = 'hls = new Hls({debug:true, enableWorker : enableWorker, defaultAudioCodec : defaultAudioCodec});'
NEW_CONSTRUCTOR = 'hls = new Hls({debug:true, enableWorker : enableWorker, defaultAudioCodec : defaultAudioCodec}, {streamrootKey: "ry-v7xuywnt", debug: true});'
OLD_SCRIPT = '<script src="../dist/hls.js"></script>'
NEW_SCRIPT = '<script src="../dist/bundle/hlsjs-p2p-bundle.js"></script>'
INDEX = File.read(DEMO_INDEX)
NEW_INDEX = INDEX.gsub(OLD_CONSTRUCTOR, NEW_CONSTRUCTOR).gsub(OLD_SCRIPT, NEW_SCRIPT)
File.open(DEMO_INDEX, "w") {|file| file.puts NEW_INDEX}