fosdem-recorder.rb/fosdem-recorder
2021-02-07 14:35:19 +01:00

94 lines
2 KiB
Ruby
Executable file

#!/usr/bin/env ruby
# frozen_string_literal: true
require 'mechanize'
require 'time'
require 'colorize'
require 'thor'
# Fosdem Cli - Download and cut streams video
class FosdemCli < Thor
desc 'info URL', 'Get information about URL'
def info(url)
meta = _get_meta(url)
puts "* title = #{meta[:title]}"
puts "* start = #{meta[:start_str]}"
puts "* stop = #{meta[:stop_str]}"
puts "* diff = #{meta[:duration_str]}"
puts "* url = #{stream_url}"
end
desc 'download URL', 'Download conference described at URL'
def download(url)
meta = _get_meta(url)
cmd = "Command: echo ffmpeg -i #{meta[:stream_url]} -c copy -t #{meta[:duration_str]} \"#{meta[:title_sane]}.mp4\" | at #{meta[:start_str]}"
puts cmd.yellow
system cmd
end
private
def _get_meta(url)
mechanize = Mechanize.new
page = mechanize.get(url)
title = page.title
title_sane =
title
.gsub(/[^a-zA-Z0-9]/, '-')
.gsub(/--*/, '-')
.gsub(/-$/, '')
.gsub(/^-/, '')
play_start_str =
page
.at('.side-box .icon-play')
.parent
.at('.value-title')
.text
.strip
play_start = Time.parse(play_start_str)
play_stop_str =
page
.at('.side-box .icon-stop')
.parent
.at('.value-title')
.text.strip
play_stop = Time.parse(play_stop_str)
duration = (play_stop - play_start) / 3600
duration_h = duration.to_i
duration_m = ((duration - duration_h) * 60).to_i
duration_str = '%02d:%02d:00' % [duration_h, duration_m]
stream_page =
page
.links
.select { |link| link.href =~ /live.fosdem.org/ }
.first
.href
stream_url =
stream_page
.gsub(%r{.*watch/}, 'https://stream.fosdem.org/')
.gsub(/$/, '.m3u8')
{
title: title,
title_sane: title_sane,
stream_url: stream_url,
start_str: play_start_str,
stop_str: play_stop_str,
duration_str: duration_str
}
end
end
FosdemCli.start(ARGV)
# https://stream.fosdem.org/dpostgresql.m3u8