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