SeriesPlugin: 1.5.8 Fixed encoding, popups, channel list integration
[enigma2-plugins.git] / seriesplugin / src / SeriesPluginIndependent.py
1 # -*- coding: utf-8 -*-
2 #######################################################################
3 #
4 #    Series Plugin for Enigma-2
5 #    Coded by betonme (c) 2012 <glaserfrank(at)gmail.com>
6 #    Support: http://www.i-have-a-dreambox.com/wbb2/thread.php?threadid=TBD
7 #
8 #    This program is free software; you can redistribute it and/or
9 #    modify it under the terms of the GNU General Public License
10 #    as published by the Free Software Foundation; either version 2
11 #    of the License, or (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU General Public License for more details.
17 #
18 #######################################################################
19
20 #TODO Add optional popup
21
22 # for localized messages
23 from . import _
24
25 # Config
26 from Components.config import *
27
28 import NavigationInstance
29 from enigma import eTimer
30 from time import localtime
31 #from ServiceReference import ServiceReference
32
33 # Plugin internal
34 from SeriesPlugin import getInstance, refactorTitle, refactorDescription
35 from SeriesPluginTimer import SeriesPluginTimer
36 from Logger import splog
37
38
39 # Globals
40 instance = None
41
42
43 def startIndependent():
44         global instance
45         instance = SeriesPluginIndependent()
46         return instance
47
48 def stopIndependent():
49         #Rename to closeInstance
50         global instance
51         if instance:
52                 instance.stop()
53                 instance = None
54
55 def runIndependent():
56         try:
57                 
58                 for timer in NavigationInstance.instance.RecordTimer.timer_list:
59                         
60                         if timer.isRunning():
61                                 splog("SeriesPluginIndependent: Skip running timer", timer.name)
62                                 continue
63                         
64                         if timer.justplay:
65                                 splog("SeriesPluginIndependent: Skip justplay timer", timer.name)
66                                 continue
67                         
68                         if timer.repeated:
69                                 splog("SeriesPluginIndependent: Skip repeating timer", timer.name)
70                                 continue
71                         
72                         if not config.plugins.seriesplugin.independent_retry.value:
73                                 splog("SeriesPluginIndependent: timer retry is disabled")
74                                 if hasattr(timer, 'serieslookupdone') and timer.serieslookupdone:
75                                         splog("SeriesPluginIndependent: Skip timer retry", timer.name)
76                                         continue
77                         
78                         #Maybe later add a series whitelist xml
79                         SeriesPluginTimer(timer, timer.name, timer.begin, timer.end)
80                         
81                         timer.serieslookupdone = True
82         
83         except Exception as e:
84                 splog("SeriesPluginIndependent: run exception " + str(e))
85
86
87
88 #######################################################
89 # Label timer
90 class SeriesPluginIndependent(object):
91
92         data = []
93         
94         def __init__(self):
95                 self.etimer = eTimer()
96                 self.etimer_conn = None
97                 try:
98                         self.etimer_conn = self.etimer.timeout.connect(self.run)
99                 except:
100                         self.etimer.callback.append(self.run)
101                 cycle = int(config.plugins.seriesplugin.independent_cycle.value)
102                 if cycle > 0:
103                         self.etimer.start( (cycle * 60 * 1000) )
104                 # Start timer as single shot, just for testing
105                 #self.etimer.start( 10, True )
106
107         def run(self):
108                 splog("SeriesPluginIndependent: run",  strftime("%a, %d %b %Y %H:%M:%S", localtime()) )
109
110                 runIndependent()
111
112         def stop(self):
113                         self.etimer_conn = None
114                         try:
115                                 self.etimer.callback.remove(self.run)
116                         except:
117                                 pass