Vc@sddlmZmZmZmZmZddlmZddlm Z ddl m Z ddl m Z ddlZddlmZmZmZddlmZdd lmZddlZddlZddlZdd lmZdd lmZmZm Z mZdd l!m"Z"ej#j$d e%dej&e'dZ(dfdYZ)dej*e+fdYZ,dZ-d ej.fdYZ/dS(i(t eEPGCachetgetBestPlayableServiceReferenceteServiceReferencetiRecordableServicet quitMainloop(tconfig(tdefaultMoviePath(tTimerSanityCheck(t MessageBoxN(t Directoriest Notificationst ASCIItranslit(t stringToXML(tsaveFile(tServiceReference(t localtimetstrftimetctimettime(tinsortt RecordTimers record timercCs|r!|j}|j}n d}d}|j}||j}|j}|tjjjd8}|tjj jd7}|||||fS(Nti<( t getEventNametgetShortDescriptiont getBeginTimet getDurationt getEventIdRt recordingt margin_beforetvaluet margin_after(tevt descriptiontnametbegintendteit((s&/usr/lib/enigma2/python/RecordTimer.pyt parseEvent s   t AFTEREVENTcBs eZdZdZdZdZRS(iiii(t__name__t __module__tNONEtSTANDBYt DEEPSTANDBYtAUTO(((s&/usr/lib/enigma2/python/RecordTimer.pyR&.stRecordTimerEntrycBseZeZedZedZedZeedZ eee j eddidZ dZdZdZdZd Zdd Zd Zd Zd ZdZdZdZdZedeZdZRS(cCstddS(Ni(R(((s&/usr/lib/enigma2/python/RecordTimer.pytshutdown9scCs|tjkrdGHtjj}|stjjj}|dkrq|tdkrqdG|tGdGHqdGHtj qn|tj krdGHndS(Ns:RecordTimer.staticGotRecordEvent(iRecordableService.evEnd)iihsanother recording starts insseconds... do not shutdown yetsAno starting records in the next 360 seconds... immediate shutdowns<RecordTimer.staticGotRecordEvent(iRecordableService.evStart)( RtevEndtNavigationInstancetinstancet getRecordingsRtgetNextRecordingTimeRR-R.tevStart(t recserviceteventt recordingstrec_time((s&/usr/lib/enigma2/python/RecordTimer.pytstaticGotRecordEvent=scCs(dGHtjjjtjtt_dS(NsRecordTimer.stopTryQuitMainloop(R0R1t record_eventtremoveR-R9tFalsetreceiveRecordEvents(((s&/usr/lib/enigma2/python/RecordTimer.pytstopTryQuitMainloopLscCs`tjs\dGHtjjjtjtt_tjdt j t j j jjtjndS(NsRecordTimer.TryQuitMainloop(R-R=R0R1R:tappendR9tTruetNoneRR/tScreenstStandbyt inStandbytonCloseR>(t default_yes((s&/usr/lib/enigma2/python/RecordTimer.pytTryQuitMainloopRs   cCsctjj|t|t|| tkr\|jtdkr\tt|_q\n|j|jkr}|j|_n|dk r|j r||_ nt d|_ ||_ t |_||_||_||_d|_d|_d|_||_| |_| |_t |_t |_d|_| p7g|_| pFi|_g|_|jdS(NiuiiiiQ(ttimert TimerEntryt__init__tintR@R"RR#RAt isRecordablet service_refRR$R<tdontSaveR!R tdisabledt!_RecordTimerEntry__record_servicet start_preparetjustplayt afterEventtdirnametdirnameHadToFallbackt autoincreasetautoincreasetimettagstpluginst log_entriest resetState(tselft servicerefR"R#R!R R$RORRRStcheckOldTimersRTRXRY((s&/usr/lib/enigma2/python/RecordTimer.pyRJ_s6"                 cCs/|jjtt||fdG|GHdS(Ns[TIMER](RZR?RKR(R\tcodetmsg((s&/usr/lib/enigma2/python/RecordTimer.pytlogs"cCs|jj}tdt|j}tdt|j}dG|GHdG|GHdG|jGHdG|jGH|d|}|jrtjj j dkrtj j j d kr|d|j}qtj j j d kr|d|jd|j7}q|d|j7}q|d|j7}ntj jj r;tj|}n|j s[tj|jd  r||jrpt|_nt}n |j}tj|||_|jd d |jdS(Ns %Y%m%d %H%Ms%Y%m%ds begin_date: sservice_name: sname:s description: s - itshorttlongtwisFilename calculated as: '%s'(RMtgetServiceNameRRR"R!R Rtusaget setup_leveltindexRtfilename_compositionRtascii_filenamesR t legacyEncodeRTR t fileExistsR@RURtgetRecordingFilenametFilenameRa(R\t service_namet begin_datetbegin_shortdatetfilenameRT((s&/usr/lib/enigma2/python/RecordTimer.pytcalculateFilenames2          c Cs|jr tS|j|jo)|jj}|rq|jtj@rqt|t}|sq|j ddt Sn|ot j j ||_|js|j ddt S|jrtj}|j|j|jd}|j||}|r|j|_|j}q6d}n|j}|dkr6d}n|jj|jd|j|j||jjdd|jjddd j|j}|r|d kr|j d d n|j dd ||j t!|j"|_#t j j$|jd|_t StSdS(Nis6'get best playable service for group... record' faileds'record service' failediis.tss Rt iis failed to write meta informations'prepare' failed: error %d(%RRR@RsRMtreftflagsRtisGroupRRaR<R0R1t recordServicetrecord_servicetrepeatedRt getInstanceR"R#tlookupEventTimeRR RR$RAtprepareRnR!treplacetjoinRXt do_backoffRtbackoffRQtstopRecordService(R\trec_reftepgcachet queryTimetevttevent_idtprep_res((s&/usr/lib/enigma2/python/RecordTimer.pyt tryPreparesF         [   cCs`|jdkrd|_n*|jd9_|jdkrEd|_n|jdd|jdS(Niiiidi sbackoff: retry in %d seconds(RRa(R\((s&/usr/lib/enigma2/python/RecordTimer.pyRs   c Cs-|jd}|jdd|||jkr|jr|jdd|jsrt|jddjn|j|_ d|_ t S|jd d |j rt |_ tjj}|rz|j s|jdd krztjjjs/|jd d tj|jttdddddq|jddtjttddtjdddd|jt q|r|jd dq|jd dnt S||jkr|jrt S|jrTtj j!r*tj"j#jr"|jdd|j$j%tj j!_&tj j!j'qPdGHn&|jddtjj(|j$j%t S|jdd|j)j*}|r|jdd||j+t,|j |_t St Snt||j-kr)|j.}|j/r|jd d!t0|j.|d"|jd8_t S|jd d#tjj1o]tj2j3jo]tj j!o]tj2j4jdk}|jstjj5|j)d|_)n|j7t8j9krtj j!s?tj|j:ttd$ddddq?nk|j7t8j;ks|r?tj j<s?tj j!rt=j>q<tj|j?ttd%ddddq?n|j@r%d&d'lAmB}d&d(lCm@}x|j@jDD]\}\} } | d)krxx|jE|jFD]n} || jGkr| jHjId*r| jHd*} d+G| jGG| G| G| GHtj| | | |ddqqqWqxqxWnt SdS(,Niisactivating state %disprepare ok, waiting for begins.tsRdiisprepare failedt/isasking user to zap aways4A timer failed to record! Disable TV and try again? ttimeoutitdomainRi szap without askingsJIn order to record a timer, the TV was switched to the recording service! ttypesKcurrently running service is not a live service.. so stop it makes no senses:currently no service running... so we dont need to stop iti swakeup and zapsignore zaptimer in idle modetzappingsstart recordingi sstart record returned %di s"autoincrase recording %d minute(s)i<sstop recordingsKA finished record timer wants to set your Dreambox to standby. Do that now?sGA finished record timer wants to shut down your Dreambox. Shutdown now?i(tPluginDescriptor(RYR@t finishedFncs.calling finishedFnc of WHERE_TIMEREDIT plugin:(JtstateRat StatePreparedRRRtopenRntcloseR"tnext_activationRR@tfirst_try_prepareR<R0R1t#getCurrentlyPlayingServiceReferencetgetPathRRtasktozapRR tAddNotificationWithCallbackt failureCBRt_tAddNotificationt TYPE_INFOt StateRunningt cancelledRBRCRDRftstandby_zaptimer_wakeupRMRutprev_running_servicetPowert playServiceRytstartRRt StateEndedR#tsetAutoincreaseEndRKtwasTimerWakeuptmisct%isNextRecordTimerAfterEventActionAutotstandbyCounterRRARSR&R*tsendStandbyNotificationR+tinTryQuitMainloopR-RGtsendTryQuitMainloopNotificationRYtPlugins.PluginRtComponents.PluginComponentt iteritemst getPluginstWHERE_TIMEREDITR!t__call__thas_key( R\t next_statetcur_reft record_restold_endtforce_auto_shutdownRRYtpnametpvaltpdatatptfnc((s&/usr/lib/enigma2/python/RecordTimer.pytactivates       )++      %!   .   . "  0cCs3|js tS|dkr2tt|j}n |jd}t|j|j||j |j |j dt d|j d|jd|jd|jd|j}|j|_ttjjj|}|js|j}|dk rt|dkr|dj}|d8}qn|tkr&tS||_t S( NiRORRRSRTRXRYi(RVR<RARKRRWR"R-RMR!R R$R@RRRSRTRXRYRORR0R1Rt timer_listtchecktgetSimulTimerListtlenR#(R\tentrytnew_endt dummyentryttimersanitychecktsimulTimerList((s&/usr/lib/enigma2/python/RecordTimer.pyRJs"   ]     cCs)|r%tjdtjjddndS(NRCRR(R tAddNotificationWithIDRBRC(R\tanswer((s&/usr/lib/enigma2/python/RecordTimer.pyR_scCs,|r(tjdtjjdddndS(NtShutdowniRR(R RRBRCRG(R\R((s&/usr/lib/enigma2/python/RecordTimer.pyRcscCsU|j|jkr|jS|jd}i|j|j6|j|j6|j|j6|S(Ni(RRR#RQRR"R(R\R((s&/usr/lib/enigma2/python/RecordTimer.pytgetNextActivationgs   cCsI|tkr5|jddtjj|jjn|jdddS(Ni sok, zapped awayis7user didn't want to zap away, record will probably fail(R@RaR0R1RRMRu(R\R((s&/usr/lib/enigma2/python/RecordTimer.pyRqs cCsd|j}|j|j|_d|_t|t|jkr`|jddt|jndS(Niis-record time changed, start prepare is now: %s(RQR"t prepare_timeRRKRaR(R\t old_prepare((s&/usr/lib/enigma2/python/RecordTimer.pyt timeChangedys   c Cs|jj|jkrdS|jdd||tjkr{dGHtjdtddtj ddd d d d n|tj krtd |j }|j rdj |tdf}ntjjjrtjd|dtjddd d qndS(Nisrecord event %ds$WRITE ERROR on recording, disk full?ttexts(Write error while recording. Disk full? RRitidtDiskFullMessageRRsA record has been started: %ss sPlease note that the previously selected media could not be accessed and therefore the default directory is being used instead.i(RPt __deref__RaRtevRecordWriteErrorR tAddPopupRRt TYPE_ERRORR4R!RURRRft"show_message_when_recording_startsRR(R\trecordR6R((s&/usr/lib/enigma2/python/RecordTimer.pytgotRecordEvents4 cCsg|jdk r-dGHtjjj|jn||_|jdk rcdGHtjjj|jndS(Ns[remove callback]s[add callback](RPRAR0R1R:R;RR?(R\tservice((s&/usr/lib/enigma2/python/RecordTimer.pytsetRecordServices cCs|jS(N(RP(R\((s&/usr/lib/enigma2/python/RecordTimer.pytscCs;d|jjt||jt|dr3|jp6dfS(Ns<%s instance at %x name=%s %s>RnR(t __class__R'RR!thasattrRn(R\((s&/usr/lib/enigma2/python/RecordTimer.pyt__str__sN(R'R(R<R=t staticmethodR.R9R>R@RGR&R,RARJRaRsRRRRRRRRRRRtpropertyRyR(((s&/usr/lib/enigma2/python/RecordTimer.pyR-5s, !$  # 1 f       cCst|jd}t|jd}t|jdjd}|jdjd}|jdjd}t|jdpd}t|jd pd}t|jd pd }itjd 6tjd 6tj d 6tj d6|}|jd} | r+| dkr+t| } nd} |jd} | rd| dkrd| jd} nd} |jd} | r| dkr| jdj d} nd} |jdjd} i} x`|j dD]O}t|jd}t|jd}t|j}||f| | s s%s s s (#R?RRRNRRKR"R#R RMRzR!R R&R)R*R+R,RSR$RARTRXRRORRRRtdebugRRZRYRR Rn( R\tlistRHRR_R`tkeytvaltdata((s&/usr/lib/enigma2/python/RecordTimer.pyt saveTimer-sN(    $$$$$$J!'0$$    " < cCsMt}x=|jD]2}|j s|js|j|krAqn|jSWdS(Ni(RRRRROR"(R\tnowRH((s&/usr/lib/enigma2/python/RecordTimer.pytgetNextZapTimes  "cCsRt}xB|jD]7}|j}|js|js||krIqn|SWdS(Ni(RRRRORR(R\RRHtnext_act((s&/usr/lib/enigma2/python/RecordTimer.pyR3s  cCst}d}xu|jD]j}|js|js|j|krFqn|dksd|j|jkr|}|jtjkrt SqqWt S(N( RRARRRROR"RSR&R,R@R<(R\RttRH((s&/usr/lib/enigma2/python/RecordTimer.pyt isNextRecordAfterEventActionAutos ! cCs|sVt|j|}|js>dGH|jGH|jS|jrVdGHdSn|jdt|GH||_|j ||r|j ndS(Nstimer conflict detected!signore double timers[Timer] Record ( RRRRt doubleCheckRARRRRR(R\RRRR((s&/usr/lib/enigma2/python/RecordTimer.pyRs         c Csd}d}d}d}||} t|} x|jD]} | jjj| k} | s| jj} | jd}| jd}|r|r| jd}| jd}| jd|| jd|| jdd| jdd| j| k} d}| rGt } t j j | |}|r>|j pAd}n| jd|| jd|| jd|| jd|xKt|D]:}|j| |}| j|jkrt} PqqWqn| r8| jdkr4|dkr5t|}|jd|jd|j}||d}nt| j}xxd D]}| jd|>@rK| j|ks|| jko| knrK|d|jd|j}||ko|| j| jdknr|| j| jd|d}q-||ko|knr-||d}q-qKqKWn|| jkoN| knrx| | j}||kr|}qnG| j|ko| jknr| j|}||kr|}qn|rPqq8q8W|S( Niiiiiii<ii(iiiiiii(RARRRMRuttoStringtgetUnsignedDatatsetUnsignedDatattoCompareStringR<RR{t lookupEventIdtgetNumOfLinkageServicestrangetgetLinkageServiceR@RzRttm_wdayttm_hourttm_minR"R#(R\teventidR"tdurationRt time_matchtchktimet chktimecmptchktimecmp_endR#trefstrtxRtsreft parent_sidt parent_tsidtsidttsidtnumR6tcntt subserviceRtyttimecmptdiff((s&/usr/lib/enigma2/python/RecordTimer.pyt isInTimersv       ?.#   "    cCsdt|GHt|_t|_|j|j|jkrM|j|ndG|jGHdG||jkGHdG||j kGH|jj ||j dS(Ns[Timer] Remove sstate: sin processed: s in running: ( RR<RzRVtabortRRRRRR;R(R\R((s&/usr/lib/enigma2/python/RecordTimer.pyt removeEntrys     cCs|jdS(N(R(R\((s&/usr/lib/enigma2/python/RecordTimer.pyR.s(R'R(RJRRRRR R3R#R<R@RRCRER.(((s&/usr/lib/enigma2/python/RecordTimer.pyRs   " [   > (0tenigmaRRRRRtComponents.configRtComponents.UsageConfigRtComponents.TimerSanityCheckRR RtScreens.StandbyRBtToolsR R R tTools.XMLToolsR tTools.IOR RHtxml.etree.cElementTreeRR0RRRRRtbisectRtnotificationQueuetregisterDomainRt ICON_TIMERR@R%R&RItobjectR-RRR(((s&/usr/lib/enigma2/python/RecordTimer.pyts*(    " t 4