fosdem-recorder.cr/src/event_page.cr

74 lines
1.9 KiB
Crystal

module FosdemRecorder
# Fosdem Cli - Download and cut streams video
class EventPage
def self.get_meta(url)
puts "Loading data from #{url}".colorize.fore(:yellow)
mechanize = Mechanize.new
begin
page = mechanize.get(url)
rescue ex : Socket::Addrinfo::Error
STDERR.puts "ERROR: #{ex.message}"
exit 1
end
# body_class = page.at('body').attr('class')
# if body_class != 'schedule-event'
# STDERR.puts "ERROR: Not an event schedule page!"
# exit 1
# end
# puts body_class
title = page.title
title_sanitized =
title
.gsub(/[^a-zA-Z0-9]/, "-")
.gsub(/--*/, "-")
.gsub(/-$/, "")
.gsub(/^-/, "")
play_start_str =
page
.css(".side-box .icon-play").first.parent
.try &.css(".value-title").first["title"].strip
play_start_str = "" if play_start_str.nil?
location = Time::Location.load("Europe/Brussels")
# play_start = Time.parse(play_start_str, "%H:%S", location)
play_start = Time.parse_rfc3339(play_start_str) #, location)
play_stop_str =
page
.css(".side-box .icon-stop").first.parent
.try &.css(".value-title").first["title"].strip
play_stop_str = "" if play_stop_str.nil?
# play_stop = Time.parse(play_stop_str, "%H:%S", location)
play_stop = Time.parse_rfc3339(play_stop_str)
stream_page =
page
.links
.select { |link| link.href =~ /live.fosdem.org/ }
.first?
.try &.href
stream_url =
stream_page
.try &.gsub(%r{.*watch/}, "https://stream.fosdem.org/")
.gsub(/$/, ".m3u8")
meta = MetaData.new(
title: title,
title_sanitized: title_sanitized,
stream_url: stream_url,
event_start: play_start,
event_stop: play_stop,
)
end
end
end