-
Notifications
You must be signed in to change notification settings - Fork 0
/
record_24seven.rb
40 lines (32 loc) · 1.06 KB
/
record_24seven.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
require 'open-uri'
# Fetch playlist and set up the stream
stream = 'http://rrr.sz.xlcdn.com/?account=Radio24syv&file=ENC1_iOS_ABR&type=live&service=wowza&protocol=http&output=playlist.m3u8'
pl = open(stream).read.split("\n").grep(/http/)
stream = pl.last
tld = stream.split("/")
tld.pop
tld = tld.join("/") + "/"
# Name the file the current time
filename = "#{Time.now.to_s}.aac"
outputs_file = File.open(filename, "w+")
puts "Writing to #{filename} -- Stop with Ctrl+c"
# Catch the user stopping the process
stop = false
Signal.trap("INT") do
stop = true
puts "x"
puts "Gracefully shutting down"
end
read_files = []
until stop # Until the user terminates the process
print "|"
# Find out if theres new audio bits in the stream playlist
new_files = open(stream).read.split("\n").grep(/\.aac/).select { |f| !read_files.include? f }
new_files.each do |audio|
# Append the newly fetched audio bits to the result
outputs_file << open("#{tld}/#{audio}").read
print "."
end
read_files += new_files
sleep 10 # wait 10 seconds, then do it again
end