awslive-poster 0.1.3 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/awslive-poster/awslive_poster.rb +29 -19
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d6dee51339f6c358928f00435ebdd580e636c170a3b2bd2ba70a134fd41f67a7
|
|
4
|
+
data.tar.gz: e4375e684cb1e8e9814ec1e2e855c40ff3ac4ec6d7ade4bf8d45d5891851412c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 600cef8d3488889dc0a2a6018bc8469730e5b970c4d243af82d1a6b2dbd76c48bfe7c9655ba075fe4ba9f0366b50a96a6122337368070b53a3858ac5fdbad5d3
|
|
7
|
+
data.tar.gz: 50a83b393fee8ffc85c14e36ef9477b4cbeaa5367c6171bb6147d4af2087b635191acb87dd8302431f61c44e17b196e31e2be8bf9d88b669b37eee3af6472c41
|
|
@@ -12,31 +12,29 @@ module Awslive
|
|
|
12
12
|
|
|
13
13
|
MAX_CHANNEL_START_TIME = 2 * 60
|
|
14
14
|
|
|
15
|
-
def initialize(channel_id)
|
|
15
|
+
def initialize(channel_id, access_key=nil , access_secret =nil, region = nil)
|
|
16
16
|
credentials = Aws::SharedCredentials.new
|
|
17
|
-
if
|
|
17
|
+
if !access_key.nil? && !access_secret.nil?
|
|
18
|
+
aws_region = region.nil? ? 'us-east-1' : region
|
|
19
|
+
puts "AWS REgion #{aws_region}"
|
|
20
|
+
@medialiveclient = Aws::MediaLive::Client.new( :access_key_id => access_key, :secret_access_key => access_secret, :region => aws_region )
|
|
21
|
+
client = Aws::S3::Client.new(access_key_id: access_key, secret_access_key: access_secret, region: 'us-east-1')
|
|
22
|
+
@s3 = Aws::S3::Resource.new(client: client)
|
|
23
|
+
elsif credentials.set?
|
|
18
24
|
@medialiveclient = Aws::MediaLive::Client.new(:credentials => credentials)
|
|
19
|
-
@s3 = Aws::S3::
|
|
25
|
+
@s3 = Aws::S3::Client.new(:credentials => credentials)
|
|
20
26
|
else
|
|
21
27
|
@medialiveclient = Aws::MediaLive::Client.new
|
|
22
|
-
@s3 = Aws::S3::
|
|
28
|
+
@s3 = Aws::S3::Client.new
|
|
23
29
|
end
|
|
24
30
|
@channel_id = channel_id
|
|
25
31
|
@last_computed_time = nil
|
|
32
|
+
|
|
26
33
|
@last_preview_url = nil
|
|
27
34
|
@interval = nil
|
|
28
35
|
end
|
|
29
36
|
|
|
30
37
|
def get_url(channel_info = nil)
|
|
31
|
-
if !@last_computed_time.nil? && !@last_preview_url.nil? && !@interval.nil?
|
|
32
|
-
threshold_gap = @interval > MAX_CHANNEL_START_TIME ? MAX_CHANNEL_START_TIME : @interval
|
|
33
|
-
current_time = Time.now.to_i
|
|
34
|
-
if current_time - @last_computed_time < threshold_gap
|
|
35
|
-
# quick fetch hence returning already computed preview URL.
|
|
36
|
-
puts "returning from cache"
|
|
37
|
-
return @last_preview_url
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
38
|
preview_url = nil
|
|
41
39
|
channel_info = @medialiveclient.describe_channel({ :channel_id => "#{@channel_id}" }) if channel_info.nil?
|
|
42
40
|
channel_state = channel_info[:state]
|
|
@@ -54,24 +52,36 @@ module Awslive
|
|
|
54
52
|
seq_counter = compute_index(start_time, @interval)
|
|
55
53
|
suffix = uri.path[1..-1]
|
|
56
54
|
bucket = @s3.bucket("#{uri.host}")
|
|
55
|
+
puts "object prefix #{suffix}#{modifier}.#{seq_counter}.jpg"
|
|
57
56
|
obj = bucket.object("#{suffix}#{modifier}.#{seq_counter}.jpg")
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
preview_url = get_presigned_url(obj) rescue nil
|
|
58
|
+
if preview_url.nil?
|
|
59
|
+
puts "seems delay in generating posters; giving a pause for fetching!!"
|
|
60
|
+
sleep (@interval / 2 ).round
|
|
61
|
+
preview_url = get_presigned_url(obj)
|
|
62
62
|
end
|
|
63
|
+
raise PosterImageDoesNotExist.new("Poster Image #{suffix}#{modifier}.#{seq_counter}.jpg Does not exist!") if preview_url.nil?
|
|
63
64
|
else
|
|
64
65
|
raise InvalidChannelState.new("Channel Need to be in running state!, current state is #{channel_state}")
|
|
65
66
|
end
|
|
66
|
-
@last_preview_url = preview_url
|
|
67
67
|
preview_url
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
+
def get_presigned_url(obj)
|
|
71
|
+
url = nil
|
|
72
|
+
puts "Fetching the object at #{Time.now}"
|
|
73
|
+
puts "Object #{obj}"
|
|
74
|
+
if obj.exists?
|
|
75
|
+
url = obj.presigned_url(:get) rescue nil
|
|
76
|
+
end
|
|
77
|
+
url
|
|
78
|
+
end
|
|
79
|
+
|
|
70
80
|
def compute_index(start_time, interval)
|
|
71
81
|
channel_start_time = Time.iso8601(start_time).to_i
|
|
72
82
|
current_time = Time.now.utc.to_i
|
|
73
83
|
diff_time = current_time - channel_start_time
|
|
74
|
-
image_index = (diff_time / interval.to_i).
|
|
84
|
+
image_index = (diff_time / interval.to_i).round
|
|
75
85
|
index = image_index.to_s.rjust(5,'0')
|
|
76
86
|
index
|
|
77
87
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: awslive-poster
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Maheshwaran G
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-06-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|