Skip to content

Instantly share code, notes, and snippets.

@ryosan-470
Created July 5, 2014 02:21
Show Gist options
  • Save ryosan-470/ca92c6a7b3d1c819acdc to your computer and use it in GitHub Desktop.
Save ryosan-470/ca92c6a7b3d1c819acdc to your computer and use it in GitHub Desktop.
録画サーバー向けスクリプトと設定

録画サーバー用スクリプト

各ファイルに関する説明

  • smb.conf

Samba向けの設定

  • autoshutdown.sh

録画終了後に自動的にシャットダウンを行う.これはcronで定期的に動かす.なおこのスクリプトが起動時に誰もSSHに接続していないかつSambaを利用していない活録画していないかつ次の予約が30分以内にない場合は次の予約時間の5分前に起動するようにしてからシャットダウンする

  • chinachuNext

要Python 3.Chinachuの次の予約時間を見てUnix Timeで返す

  • config.json

Chinachu用の設定.

#!/bin/bash -x
# chinachuで録画時間を見て自動的にシャットダウンします.
WAKEUPTIME=`python3 /usr/local/bin/chinachuNext`
# SSH ログインしているユーザーがいない
if [ `who | wc -l` -eq 0 ]; then
# 利用者がいない
if [ `smbstatus -L | wc -l` -eq 2 ];then
# 録画中または番組表更新中ではない
if [ `ps aux | grep recpt1 | wc -l` -le 1 ];then
NOW=`date +%s`
if [ `expr $WAKEUPTIME - $NOW` -gt 1800 ]; then
echo 0 > /sys/class/rtc/rtc0/wakealarm
echo $WAKEUPTIME > /sys/class/rtc/rtc0/wakealarm
# shutdown
sudo /sbin/shutdown -h now
fi
fi
fi
fi
#!/usr/bin/env python3
from urllib.request import urlopen
import json
import io
import time
class Reserves:
def __init__(self, url):
response = urlopen(url)
self.o = json.load(io.TextIOWrapper(response, response.getheader('content-type').split('charset=')[1]))
def getNextTime(self):
now = time.time()
for e in [ int(ent['start'] / 1000) for ent in self.o if ent['start'] / 1000 > now ]:
return e
if __name__ == '__main__':
url = 'http://192.168.0.100:10072/api/reserves.json'
print(Reserves(url).getNextTime() - 300)
{
"recordedDir" : "/home/chinachu/video/",
"temporaryDir": "/tmp/",
"wuiPort" : 10072,
"wuiHost" : "::",
"wuiTlsKeyPath" : null,
"wuiTlsCertPath" : null,
"wuiOpenServer" : false,
"wuiOpenPort" : 20772,
"wuiPreviewer" : true,
"wuiStreamer" : true,
"wuiFiler" : true,
"wuiConfigurator": true,
"recordedFormat": "[<date:yymmdd-HHMM>][<type><channel>]<title>.ts",
"tuners": [
{
"name" : "PT3-T1",
"isScrambling": false,
"types" : [ "GR" ],
"command" : "recpt1 --device /dev/pt3video2 --b25 --strip --sid <sid> <channel> - -"
},
{
"name" : "PT3-T2",
"isScrambling": false,
"types" : [ "GR" ],
"command" : "recpt1 --device /dev/pt3video3 --b25 --strip --sid <sid> <channel> - -"
}
],
"channels": [
{ "type": "GR", "channel": "16" },
{ "type": "GR", "channel": "21" },
{ "type": "GR", "channel": "22" },
{ "type": "GR", "channel": "23" },
{ "type": "GR", "channel": "24" },
{ "type": "GR", "channel": "25" },
{ "type": "GR", "channel": "26" },
{ "type": "GR", "channel": "27" },
{ "type": "GR", "channel": "32" }
]
}
# samba
[global]
# 文字コードの設定
dos charset = CP932
unix charset = UTF-8
# 接続元を制限
interfaces = 127.0.0.0/8, eth0
hosts allow = 127.0.0.0/8, 192.168.0.0/24
hosts deny = all
# guestアクセスの許可
security = user
map to guest = Bad User
guest account = nobody
[printing]
load printers = no
printcap name = /dev/null
printing = bsd
[video]
comment = Recorded File Directory
path = /home/chinachu/video
public = no
writable = yes
[public]
comment = Allow to access for everyone
path = /home/chinachu/video/public
public = yes
writable = yes
@ryosan-470
Copy link
Author

IPアドレスのハードコーディングよくない

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment