Skip to content

Commit

Permalink
mc2xml integration, manual changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavion committed May 6, 2015
1 parent a481aa8 commit 2669398
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 116 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2015-05-06 1.0.9 mc2xml integration (please read manual)
Manual updated to be read
SQL refactoring and minor fixes

2015-03-28 1.0.8 EPG Chart date buttons
mc2xml support
Minor fixes
Expand Down
58 changes: 29 additions & 29 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
'cfg_server_bind_address',
'Server bind address (restart needed)',
'0.0.0.0'
],
],

[
'cfg_server_port',
Expand All @@ -61,7 +61,7 @@
"File extension for the recorded stream (default='.ts')",
'.ts'
],

[
'cfg_ffmpeg_path',
'Full path to ffmpeg for other streams support',
Expand All @@ -73,19 +73,19 @@
'Stream types, which should be forwarded to ffmpeg (space separated)',
'rtmp rtp'
],

[
'cfg_ffmpeg_params',
"Additional output arguments for ffmpeg (default: '-acodec copy -vcodec copy')",
'-acodec copy -vcodec copy'
],
],

[
'cfg_grab_time',
"Time to perform daily EPG grab on all marked channels (hh:mm format, 24h based, default '0' for manual only)",
'0'
],

[
'cfg_grab_max_duration',
"Maximal EPG scan duration per channel, [seconds] (default '60')",
Expand Down Expand Up @@ -165,40 +165,40 @@

for config in configuration:
globals()[config[0]] = config[2]
def getUser():

def getUser():
rows = sqlRun("SELECT value FROM config WHERE param='credentials'")
if rows:
return rows[0][0]
else:
return setUser("")

def setUser(userhash):
sqlRun("UPDATE config SET value = '%s' WHERE param='credentials'" % userhash)
sqlRun("UPDATE config SET value = ? WHERE param='credentials'", (userhash, ))
return userhash

def banIP(ip):
rows = sqlRun("SELECT trycount FROM blacklist WHERE ip='%s'" % ip)
rows = sqlRun("SELECT trycount FROM blacklist WHERE ip=?", (ip, ))
now = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S")
if rows:
sqlRun("UPDATE blacklist SET trycount=%s, lasttry='%s' WHERE ip='%s'" % (rows[0][0]+1, now, ip) )
sqlRun("UPDATE blacklist SET trycount=?, lasttry=? WHERE ip=?", (rows[0][0]+1, now, ip))
if rows[0][0]+1==3:
print ("IP %s has been blacklisted for for three unsuccessful login attempts" % ip)

else:
sqlRun("INSERT INTO blacklist VALUES ('%s', %s, '%s')" % (ip, 1, now) )
sqlRun("INSERT INTO blacklist VALUES (?, ?, ?)", (ip, 1, now) )

def clearIP(ip):
sqlRun("DELETE FROM blacklist WHERE ip='%s'" % ip)
sqlRun("DELETE FROM blacklist WHERE ip=?", (ip, ))

def checkIP(ip):
sqlRun("DELETE FROM blacklist WHERE julianday('now', 'localtime')-julianday(lasttry)>=2;")
rows = sqlRun("SELECT trycount FROM blacklist WHERE ip='%s'" % ip)
rows = sqlRun("SELECT trycount FROM blacklist WHERE ip=?", (ip, ))
if rows:
if rows[0][0]>=3:
return False
return False
return True

def getDict():
ret = []
for r in globals():
Expand All @@ -211,7 +211,7 @@ def loadConfig():
rows = sqlRun("SELECT param, value FROM config WHERE param<>'cfg_version'")
setConfig(rows)
return

def setConfig(attrlist = []):
for attr in attrlist:
if attr[0] in globals():
Expand All @@ -220,27 +220,27 @@ def setConfig(attrlist = []):
writeWebman(int(attr[1]))
if attr[0]=="cfg_recordpath":
if attr[1][-1]!="/" and attr[1][-1]!="\\":
if "\\" in attr[1]:
if "\\" in attr[1]:
attr=(attr[0], attr[1]+"\\")
else:
attr=(attr[0], attr[1]+"/")
globals()[attr[0]] = attr[1]
globals()[attr[0]] = attr[1]
saveConfig()


def saveConfig():
sql = ''
sql = ''
for var in getDict():
sql += "UPDATE config SET value='%s' WHERE param='%s';" % (globals()[var], var)
sql += "UPDATE config SET value='%s' WHERE param='%s';" % (globals()[var], var)
sqlRun(sql, -1, 1)

# Port changes should also be written in the Synology Webman configuration
def writeWebman(port):
def writeWebman(port):
webman = list()
lfile = open("webman/config", "rb")
for lline in lfile:
webman.append(lline)
lfile.close()
lfile.close()
lfile = open("webman/config", "wb")
for lline in webman:
pos = lline.find('"port":')
Expand All @@ -250,6 +250,6 @@ def writeWebman(port):
lfile.write(lline)
lfile.close()
print ("Port changes saved, new port: %s, please restart the software" % str(port))
return
return


Binary file modified manual.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion mylogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def write(self, message):
self.log.write(datetime.now().strftime("%Y-%m-%d %H:%M:%S") + " " + self.typ + " " + mylines + "\n")
# except Exception as ex:
# pass

def flush(self):
pass

Expand Down
2 changes: 1 addition & 1 deletion synology/INFO
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package="tvstreamrecord"
version="1.0.8"
version="1.0.9"
maintainer="Pavion"
description="Program to record TV streams. Python required. Server runs at port 8030 (changeable)"
reloadui="yes"
Expand Down
6 changes: 3 additions & 3 deletions timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def _isdst(self, dt):
stamp = _time.mktime(tt)
tt = _time.localtime(stamp)
return tt.tm_isdst > 0

Local = LocalTimezone()

def tDiff(dt2, dt1):
return (dt2 - dt1) - (Local.dst(dt2) - Local.dst(dt1))

Loading

0 comments on commit 2669398

Please sign in to comment.