- add autotimer to where_movielist to create a new autotimer based on movie metadata...
authorMoritz Venn <ritzmo@users.schwerkraft.elitedvb.net>
Thu, 29 May 2008 15:30:20 +0000 (15:30 +0000)
committerMoritz Venn <ritzmo@users.schwerkraft.elitedvb.net>
Thu, 29 May 2008 15:30:20 +0000 (15:30 +0000)
autotimer/src/AutoTimerEditor.py
autotimer/src/plugin.py

index 06f3891..be25757 100644 (file)
@@ -14,7 +14,8 @@ from Components.Button import Button
 
 # Configuration
 from Components.config import getConfigListEntry, ConfigEnableDisable, \
-       ConfigYesNo, ConfigText, ConfigClock, ConfigNumber, ConfigSelection
+       ConfigYesNo, ConfigText, ConfigClock, ConfigNumber, ConfigSelection, \
+       config
 
 # Timer
 from RecordTimer import AFTEREVENT
@@ -25,6 +26,9 @@ from time import localtime, mktime
 # Show ServiceName instead of ServiceReference
 from ServiceReference import ServiceReference
 
+# addAutotimerFromService
+from enigma import eServiceCenter, iServiceInformation
+
 weekdays = [
        ("0", _("Monday")),
        ("1", _("Tuesday")),
@@ -871,9 +875,15 @@ class AutoTimerServiceEditor(Screen, ConfigListScreen):
 
 def addAutotimerFromEvent(session, evt = None, service = None):
        from AutoTimerComponent import AutoTimerComponent
+       from plugin import autotimer
+               
+       # Create instance if needed
+       if autotimer is None:
+               from AutoTimer import AutoTimer
+               autotimer = AutoTimer()
 
-       name = evt and evt.getEventName() or "New AutoTimer"
        match = evt and evt.getEventName() or ""
+       name = match or "New AutoTimer"
        servicelist = []
        if service is not None:
                service = str(service)
@@ -886,7 +896,50 @@ def addAutotimerFromEvent(session, evt = None, service = None):
        if evt:
                begin = evt.getBeginTime()
                end = begin + evt.getDuration()
-               timetuple = (begin-3600, end+3600) # timespan defaults to +- 1h
+               timetuple = (localtime(begin-3600)[3:5], localtime(end+3600)[3:5]) # timespan defaults to +- 1h
+       else:
+               timetuple = None
+
+       session.openWithCallback(
+               addCallback,
+               AutoTimerEditor,
+               AutoTimerComponent(
+                       autotimer.getUniqueId(),        # Id
+                       name,                                                   # Name
+                       match,                                                  # Match
+                       True,                                                   # Enabled
+                       timespan = timetuple,
+                       services = servicelist
+               )
+       )
+
+def addAutotimerFromService(session, service = None):  
+       from AutoTimerComponent import AutoTimerComponent
+       from plugin import autotimer
+               
+       # Create instance if needed
+       if autotimer is None:
+               from AutoTimer import AutoTimer
+               autotimer = AutoTimer()
+
+       serviceHandler = eServiceCenter.getInstance()
+       info = serviceHandler.info(service)
+
+       match = info and info.getName(service) or ""
+       name = match or "New AutoTimer"
+       servicelist = []
+       recordservice = info.getInfoString(service, iServiceInformation.sServiceref)
+       if recordservice:
+               # strip all after last :
+               pos = recordservice.rfind(':')
+               if pos != -1:
+                       recordservice = recordservice[:pos+1]
+
+               servicelist.append(recordservice)
+       if info:
+               begin = info.getInfo(service, iServiceInformation.sTimeCreate)
+               end = begin + info.getLength(service)
+               timetuple = (localtime(begin)[3:5], localtime(end)[3:5])
        else:
                timetuple = None
 
@@ -894,7 +947,7 @@ def addAutotimerFromEvent(session, evt = None, service = None):
                addCallback,
                AutoTimerEditor,
                AutoTimerComponent(
-                       self.autotimer.getUniqueId(),   # Id
+                       autotimer.getUniqueId(),        # Id
                        name,                                                   # Name
                        match,                                                  # Match
                        True,                                                   # Enabled
@@ -907,15 +960,15 @@ def addCallback(ret):
        if ret:
                from plugin import autotimer
                
-               # Create instance if needed
+               # Create instance if needed (should have been created by addAutotimerFrom* above though)
                if autotimer is None:
                        from AutoTimer import AutoTimer
                        autotimer = AutoTimer()
 
                autotimer.add(ret)
                
-               # Remove instance if not running in background
-               if not config.plugins.autotimer.autopoll.value:
-                       # Save xml
-                       autotimer.writeXml()
-                       autotimer = None
+       # Remove instance if not running in background
+       if not config.plugins.autotimer.autopoll.value:
+               # Save xml
+               autotimer.writeXml()
+               autotimer = None
index 51bf6f3..ef6e297 100644 (file)
@@ -118,11 +118,17 @@ def editCallback(session):
                session and autotimer.writeXml()
                autotimer = None
 
+# Movielist
+def movielist(session, service, **kwargs):
+       from AutoTimerEditor import addAutotimerFromService
+       addAutotimerFromService(session, service)
+
 def Plugins(**kwargs):
        from Plugins.Plugin import PluginDescriptor
 
        return [
                PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart),
-               PluginDescriptor(name="AutoTimer", description = "Edit Timers and scan for new Events", where = PluginDescriptor.WHERE_PLUGINMENU, icon = "plugin.png", fnc = main),
-               PluginDescriptor(name="AutoTimer", description = "Edit Timers and scan for new Events", where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = main)
+               PluginDescriptor(name="AutoTimer", description = _("Edit Timers and scan for new Events"), where = PluginDescriptor.WHERE_PLUGINMENU, icon = "plugin.png", fnc = main),
+               PluginDescriptor(name="AutoTimer", description = _("Edit Timers and scan for new Events"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = main),
+               PluginDescriptor(name="AutoTimer", description= _("Add AutoTimer..."), where = PluginDescriptor.WHERE_MOVIELIST, fnc = movielist)
        ]