-
-
Save aoi-s/db7ad27ea28854a84906 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
概要はこのへんにあります。 | |
http://info-student-laboratory.blogspot.com/2015/04/raspi2a-3ruby.html |
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 55; ruby agqr.rb | |
require 'yaml' | |
rtmpdump = '/usr/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 | |
schedule_yaml = YAML.load_file(schedule) | |
schedule_yaml.each do |program| | |
program_wday = program['wday'] | |
is_next_day_program = false | |
# 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 | |
is_next_day_program = true | |
else | |
# check today's wday | |
is_appropriate_wday = program_wday == today.wday | |
end | |
# appropriate time | |
if is_next_day_program | |
# 日付を跨ぐので録音開始の日付が1日ずれる | |
next_day = today + 60 * 60 * 24 | |
# today.day + 1 してたら 31 を超えるとTimeがエラー吐く | |
program_start = Time.new(next_day.year, next_day.month, next_day.day, h, m, 0) | |
else | |
program_start = Time.new(today.year, today.month, today.day, h, m, 0) | |
end | |
is_appropriate_time = (program_start - today).abs < 120 | |
length = program['length'] * 60 + 10 | |
if is_appropriate_wday && is_appropriate_time | |
title = (program['title'].to_s + '_' + today.strftime('%Y%m%d')).gsub(' ','') | |
flv_path = "#{save_dir}/flv/#{title}.flv" | |
rec_command = "#{rtmpdump} -r #{agqr_stream_url} --live -B #{length} -o #{flv_path} >/dev/null 2>&1" | |
system rec_command | |
movie = program['movie'] | |
if movie == 0 | |
# encode flv -> m4a | |
m4a_path = "#{save_dir}/mp3/#{title}.m4a" | |
m4a_encode_command = "#{ffmpeg} -y -i #{flv_path} -vn -acodec copy #{m4a_path} >/dev/null 2>&1" | |
system m4a_encode_command | |
# encode m4a -> mp3 | |
mp3_path = "#{save_dir}/mp3/#{title}.mp3" | |
mp3_encode_command = "#{ffmpeg} -i #{m4a_path} #{mp3_path} >/dev/null 2>&1" | |
system mp3_encode_command | |
# delete m4a | |
system "rm -rf #{m4a_path}" | |
end | |
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
- title: ladygo_mon | |
wday: 1 | |
time: '20:00' | |
length: 60 | |
movie: 1 | |
- title: ladygo_tue | |
wday: 2 | |
time: '20:00' | |
length: 60 | |
movie: 1 | |
- title: ladygo_wed | |
wday: 3 | |
time: '20:00' | |
length: 60 | |
movie: 1 | |
- title: ladygo_thu | |
wday: 4 | |
time: '20:00' | |
length: 60 | |
movie: 1 | |
- title: ladygo_fri | |
wday: 5 | |
time: '20:00' | |
length: 60 | |
movie: 1 | |
- title: tyoroi | |
wday: 3 | |
time: '23:00' | |
length: 30 | |
movie: 1 | |
- title: suzakinishi | |
wday: 3 | |
time: '1:00' | |
length: 30 | |
movie: 0 | |
- title: hitokana | |
wday: 水 | |
time: '21:00' | |
length: 60 | |
movie: 0 | |
- title: adlib | |
wday: 0 | |
time: '1:00' | |
length: 30 | |
movie: 0 | |
- title: remake | |
time: '1:30' | |
wday: 2 | |
length: 30 | |
movie: 0 | |
- title: five_stars_mon | |
wday: 1 | |
time: '19:30' | |
length: 30 | |
movie: 1 | |
- title: five_stars_tue | |
wday: 2 | |
time: '19:30' | |
length: 30 | |
movie: 1 | |
- title: five_stars_wed | |
wday: 3 | |
time: '19:30' | |
length: 30 | |
movie: 1 | |
- title: five_stars_thu | |
wday: 4 | |
time: '19:30' | |
length: 30 | |
movie: 1 | |
- title: five_stars_fri | |
wday: 5 | |
time: '19:30' | |
length: 30 | |
movie: 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment