Last active
April 17, 2016 14:00
-
-
Save mhermans/4524410 to your computer and use it in GitHub Desktop.
Script: write upcoming Tvheadend recording start dates to Synology power scheduler
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
#!/usr/bin/env python | |
import datetime, os, json | |
# Write upcoming Tvheadend recording start dates to Synology power scheduler | |
# i.e. turn on your Synology so Tvheadend can record. | |
# Usage: ./pvr_poweron.py > /etc/power_sched.conf (or use cron) | |
# location of Tvheadend PVR-schedule files: | |
PVR_DIR="/usr/local/tvheadend/var/dvr/log" | |
# Day-code constants for power scheduler Monday-Sunday: | |
DAYS = (16908288, 17039360, 17301504, 17825792, 18874368, 20971520, 16842752) | |
# read in all the recording start dates | |
start_dates = [] | |
for f in os.listdir(PVR_DIR): | |
f = open(os.path.join(PVR_DIR,f), 'r') | |
data = f.read() | |
f.close() | |
data = json.loads(data) | |
start_dates.append(int(data.get('start'))) | |
# print out config file, with upcoming dates | |
print '[Power On schedule]' | |
for date in start_dates: | |
d = datetime.datetime.fromtimestamp(date) | |
n = datetime.datetime.now() | |
#print d.isoformat() | |
day_constant = DAYS[d.weekday()] | |
time_offset = 256*d.hour + d.minute | |
time_code = day_constant + time_offset | |
if d > n: print time_code | |
print '[Power Off schedule]' |
Hi,
thanks for sharing - works great here and it's very usefull.
I just add two lines to handle PVR schedules within the next 7 days only, to avoid starts within the current time periode of the Power Scheduler that are related to schedules from onther upcoming weeks.
for date in start_dates:
date = date - 600
d = datetime.datetime.fromtimestamp(date)
n = datetime.datetime.now()
e = n + datetime.timedelta(days=6)
#print d.isoformat()
day_constant = DAYS[d.weekday()]
time_offset = 256*d.hour + d.minute
time_code = day_constant + time_offset
if d > n and d < e: print time_code
print '[Power Off schedule]'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: enkel data voor deze week in rekening brengen.