From 5b6f8bb13db064666d0eab12f5da4433cef1f0fe Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Sun, 7 Feb 2021 14:35:19 +0100 Subject: [PATCH] Initial import --- .gitignore | 2 ++ Gemfile | 13 +++++++ Gemfile.lock | 48 +++++++++++++++++++++++++ fosdem-recorder | 94 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100755 fosdem-recorder diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d3c4db --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.mp4 +*.part diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..3422c4a --- /dev/null +++ b/Gemfile @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } + +# gem "rails" + +gem "thor", "~> 1.1" + +gem "mechanize", "~> 2.7" + +gem "colorize", "~> 0.8.1" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..18768d5 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,48 @@ +GEM + remote: https://rubygems.org/ + specs: + colorize (0.8.1) + connection_pool (2.2.3) + domain_name (0.5.20190701) + unf (>= 0.0.5, < 1.0.0) + http-cookie (1.0.3) + domain_name (~> 0.5) + mechanize (2.7.7) + domain_name (~> 0.5, >= 0.5.1) + http-cookie (~> 1.0) + mime-types (>= 1.17.2) + net-http-digest_auth (~> 1.1, >= 1.1.1) + net-http-persistent (>= 2.5.2) + nokogiri (~> 1.6) + ntlm-http (~> 0.1, >= 0.1.1) + webrick (~> 1.7) + webrobots (>= 0.0.9, < 0.2) + mime-types (3.3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2020.1104) + mini_portile2 (2.5.0) + net-http-digest_auth (1.4.1) + net-http-persistent (4.0.1) + connection_pool (~> 2.2) + nokogiri (1.11.1) + mini_portile2 (~> 2.5.0) + racc (~> 1.4) + ntlm-http (0.1.1) + racc (1.5.2) + thor (1.1.0) + unf (0.1.4) + unf_ext + unf_ext (0.0.7.7) + webrick (1.7.0) + webrobots (0.1.2) + +PLATFORMS + ruby + +DEPENDENCIES + colorize (~> 0.8.1) + mechanize (~> 2.7) + thor (~> 1.1) + +BUNDLED WITH + 2.1.2 diff --git a/fosdem-recorder b/fosdem-recorder new file mode 100755 index 0000000..e766640 --- /dev/null +++ b/fosdem-recorder @@ -0,0 +1,94 @@ +#!/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 +