-
Notifications
You must be signed in to change notification settings - Fork 0
/
webcam-resolver.rb
49 lines (42 loc) · 1.21 KB
/
webcam-resolver.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
44
45
46
47
require 'sinatra'
require 'json'
require 'httparty'
use Rack::Logger
helpers do
def logger
request.logger
end
end
def get_camera_url(provider, camera)
case provider
when 'surfchex'
markup = HTTParty.get("https://www.surfchex.com/cams/#{camera}/").body
markup.scan(/src: \"(https:\/\/\w+\.streamlock.*\.m3u8)\"/m).flatten.first
when 'ipcamlive'
stream_data = JSON.parse(HTTParty.get("https://www.ipcamlive.com/ajax/getcamerastreamstate.php?cameraalias=#{camera}").body)
logger.info "Stream data: #{stream_data}"
"#{stream_data['details']['address']}streams/#{stream_data['details']['streamid']}/stream.m3u8"
end
end
get '/' do
'Get a camera stream URL by visiting /camera/:provider/:camera. For example, /camera/ipcamlive/1234567890.\n\n' +
'Stream from the camera by visiting /stream/:provider/:camera. For example, /stream/ipcamlive/1234567890.'
end
get '/camera/:provider/:camera' do
url = get_camera_url(params['provider'], params['camera'])
if url
url
else
status 404
'Camera not found'
end
end
get '/stream/:provider/:camera' do
url = get_camera_url(params['provider'], params['camera'])
if url
redirect url
else
status 404
'Camera not found'
end
end