Skip to content

Commit

Permalink
Splitting EPG deltas
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavion committed Aug 25, 2018
1 parent 6085329 commit c0eef94
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
2018-08-25 1.3.5 Adding more placeholders, delta before and after an EPG record

2018-03-11 1.3.4 Failsafe delta for ffmpeg: do not restart if but X seconds remain

2018-02-27 1.3.3 Extending TV Browser support (plugin v.1.0.3 required)
Expand Down
10 changes: 8 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@
],

[
'cfg_delta_for_epg',
'Lenghten an EPG-record (delta before and after), [minutes]',
'cfg_delta_before_epg',
'Lenghten an EPG-record (delta before), [minutes]',
3
],

[
'cfg_delta_after_epg',
'Lenghten an EPG-record (delta after), [minutes]',
3
],

Expand Down
16 changes: 9 additions & 7 deletions js/tvstreamrecord.basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,14 @@ function initIcons() {
// $("#dialog_content").html (data[i][7]);
var dat_v = data[i][3].split(" ")[1].substr(0,5);
var dat_b = data[i][4].split(" ")[1].substr(0,5);
var delta = $("#delta_for_epg").attr("delta");
var delta_before = $("#delta_before_epg").attr("delta");
var delta_after = $("#delta_after_epg").attr("delta");
$( "#dialog_content" ).html ("<b>" + data[i][1] + ": "+dat_v + " - " + dat_b + "</b><BR><BR>" + data[i][2].replace(/\n/g, '<BR>'));
recName = data[i][1];
recChannel = data[i][0];
recDate = data[i][3].split(" ")[0];
recStart = new Date( parseDate(data[i][3]).valueOf() - delta*60000 ).toTimeString().substring(0, 5);
recEnd = new Date( parseDate(data[i][4]).valueOf() + delta*60000 ).toTimeString().substring(0, 5);
recStart = new Date( parseDate(data[i][3]).valueOf() - delta_before*60000 ).toTimeString().substring(0, 5);
recEnd = new Date( parseDate(data[i][4]).valueOf() + delta_after*60000 ).toTimeString().substring(0, 5);

$( "#dialog_record_from_epg" ).dialog( "open" );
event.preventDefault();
Expand Down Expand Up @@ -1058,9 +1059,10 @@ $(function() {
recName = $(this).text();
recChannel = $(this).attr("cid");
recDate = $(this).attr("at").split(" ")[0];
var delta = $("#delta_for_epg").attr("delta");
recStart = new Date( parseDate($(this).attr("at")).valueOf() - delta*60000 ).toTimeString().substring(0, 5);
recEnd = new Date( parseDate($(this).attr("till")).valueOf() + delta*60000 ).toTimeString().substring(0, 5);
var delta_before = $("#delta_before_epg").attr("delta");
var delta_after = $("#delta_after_epg").attr("delta");
recStart = new Date( parseDate($(this).attr("at")).valueOf() - delta_before*60000 ).toTimeString().substring(0, 5);
recEnd = new Date( parseDate($(this).attr("till")).valueOf() + delta_after*60000 ).toTimeString().substring(0, 5);
$( "#dialog_record_from_epg" ).dialog( "open" );
$(this).removeClass("ui-selected");
}
Expand Down Expand Up @@ -1135,7 +1137,7 @@ $(function() {
$( "#configtabs" ).tabs().addClass( "ui-tabs-vertical ui-helper-clearfix" );
$( "#configtabs li" ).removeClass( "ui-corner-top" ).addClass( "ui-corner-left" );

$("#cfg_purgedelta,#cfg_delta_for_epg,#cfg_grab_max_duration,#cfg_retry_count,#cfg_failsafe_delta,#cfg_xmltvtimeshift").spinner();
$("#cfg_purgedelta,#cfg_delta_before_epg,#cfg_delta_after_epg,#cfg_grab_max_duration,#cfg_retry_count,#cfg_failsafe_delta,#cfg_xmltvtimeshift").spinner();
$("#cfg_grab_zoom").spinner( { step: 0.1 } );
$("#cfg_epg_max_events").spinner( { step: 1000 } );

Expand Down
3 changes: 2 additions & 1 deletion lang/tvstreamrecord.dummy.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"Interface language (default='english')": "",
"Date/time locale (default='default')": "",

"Lenghten an EPG-record (delta before and after), [minutes]": "",
"Lenghten an EPG-record (delta before), [minutes]": "",
"Lenghten an EPG-record (delta after), [minutes]": "",
"Enable XMLTV import": "",
"Initial path for an XMLTV import": "",
"Time shift for XMLTV data (in hours)": "",
Expand Down
3 changes: 2 additions & 1 deletion lang/tvstreamrecord.german.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"Interface language (default='english')": "Sprache des Webinterfaces (Vorgabe='english')",
"Date/time locale (default='default')": "Lokalisierung für Datum / Uhrzeit (Vorgabe='default')",

"Lenghten an EPG-record (delta before and after), [minutes]": "EPG Aufnahme verlängern um (vor und nach) [Minuten]",
"Lenghten an EPG-record (delta before), [minutes]": "EPG Aufnahme verlängern um (vor) [Minuten]",
"Lenghten an EPG-record (delta after), [minutes]": "EPG Aufnahme verlängern um (nach) [Minuten]",
"Enable XMLTV import": "XMLTV-Import einschalten",
"Initial path for an XMLTV import": "Suchpfad für XMLTV-Import",
"Time shift for XMLTV data (in hours)": "Zeitverschiebung für die XMLTV-Daten (in Stunden)",
Expand Down
3 changes: 2 additions & 1 deletion lang/tvstreamrecord.russian.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"Interface language (default='english')": "Язык интерфейса (по умолчанию=english)",
"Date/time locale (default='default')": "Локализация времени и даты (по умолчанию=default)",

"Lenghten an EPG-record (delta before and after), [minutes]": "Продлевать EPG записи на (до и после) [мин.])",
"Lenghten an EPG-record (delta before), [minutes]": "Продлевать EPG записи на (до) [мин.])",
"Lenghten an EPG-record (delta after), [minutes]": "Продлевать EPG записи на (после) [мин.])",
"Enable XMLTV import": "Включить XMLTV-импорт",
"Initial path for an XMLTV import": "Адрес для XMLTV-импорта",
"Time shift for XMLTV data (in hours)": "Сдвиг во времени данных XMLTV (в часах)",
Expand Down
3 changes: 3 additions & 0 deletions sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def sqlCreateAll(version):
sql += "UPDATE config SET value='-loglevel fatal ' || value WHERE param = 'cfg_ffmpeg_params' and not lower(value) LIKE '%loglevel%';"
if oldver < '1.3.2':
sql += "ALTER TABLE records ADD COLUMN uniqueid TEXT;"
if oldver < '1.3.5':
sql += "INSERT OR IGNORE INTO config VALUES ('cfg_delta_before_epg', '', (SELECT value FROM config WHERE param='cfg_delta_for_epg'));"
sql += "UPDATE config SET param='cfg_delta_after_epg' WHERE param='cfg_delta_for_epg';"

if oldver > version:
print ("Critical error: Version mismatch!!!")
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.3.4b"
version="1.3.5"
maintainer="Pavion"
description="Program to record TV streams. Python required. Server runs at port 8030 (changeable)"
reloadui="yes"
Expand Down
23 changes: 12 additions & 11 deletions tvstreamrecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def total(timedelta):
localdate = "%d.%m.%Y"
dayshown = datetime.combine(date.today(), time.min)
shutdown = False
version = '1.3.4b'
version = '1.3.5'

@route('/live/<filename>')
def server_static9(filename):
Expand Down Expand Up @@ -696,7 +696,7 @@ def epg_s():
for row in rows:
cid=row[1]
rtemp = list()
c_rows=sqlRun("SELECT g_title, g_start, g_stop, g_desc, guide.rowid, (records.renabled is not null and records.renabled = 1) FROM guide LEFT JOIN records ON records.cid=? AND datetime(guide.g_start, '-%s minutes')=records.rvon and datetime(guide.g_stop, '+%s minutes')=records.rbis WHERE (date(g_start)=date(?) OR date(g_stop)=date(?)) AND datetime(g_stop, '+60 minutes')>datetime('now', 'localtime') AND g_id=? ORDER BY g_start" % (config.cfg_delta_for_epg, config.cfg_delta_for_epg), (cid, todaysql, todaysql, row[0]))
c_rows=sqlRun("SELECT g_title, g_start, g_stop, g_desc, guide.rowid, (records.renabled is not null and records.renabled = 1) FROM guide LEFT JOIN records ON records.cid=? AND datetime(guide.g_start, '-%s minutes')=records.rvon and datetime(guide.g_stop, '+%s minutes')=records.rbis WHERE (date(g_start)=date(?) OR date(g_stop)=date(?)) AND datetime(g_stop, '+60 minutes')>datetime('now', 'localtime') AND g_id=? ORDER BY g_start" % (config.cfg_delta_before_epg, config.cfg_delta_after_epg), (cid, todaysql, todaysql, row[0]))
for event in c_rows:

d_von = datetime.strptime(event[1],"%Y-%m-%d %H:%M:%S")
Expand All @@ -716,12 +716,12 @@ def epg_s():
if x >= 0 and w > 0:
rtemp.append ([cid, x/totalwidth*100.0*widthq, w/totalwidth*100.0*widthq, event[0], d_von, d_bis, event[3], event[4], row[2], event[5]])
ret.append(rtemp)
return internationalize(template('epgchart', curr=datetime.strftime(d_von, "%Y-%m-%d"), rowss=ret, zoom=config.cfg_grab_zoom, rows2=sqlRun('SELECT cid, cname FROM channels where cenabled=1 ORDER BY cid'), delta=config.cfg_delta_for_epg))
return internationalize(template('epgchart', curr=datetime.strftime(d_von, "%Y-%m-%d"), rowss=ret, zoom=config.cfg_grab_zoom, rows2=sqlRun('SELECT cid, cname FROM channels where cenabled=1 ORDER BY cid'), deltab=config.cfg_delta_before_epg, deltaa=config.cfg_delta_after_epg))

@route('/epglist')
@route('/epglist&<keyword>')
def epglist_s(keyword=''):
return internationalize(template('epglist', keyword_for_epg=keyword, listmode=config.cfg_switch_epglist_mode, rows2=sqlRun('SELECT cid, cname FROM channels where cenabled=1 ORDER BY cid'), delta=config.cfg_delta_for_epg))
return internationalize(template('epglist', keyword_for_epg=keyword, listmode=config.cfg_switch_epglist_mode, rows2=sqlRun('SELECT cid, cname FROM channels where cenabled=1 ORDER BY cid'), deltab=config.cfg_delta_before_epg, deltaa=config.cfg_delta_after_epg))

@route('/epglist_getter')
def epglist_getter():
Expand All @@ -745,15 +745,15 @@ def epglist_getter():
if iSearch and iSearch!="":
sWhere = "AND (guide_chan.g_name LIKE '%" + iSearch + "%' OR guide.g_title LIKE '%" + iSearch + "%' OR guide.g_desc LIKE '%" + iSearch + "%')"

query = "SELECT guide_chan.g_name, guide.g_title, guide.g_desc, guide.g_start, guide.g_stop, (records.renabled is not null and records.renabled = 1), guide.rowid FROM guide INNER JOIN guide_chan ON guide.g_id = guide_chan.g_id INNER JOIN channels ON channels.cname=guide_chan.g_name LEFT JOIN records ON records.cid=channels.cid AND datetime(guide.g_start, '-%s minutes')=records.rvon and datetime(guide.g_stop, '+%s minutes')=records.rbis WHERE datetime(guide.g_stop)>datetime('now', 'localtime') AND channels.cenabled<>0 %s %s %s" % (config.cfg_delta_for_epg, config.cfg_delta_for_epg, sWhere, sOrder, sLimit)
countquery = "SELECT COUNT(guide.g_start) FROM guide INNER JOIN guide_chan ON guide.g_id = guide_chan.g_id INNER JOIN channels ON channels.cname=guide_chan.g_name LEFT JOIN records ON records.cid=channels.cid AND datetime(guide.g_start, '-%s minutes')=records.rvon and datetime(guide.g_stop, '+%s minutes')=records.rbis WHERE datetime(guide.g_stop)>datetime('now', 'localtime') AND channels.cenabled<>0 %s" % (config.cfg_delta_for_epg, config.cfg_delta_for_epg, sWhere)
query = "SELECT guide_chan.g_name, guide.g_title, guide.g_desc, guide.g_start, guide.g_stop, (records.renabled is not null and records.renabled = 1), guide.rowid FROM guide INNER JOIN guide_chan ON guide.g_id = guide_chan.g_id INNER JOIN channels ON channels.cname=guide_chan.g_name LEFT JOIN records ON records.cid=channels.cid AND datetime(guide.g_start, '-%s minutes')=records.rvon and datetime(guide.g_stop, '+%s minutes')=records.rbis WHERE datetime(guide.g_stop)>datetime('now', 'localtime') AND channels.cenabled<>0 %s %s %s" % (config.cfg_delta_before_epg, config.cfg_delta_after_epg, sWhere, sOrder, sLimit)
countquery = "SELECT COUNT(guide.g_start) FROM guide INNER JOIN guide_chan ON guide.g_id = guide_chan.g_id INNER JOIN channels ON channels.cname=guide_chan.g_name LEFT JOIN records ON records.cid=channels.cid AND datetime(guide.g_start, '-%s minutes')=records.rvon and datetime(guide.g_stop, '+%s minutes')=records.rbis WHERE datetime(guide.g_stop)>datetime('now', 'localtime') AND channels.cenabled<>0 %s" % (config.cfg_delta_before_epg, config.cfg_delta_after_epg, sWhere)
count = sqlRun(countquery)
if count:
totalrows = count[0][0]

rows=sqlRun(query)
else: # Client-side processing
rows=sqlRun("SELECT guide_chan.g_name, guide.g_title, guide.g_desc, guide.g_start, guide.g_stop, (records.renabled is not null and records.renabled = 1), guide.rowid FROM guide INNER JOIN guide_chan ON guide.g_id = guide_chan.g_id INNER JOIN channels ON channels.cname=guide_chan.g_name LEFT JOIN records ON records.cid=channels.cid AND datetime(guide.g_start, '-%s minutes')=records.rvon and datetime(guide.g_stop, '+%s minutes')=records.rbis WHERE datetime(guide.g_stop)>datetime('now', 'localtime') AND channels.cenabled<>0 ORDER BY g_start LIMIT %s;" % (config.cfg_delta_for_epg, config.cfg_delta_for_epg, config.cfg_epg_max_events))
rows=sqlRun("SELECT guide_chan.g_name, guide.g_title, guide.g_desc, guide.g_start, guide.g_stop, (records.renabled is not null and records.renabled = 1), guide.rowid FROM guide INNER JOIN guide_chan ON guide.g_id = guide_chan.g_id INNER JOIN channels ON channels.cname=guide_chan.g_name LEFT JOIN records ON records.cid=channels.cid AND datetime(guide.g_start, '-%s minutes')=records.rvon and datetime(guide.g_stop, '+%s minutes')=records.rbis WHERE datetime(guide.g_stop)>datetime('now', 'localtime') AND channels.cenabled<>0 ORDER BY g_start LIMIT %s;" % (config.cfg_delta_before_epg, config.cfg_delta_after_epg, config.cfg_epg_max_events))

for row in rows:
retlist.append([row[0], row[1], row[2], row[3], row[4], row[5], row[6]])
Expand Down Expand Up @@ -870,7 +870,7 @@ def records_p():

@post('/createepg')
def createepg():
sqlRun("INSERT INTO records SELECT guide.g_title, channels.cid, datetime(guide.g_start, '-%s minutes'), datetime(guide.g_stop, '+%s minutes'), 1, 0, '' FROM guide, guide_chan, channels WHERE guide.g_id = guide_chan.g_id AND channels.cname = guide_chan.g_name AND guide.rowid=? GROUP BY datetime(guide.g_start, '-%s minutes')" % (config.cfg_delta_for_epg, config.cfg_delta_for_epg, config.cfg_delta_for_epg), (request.forms.ret, ))
sqlRun("INSERT INTO records SELECT guide.g_title, channels.cid, datetime(guide.g_start, '-%s minutes'), datetime(guide.g_stop, '+%s minutes'), 1, 0, '' FROM guide, guide_chan, channels WHERE guide.g_id = guide_chan.g_id AND channels.cname = guide_chan.g_name AND guide.rowid=? GROUP BY datetime(guide.g_start, '-%s minutes')" % (config.cfg_delta_before_epg, config.cfg_delta_after_epg, config.cfg_delta_before_epg), (request.forms.ret, ))
setRecords()
redirect("/records")
return "null"
Expand All @@ -897,9 +897,10 @@ def create_tvb():
if rows:
cid = rows[0][0]
print ("Channel %s was found with CID %s, creating record" % (sender, cid))
deltaepg = timedelta(minutes=int(config.cfg_delta_for_epg))
d_von = d_von - deltaepg
d_bis = d_bis + deltaepg
deltaepgbefore = timedelta(minutes=int(config.cfg_delta_before_epg))
deltaepgafter = timedelta(minutes=int(config.cfg_delta_after_epg))
d_von = d_von - deltaepgbefore
d_bis = d_bis + deltaepgafter
sqlRun("INSERT INTO records VALUES (?, ?, ?, ?, 1, 0, ?)", (recname, cid, d_von, d_bis, uniqueid))
setRecords()
return "true"
Expand Down
3 changes: 2 additions & 1 deletion views/config.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
</tr>
</thead>
<tbody>
<tr><td>§Lenghten an EPG-record (delta before and after), [minutes]§</td><td><input id="cfg_delta_for_epg" /></td></tr>
<tr><td>§Lenghten an EPG-record (delta before), [minutes]§</td><td><input id="cfg_delta_before_epg" /></td></tr>
<tr><td>§Lenghten an EPG-record (delta after), [minutes]§</td><td><input id="cfg_delta_after_epg" /></td></tr>
<tr><td>§Enable XMLTV import§</td><td><input type="checkbox" class="switch icons" id="cfg_switch_xmltv_auto" /></td></tr>
<tr><td>§Initial path for an XMLTV import§</td><td><input type="text" class="text ui-widget-content ui-corner-all" id="cfg_xmltvinitpath" value="" autocomplete="off" /></td></tr>
<tr><td>§Time shift for XMLTV data (in hours)§</td><td><input id="cfg_xmltvtimeshift" /></td></tr>
Expand Down
3 changes: 2 additions & 1 deletion views/epgchart.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
%include ('create.tpl')
<div id="delta_for_epg" delta="{{delta}}"></div>
<div id="delta_before_epg" delta="{{deltab}}"></div>
<div id="delta_after_epg" delta="{{deltaa}}"></div>
<div id="users-contain" class="ui-widget">
<div id="chartheader">
<h1>
Expand Down
3 changes: 2 additions & 1 deletion views/epglist.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
%include ('create.tpl')
<div id="keyword_for_epg" keyword_for_epg="{{keyword_for_epg}}"></div>
<div id="delta_for_epg" delta="{{delta}}"></div>
<div id="delta_before_epg" delta="{{deltab}}"></div>
<div id="delta_after_epg" delta="{{deltaa}}"></div>
<div id="listmode" value="{{listmode}}"></div>
<div id="users-contain" class="ui-widget">
<h1><div class="lefty">§Electronic Program Guide§ - §list view§</div>
Expand Down

0 comments on commit c0eef94

Please sign in to comment.