-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathautoplaywith.py
105 lines (89 loc) · 4.19 KB
/
autoplaywith.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# -*- coding: utf-8 -*-
#
# Copyright (C) 2012 Tommy Winther
# http://tommy.winther.nu
#
# Modified for FTV Guide (09/2014 onwards)
# by Thomas Geppert [bluezed] - [email protected]
#
# Modified for TV Guide Fullscreen (2016)
# by primaeval - [email protected]
#
# This Program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This Program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this Program; see the file LICENSE.txt. If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
# http://www.gnu.org/copyleft/gpl.html
#
import datetime,time
import os
import xbmc
import xbmcgui, xbmcaddon, xbmcvfs
import source as src
import re
from strings import *
ADDON = xbmcaddon.Addon(id='script.tvguide.fullscreen')
class Autoplaywith(object):
def __init__(self, database, addonPath):
"""
@param database: source.Database
"""
self.database = database
self.addonPath = addonPath
self.icon = os.path.join(self.addonPath, 'icon.png')
def createAlarmClockName(self, programTitle, startTime):
return 'tvguide-%s-%s' % (programTitle, startTime)
def scheduleAutoplaywiths(self):
for program in self.database.getFullAutoplaywiths():
self._scheduleAutoplaywith(program.channel.id, program.title, program.startDate, program.endDate)
def _scheduleAutoplaywith(self, channelId, programTitle, startTime, endTime):
t = startTime - datetime.datetime.now()
timeToAutoplaywith = ((t.days * 86400) + t.seconds) / 60
if timeToAutoplaywith < 0:
return
#timeToAutoplaywith = 1
name = self.createAlarmClockName(programTitle, startTime)
timestamp = time.mktime(startTime.timetuple())
xbmc.executebuiltin('AlarmClock(%s-start,RunScript(special://home/addons/script.tvguide.fullscreen/playwith.py,%s,%s),%d,True)' %
(name.encode('utf-8', 'replace'), channelId.encode('utf-8'), timestamp, timeToAutoplaywith - int(ADDON.getSetting('autoplaywiths.before'))))
t = endTime - datetime.datetime.now()
timeToAutoplaywith = ((t.days * 86400) + t.seconds) / 60
#timeToAutoplaywith = 0
if ADDON.getSetting('autoplaywiths.stop') == 'true':
xbmc.executebuiltin('AlarmClock(%s-stop,RunScript(special://home/addons/script.tvguide.fullscreen/stopwith.py,%s,%s),%d,True)' %
(name.encode('utf-8', 'replace'), channelId.encode('utf-8'), timestamp, timeToAutoplaywith + int(ADDON.getSetting('autoplaywiths.after'))))
def _unscheduleAutoplaywith(self, programTitle, startTime):
name = self.createAlarmClockName(programTitle, startTime)
xbmc.executebuiltin('CancelAlarm(%s-start,True)' % name.encode('utf-8', 'replace'))
xbmc.executebuiltin('CancelAlarm(%s-stop,True)' % name.encode('utf-8', 'replace'))
def addAutoplaywith(self, program,type):
self.database.addAutoplaywith(program,type)
if type == 0:
self._scheduleAutoplaywith(program.channel.id, program.title, program.startDate, program.endDate)
else:
self.scheduleAutoplaywiths()
def removeAutoplaywith(self, program):
self.database.removeAutoplaywith(program)
self._unscheduleAutoplaywith(program.title, program.startDate)
if __name__ == '__main__':
database = src.Database()
def onAutoplaywithsCleared():
xbmcgui.Dialog().ok(strings(CLEAR_NOTIFICATIONS), strings(DONE)) #TODO
def onInitialized(success):
if success:
database.clearAllAutoplaywiths()
database.close(onAutoplaywithsCleared)
ADDON.setSetting('playing.channel','')
ADDON.setSetting('playing.start','')
else:
database.close()
database.initialize(onInitialized)