Skip to content

Instantly share code, notes, and snippets.

@lan496
Created March 9, 2015 01:35
Show Gist options
  • Save lan496/c45aabe3d10129e3719f to your computer and use it in GitHub Desktop.
Save lan496/c45aabe3d10129e3719f to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import json
import datetime
import os
def loadSchedule():
f = open('schedule.json','r')
pDict = json.load(f)
f.close()
d = datetime.datetime.now()
for key,p in pDict.items():
#Mon=0,Sun=6
if d.weekday() == p["date"]["wday"] and p["record"]:
pTime = datetime.datetime(d.year,d.month,d.day,
p["date"]["hour"],p["date"]["minute"],0)
dd = pTime-d
if abs(dd.total_seconds()) < 60000:
prg = program(key,p)
prg.record()
def stationOptions(station):
st = {
'agqr': '-r "rtmpe://fms2.uniqueradio.jp/" -y "aandg22" -a "?rtmp://fms-base1.mitene.ad.jp/agqr/" -v'
}
return st[station]
class program(object):
def __init__(self,name,p):
os.system('chmod +x')
self.name = name + datetime.datetime.today().strftime('%Y%m%d')
self.options = stationOptions(p["station"])
self.rTime = p["date"]["time"]
self.movie = p["movie"]
def record(self):
rtmpdump = '~/agqr/rtmpdump/rtmpdump' ####
radio_dir = 'radio' ####
rccmd = rtmpdump + ' ' + self.options + ' --stop ' + str(self.rTime) \
+ ' -o ' + radio_dir + '/' + self.name + '.flv'
os.system(rccmd)
ffmpeg='ffmpeg' ####
if self.movie:
cvcmd = ffmpeg + ' -i ' + radio_dir + '/' + self.name + '.flv ' \
+ radio_dir + '/' + self.name + '.mp4'
else:
cvcmd = ffmpeg + ' -i ' + radio_dir + '/' + self.name + '.flv ' \
+ radio_dir + '/' + self.name + '.mp3'
os.system(cvcmd)
rmcmd = 'rm ' + radio_dir + '/' +self.name + '.flv'
os.system(rmcmd)
if __name__=='__main__':
loadSchedule()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment