from Components.config import config
from Components.UsageConfig import defaultMoviePath
from Components.TimerSanityCheck import TimerSanityCheck
+from Components.SystemInfo import SystemInfo
from Screens.MessageBox import MessageBox
import Screens.Standby
from time import localtime, strftime, ctime, time
from bisect import insort
+import os
+
# ok, for descriptions etc we have:
# service reference (to get the service name)
# name (title)
DEEPSTANDBY = 2
AUTO = 3
+def findSafeRecordPath(dirname):
+ if not dirname:
+ return None
+
+ from Components import Harddisk
+ dirname = os.path.realpath(dirname)
+ mountpoint = Harddisk.findMountPoint(dirname)
+ if mountpoint in ('/', '/media'):
+ print '[RecordTimer] media is not mounted:', dirname
+ return None
+ if not os.path.isdir(dirname):
+ try:
+ os.makedirs(dirname)
+ except Exception, ex:
+ print '[RecordTimer] Failed to create dir "%s":' % dirname, ex
+ return None
+
+ return dirname
+
# please do not translate log messages
class RecordTimerEntry(timer.TimerEntry, object):
######### the following static methods and members are only in use when the box is in (soft) standby
Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1, onSessionOpenCallback=RecordTimerEntry.stopTryQuitMainloop, default_yes = default_yes)
#################################################################
- def __init__(self, serviceref, begin, end, name, description, eit, disabled = False, justplay = False, afterEvent = AFTEREVENT.AUTO, checkOldTimers = False, dirname = None, tags = None):
+ def __init__(self, serviceref, begin, end, name, description, eit, disabled = False, justplay = False, afterEvent = AFTEREVENT.AUTO, checkOldTimers = False, dirname = None, tags = None, descramble = True, record_ecm = False, filename = None):
timer.TimerEntry.__init__(self, int(begin), int(end))
if checkOldTimers == True:
self.timer = None
self.__record_service = None
self.start_prepare = 0
- self.justplay = justplay
+ if SystemInfo["PVRSupport"]:
+ self.justplay = justplay
+ else:
+ self.justplay = True
self.afterEvent = afterEvent
self.dirname = dirname
self.dirnameHadToFallback = False
self.autoincreasetime = 3600 * 24 # 1 day
self.tags = tags or []
+ self.descramble = descramble
+ self.record_ecm = record_ecm
+
self.log_entries = []
self.resetState()
-
+
+ self.Filename = filename
+ self.pvrConvert = False
+
def log(self, code, msg):
self.log_entries.append((int(time()), code, msg))
print "[TIMER]", msg
def calculateFilename(self):
+ if self.Filename:
+ self.log(0, "Filename calculated as: '%s'" % self.Filename)
+ return self.Filename
+
service_name = self.service_ref.getServiceName()
begin_date = strftime("%Y%m%d %H%M", localtime(self.begin))
begin_shortdate = strftime("%Y%m%d", localtime(self.begin))
if config.recording.ascii_filenames.value:
filename = ASCIItranslit.legacyEncode(filename)
- if not self.dirname or not Directories.fileExists(self.dirname, 'w'):
- if self.dirname:
- self.dirnameHadToFallback = True
- dirname = defaultMoviePath()
+ if not self.dirname:
+ dirname = findSafeRecordPath(defaultMoviePath())
else:
- dirname = self.dirname
+ dirname = findSafeRecordPath(self.dirname)
+ if dirname is None:
+ dirname = findSafeRecordPath(defaultMoviePath())
+ self.dirnameHadToFallback = True
+
+ if not dirname:
+ return None
+
self.Filename = Directories.getRecordingFilename(filename, dirname)
self.log(0, "Filename calculated as: '%s'" % self.Filename)
#begin_date + " - " + service_name + description)
+ return self.Filename
def tryPrepare(self):
if self.justplay:
return True
else:
- self.calculateFilename()
+ if not self.calculateFilename():
+ self.do_backoff()
+ self.start_prepare = time() + self.backoff
+ return False
+
rec_ref = self.service_ref and self.service_ref.ref
if rec_ref and rec_ref.flags & eServiceReference.isGroup:
rec_ref = getBestPlayableServiceReference(rec_ref, eServiceReference())
if event_id is None:
event_id = -1
- prep_res=self.record_service.prepare(self.Filename + ".ts", self.begin, self.end, event_id, self.name.replace("\n", ""), self.description.replace("\n", ""), ' '.join(self.tags))
+ prep_res=self.record_service.prepare(self.Filename + ".ts", self.begin, self.end, event_id, self.name.replace("\n", ""), self.description.replace("\n", ""), ' '.join(self.tags), bool(self.descramble), bool(self.record_ecm))
if prep_res:
if prep_res == -255:
self.log(4, "failed to write meta information")
self.record_service = None
if self.afterEvent == AFTEREVENT.STANDBY:
if not Screens.Standby.inStandby: # not already in standby
- Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A finished record timer wants to set your\nDreambox to standby. Do that now?"), timeout = 20)
+ Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A finished record timer wants to set your\nSTB to standby. Do that now?"), timeout = 20)
elif self.afterEvent == AFTEREVENT.DEEPSTANDBY:
if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open
if Screens.Standby.inStandby: # in standby
RecordTimerEntry.TryQuitMainloop() # start shutdown handling without screen
else:
- Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A finished record timer wants to shut down\nyour Dreambox. Shutdown now?"), timeout = 20)
+ Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A finished record timer wants to shut down\nyour STB. Shutdown now?"), timeout = 20)
return True
def setAutoincreaseEnd(self, entry = None):
# that in our state, with also keeping the possibility to re-try.
# TODO: this has to be done.
elif event == iRecordableService.evStart:
+ if self.pvrConvert:
+ return
+
text = _("A record has been started:\n%s") % self.name
if self.dirnameHadToFallback:
text = '\n'.join((text, _("Please note that the previously selected media could not be accessed and therefore the default directory is being used instead.")))
record_service = property(lambda self: self.__record_service, setRecordService)
+ def isUsbRecordingPath(self):
+ dirname = None
+
+ if self.dirname:
+ dirname = findSafeRecordPath(self.dirname)
+
+ if dirname is None:
+ dirname = findSafeRecordPath(defaultMoviePath())
+
+ from Components import Harddisk
+ return Harddisk.isUsbStorage(dirname)
+
def createTimer(xml):
begin = int(xml.get("begin"))
end = int(xml.get("end"))
description = xml.get("description").encode("utf-8")
repeated = xml.get("repeated").encode("utf-8")
disabled = long(xml.get("disabled") or "0")
- justplay = long(xml.get("justplay") or "0")
+ if SystemInfo["PVRSupport"]:
+ justplay = long(xml.get("justplay") or "0")
+ else:
+ justplay = long("1")
afterevent = str(xml.get("afterevent") or "nothing")
afterevent = {
"nothing": AFTEREVENT.NONE,
print "unable to load timers from file!"
def doActivate(self, w):
+ if w.state == RecordTimerEntry.StateWaiting:
+ from Components.SystemInfo import SystemInfo
+ if SystemInfo.get("DisableUsbRecord", True) and w.isUsbRecordingPath():
+ service_name = w.service_ref.getServiceName()
+ self.timer_list.remove(w)
+ if w.dontSave is False:
+ w.resetState()
+ w.disable()
+ self.addTimerEntry(w)
+ Notifications.AddNotification(MessageBox, _("Can not recording on a USB storage.\nService name : %s"% service_name), MessageBox.TYPE_ERROR)
+ return
+
# when activating a timer which has already passed,
# simply abort the timer. don't run trough all the stages.
if w.shouldSkip():
if timer.tags is not None:
list.append(' tags="' + str(stringToXML(' '.join(timer.tags))) + '"')
list.append(' disabled="' + str(int(timer.disabled)) + '"')
- list.append(' justplay="' + str(int(timer.justplay)) + '"')
+ if SystemInfo["PVRSupport"]:
+ list.append(' justplay="' + str(int(timer.justplay)) + '"')
+ else:
+ list.append(' justplay="1"')
list.append('>\n')
if config.recording.debug.value: