Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Modify fetch_video_duration to use m3u8 chunks (#1814)
* Modify fetch_video_duration to use m3u8 chunks

* Remove ffprober gem
  • Loading branch information
benhalpern committed Feb 17, 2019
1 parent 5d1370c commit 5eab8d4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -58,7 +58,6 @@ gem "jquery-rails", "~> 4.3"
gem "kaminari", "~> 1.1"
gem "libhoney", "~> 1.11"
gem "liquid", "~> 4.0"
gem "ffprober", "~> 0.5"
gem "nokogiri", "~> 1.10"
gem "octokit", "~> 4.13"
gem "omniauth", "~> 1.9"
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Expand Up @@ -311,7 +311,6 @@ GEM
loofah (>= 2.0)
sax-machine (>= 1.0)
ffi (1.9.25)
ffprober (0.5.3)
figaro (1.1.1)
thor (~> 0.14)
fission (0.5.0)
Expand Down Expand Up @@ -980,7 +979,6 @@ DEPENDENCIES
fastly (~> 1.15)
fastly-rails (~> 0.8)
feedjira (~> 2.2)
ffprober (~> 0.5)
figaro (~> 1.1)
fix-db-schema-conflicts!
fog (~> 1.41)
Expand Down
9 changes: 7 additions & 2 deletions app/models/article.rb
Expand Up @@ -400,8 +400,13 @@ def video_duration_in_minutes

def fetch_video_duration
if video.present? && video_duration_in_seconds.zero?
info = Ffprober::Parser.from_url video
self.video_duration_in_seconds = info.json[:format][:duration].to_f
url = video_source_url.gsub(".m3u8", "1351620000001-200015_hls_v4.m3u8")
duration = 0
HTTParty.get(url).body.split("#EXTINF:").each do |chunk|
duration = duration + chunk.split(",")[0].to_f
end
duration
self.video_duration_in_seconds = duration
end
rescue StandardError => e
puts e.message
Expand Down

0 comments on commit 5eab8d4

Please sign in to comment.