-
-
Save wakuteka/29460c3f11a176798b5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# record AGQR | |
# usage: use with crontab | |
# 29,59 * * * sleep 40; ruby agqr.rb | |
require 'yaml' | |
rtmpdump = '/usr/local/bin/rtmpdump' | |
ffmpeg = '/usr/bin/ffmpeg' | |
agqr_stream_url = 'rtmp://fms-base1.mitene.ad.jp/agqr/aandg22' | |
current = File.dirname(File.expand_path(__FILE__)) | |
save_dir = "#{current}/../data/" | |
schedule = "#{current}/schedule.yaml" | |
today = Time.now | |
WDAY = '日月火水木金土'.split(//).each_with_index.inject({}){|s, pair| | |
elem, index = pair | |
s.merge!(elem => index) | |
} | |
schedule_yaml = YAML.load_file(schedule) | |
schedule_yaml.each do |program| | |
# should record | |
should_record = program['record'] | |
program_wday = WDAY[program['wday']] | |
# appropriate wday | |
h, m = program['time'].split(':').map(&:to_i) | |
if h == 0 && m == 0 | |
# check next day's wday | |
# if today.wday is 6 (Sat), next_wday is 0 (Sun) | |
next_wday = today.wday == 6 ? 0 : today.wday + 1 | |
is_appropriate_wday = program_wday == next_wday | |
else | |
# check today's wday | |
is_appropriate_wday = program_wday == today.wday | |
end | |
# appropriate time | |
program_start = Time.local(today.year, today.month, today.day, h, m, 0) | |
is_appropriate_time = (program_start - today).abs < 120 | |
length = program['length'] * 60 + 15 | |
if should_record && is_appropriate_wday && is_appropriate_time | |
title = (program['title'] + '_' + today.strftime('%Y%m%d')).gsub(' ','') | |
flv_path = "#{save_dir}/#{title}.flv" | |
mp4_path = "#{save_dir}/#{title}.mp4" | |
rec_command = "#{rtmpdump} -r #{agqr_stream_url} --live -B #{length} -o #{flv_path}" | |
encode_command = "#{ffmpeg} -y -i #{flv_path} -vcodec copy -acodec copy #{mp4_path}" | |
system rec_command | |
system encode_command | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- record: true | |
title: ladygo_mon | |
wday: 月 | |
time: '17:00' | |
length: 60 | |
- record: true | |
title: ladygo_tue | |
wday: 火 | |
time: '17:00' | |
length: 60 | |
- record: true | |
title: ladygo_wed | |
wday: 水 | |
time: '17:00' | |
length: 60 | |
- record: true | |
title: ladygo_thu | |
wday: 木 | |
time: '17:00' | |
length: 60 | |
- record: true | |
title: ladygo_fri | |
wday: 金 | |
time: '17:00' | |
length: 60 | |
- record: true | |
title: mu_n | |
wday: 月 | |
time: '22:00' | |
length: 60 | |
- record: true | |
title: it_kakumei | |
wday: 火 | |
time: '21:00' | |
length: 30 | |
- record: true | |
title: free_style | |
wday: 火 | |
time: '21:00' | |
length: 30 | |
- record: true | |
title: shinshu | |
wday: 火 | |
time: '23:30' | |
length: 30 | |
- record: true | |
title: tyoroi | |
wday: 水 | |
time: '23:00' | |
length: 30 | |
- record: true | |
title: suzakinishi | |
wday: 水 | |
time: '1:00' | |
length: 30 | |
- record: true | |
title: kokoro | |
wday: 日 | |
time: '0:00' | |
length: 30 | |
- record: true | |
title: alamode | |
wday: 日 | |
time: '21:30' | |
length: 30 | |
- record: true | |
title: seisyun | |
wday: 日 | |
time: '23:30' | |
length: 30 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment