def __do_rename(kbd): if kbd.text: record_id = context['selected'].record.id scheduler = WyRecord().scheduler scheduler.UpdateRecordingName(record_id, kbd.text) context['selected'].show_menu() kbd.hide() return None
def __init__(self, wymedia_resource, type_='channel', **kw): service_id = int(wymedia_resource.get('serviceId', 0)) live = WyRecord().live_manager._GetLiveFromServiceID(service_id) if live and live.isRecording(): type_ += '_recording' MediaItem.__init__(self, wymedia_resource, type_=type_, **kw) if ChannelItem.player is None: try: from pygui.menu.players import TVPlayer from pygui.menu.players.core import wyplayer_instance ChannelItem.player = TVPlayer(player=wyplayer_instance(), type='tvplayer') except Exception, e: log.error('Unable to spawn TV player: %s', str(e))
def __do_cancel(context): record = context['selected'] scheduler = WyRecord().scheduler try: rule_id = record.periodic_rule.id scheduler.RemovePeriodicRecording(rule_id, 'delete_records', False) except AttributeError: try: scheduler.DeleteRecording(record, record.id) except SchedulerRecordingRunningError: error_title = _('Impossible to cancel recording') message = _('This recording has already started.') MessageWindow(message, error_title, button=None).show(timeout=5) return None context['selected'].show_menu() return None
def _set_record(self, scheduled_record): self._record_to_remove = scheduled_record _wyrecord = WyRecord() self.record_name = scheduled_record.name self.select_date(scheduled_record.record.start_time, scheduled_record.record.stop_time) target_channel = TVRootItem().get_acl( self).get_channel_from_service_id( str(scheduled_record.record.service_id)) for i in xrange(len(self.favorite_list)): if self.favorite_list[i]['serviceId'] == str( scheduled_record.record.service_id): target_channel, target_channel = None, self.favorite_list[i] break self.select_channel(target_channel) if isinstance(scheduled_record, PeriodicScheduledRecordItem): _rule = _wyrecord.scheduler.GetPeriodicRuleById( scheduled_record.record.periodicity_rule_id) self.repetition_type_list.select( Item(self.PERIODICITY[_rule.extern_rule_name][0], 'periodic', self)) _num = (mktime(_rule.last_time.timetuple()) - _rule.recording_ref.start_time) / float( self.PERIODICITY[_rule.extern_rule_name][1] * 86400) self.repetition_number_list.select(IntegerItem(int(_num))) return None
def _get_recording_info(self): for live in WyRecord().live_controller.getRunningLiveList(): if live.isRecording(): service_id = live.serviceid channel = self._all_channel_list.get_channel_from_service_id( service_id) return channel.name return u''
def record_selected(self): program = self.selected now = int(time()) if program.end_time > now: start_time = max(now, program.start_time) end_time = min(program.end_time, start_time + 21600) channel = program.parent chan_id = int(channel['serviceId']) favorite_name = channel.parent.name values = { 'channel': channel.name, 'title': program.name, 'date': strftime('%Y/%m/%d', localtime(start_time)), 'start_time': seconds_to_hhmm(start_time), 'end_time': seconds_to_hhmm(end_time) } record_name = EPG_RECORDING_NAME_PATTERN % values try: WyRecord().scheduler.ScheduleRecording(chan_id, start_time, end_time, record_name, program_id=program.id, favorite=favorite_name) louie_send('update_record') except SchedulerConflictWithInstantRecordError, e: louie_send('update_record', sender=None) conflicting_rec = e.conflict.getAllRecInConflict()[0] message_pattern = _( 'An instant recording on %(channel)s will be stopped when this recording starts.' ) message = message_pattern % { 'name': ellipsize(conflicting_rec.name, 40), 'start_time': seconds_to_hhmm(conflicting_rec.start_time), 'channel': conflicting_rec.service_name } title = _('Conflict with an instant recording') MessageWindow(message, title, button=None).show(timeout=5) except SchedulerConflictError, e: conflicting_rec = e.conflict.getAllRecInConflict()[0] message_pattern = _( 'The recording you are attempting to schedule conflicts with "%(name)s", starting at %(start_time)s on %(channel)s.' ) message = message_pattern % { 'name': ellipsize(conflicting_rec.name, 40), 'start_time': seconds_to_hhmm(conflicting_rec.start_time), 'channel': conflicting_rec.service_name } title = _('Recording scheduler error') MessageWindow(message, title, button=None).show(timeout=5)
def _schedule_record(self, rec_name): _wyrecord = WyRecord() start_time, stop_time = self.start_time, self.end_time if self._record_to_remove: log.info('Deleting scheduled recording [%s] for replacement', self._record_to_remove) try: rule_id = self._record_to_remove.periodic_rule.id _wyrecord.scheduler.RemovePeriodicRecording( rule_id, delete_records=False) except AttributeError: try: _wyrecord.scheduler.DeleteRecording( self._record_to_remove.record.id) except SchedulerRecordingRunningError: error_title = _('Impossible to cancel recording') message = _('This recording has already started.') MessageWindow(message, error_title, button=None).show(timeout=5) self._record_to_remove = None try: self.scheduled_record = _wyrecord.scheduler.ScheduleRecording( int(self.channel_list.selected['serviceId']), int(start_time), int(stop_time), rec_name, favorite=self['favorite_name']) periodicity_type = self.repetition_type_list.selected periodicity_number = self.repetition_number_list.selected.val rule_id = None if periodicity_type.key != 'none' and periodicity_number > 1: rule_id = _wyrecord.scheduler.createPeriodicityRule( periodicity_type.key) end_date = datetime.fromtimestamp(start_time) + timedelta( days=periodicity_type.val[1] * periodicity_number - 1) res = _wyrecord.scheduler.GeneratePeriodicRecording( self.scheduled_record.id, rule_id, end_date) except SchedulerConflictWithInstantRecordError, e: conflicting_rec = e.conflict.getAllRecInConflict()[0] message_pattern = _( 'An instant recording on %(channel)s will be stopped when this recording starts.' ) message = message_pattern % { 'name': conflicting_rec.name, 'start_time': seconds_to_hhmm(conflicting_rec.start_time), 'channel': conflicting_rec.service_name } title = _('Conflict with an instant recording') MessageWindow(message, title, button=None).show(timeout=5) self.scheduled_record = e.conflict.rec
def cancel_record_selected(self): program = self.selected rec_id = program.recording_id if rec_id: log.info('Canceling recording for %s', program) try: WyRecord().scheduler.DeleteRecording(rec_id) except SchedulerRecordingRunningError: error_title = _('Impossible to cancel recording') message = _( 'This recording has already started. To stop it, close the EPG grid and press Stop.' ) MessageWindow(message, error_title, button=None).show(timeout=5) return None
def _select_option(self, val): UserConfigSetupItem._select_option(self, val) WyRecord().setRecordPadding(val * 60) return None
def recording_status(self): rec_id = self.recording_id if rec_id: return WyRecord().scheduler.GetRecording(rec_id).status return RECORDING_STATUS_UNKNOWN
def recording_id(self): return WyRecord().scheduler.GetRecordingIdFromProgramId(self.id)
def record_universe(self, command): # Initiate WyRecord scheduler try: Scheduler = WyRecord().scheduler except: self.wymodcp_conn.send('ERROR SCHEDULER') return 0 # GETLIST Command -> 'universe:RECORD command:GETLIST arg1:nFlags arg2:ignore_periodic' # - arg1 (flag) can be RECORDING_FLAG_RUNNING = 1, RECORDING_FLAG_COMPLETED = 2, RECORDING_FLAG_INCONFLICT = 4, # RECORDING_FLAG_SCHEDULED = 8, RECORDING_FLAG_CANCELED = 16, RECORDING_FLAG_MISSED = 16, RECORDING_FLAG_ALL = 255 # - arg2 (ignore_periodic) can be True or False # Return value: Recording list or 'ERROR' if 'GETLIST' in command['command']: try: result = [] rec_list = Scheduler.GetRecordingList( nFlags=int(command['arg1']), ignore_periodic=self.str2bool(command['arg2'])) for e in rec_list: result.append(str(e)) except: result = 'ERROR' # GETPERIODICLIST Command -> 'universe:RECORD command:GETPERIODICLIST arg1:active arg2:unactive' # - arg1 (active) can be True or False # - arg1 (unactive) can be True or False # Return value: Periodic recording list or 'ERROR' elif 'GETPERIODICLIST' in command['command']: try: result = [] rec_list = Scheduler.GetPeriodicRecordingList( active=self.str2bool(command['arg1']), unactive=self.str2bool(command['arg2'])) for e in rec_list: result.append(str(e)) except: result = 'ERROR' # SAVELIST Command -> 'universe:RECORD command:SAVELIST' # Return value: OK or 'ERROR' elif 'SAVELIST' in command['command']: try: print "Saving Recording List" Scheduler.SaveRecordingList() result = 'OK' except: result = 'ERROR' # RENAME Command -> 'universe:RECORD command:RENAME arg1:nRecordingID arg2:new_name' # - arg1 (nRecordingID) must be a valid record id taken from records list # - arg2 (new_name) must be the new name of the record # Return value: OK or 'ERROR' elif 'RENAME' in command['command']: try: print 'Renaming record id %d to %s' % (command['arg1'], command['arg2']) res = Scheduler.UpdateRecordingName(nRecordingID=int( command['arg1']), new_name=command['arg2']) if res is None: result = 'OK' else: result = 'ERROR' except: result = 'ERROR' # STOP Command -> 'universe:RECORD command:STOP arg1:nRecordingID arg2:stop_at_player_pos' # - arg1 (nRecordingID) must be a valid record id taken from records list # - arg2 (stop_at_player_pos) can be True or False (always False it seems ???) # Return value: OK or 'ERROR' elif 'STOP' in command['command']: try: print "Stopping all running records" res = Scheduler.StopRecording( nRecordingID=int(command['arg1']), stop_at_player_pos=self.str2bool(command['arg2'])) if res == True: result = 'OK' else: result = 'ERROR' except: result = 'ERROR' # STOPALL Command -> 'universe:RECORD command:STOPALL' # Return value: OK or 'ERROR' elif 'STOPALL' in command['command']: try: print "Stopping all running records" Scheduler.StopAllRunningRecord() result = 'OK' except: result = 'ERROR' # CHECKSCHEDULE Command -> 'universe:RECORD command:CHECKSCHEDULE arg1:save_list' # - arg1 (save_list) can be True or False # Return value: OK or 'ERROR' elif 'CHECKSCHEDULE' in command['command']: try: print 'Checking scheduled records' res = Scheduler.CheckSchedule( save_list=self.str2bool(command['arg1'])) if res is None: result = 'OK' else: result = 'ERROR' except: result = 'ERROR' # STARTLIVE Command -> 'universe:RECORD command:STARTLIVE arg1:nServiceID arg2:nForcedDeviceID arg3:duration arg4:name' # - arg1 (nServiceID) # - arg2 (nForcedDeviceID) # - arg3 (duration) # - arg4 (name) # Return value: OK or 'ERROR' elif 'STARTLIVE' in command['command']: try: print 'Starting live record' res = Scheduler.StartLiveRecording( nServiceID=int(command['arg1']), nForcedDeviceID=self.str2bool(command['arg2']), duration=int(command['arg3']), name=command['arg4']) if res['status'] != error.WYRECORD_SUCCESS: result = 'OK' else: result = 'ERROR' except: result = 'ERROR' # UNKNOW RECORD COMMAND else: print 'UNKNOW RECORD COMMAND !!!' result = 'ERROR COMMAND' # Send result through socket self.wymodcp_conn.send(str(result))
pygui_globs['subserver'] = subserver # try: from pygui.menu.players.audio_player import AudioPlayer log.debug('Audio Player loaded') # except Exception, e: # AudioPlayer = None # log.error('Audio Player loading error: %s', str(e)) try: from pygui.menu.players.video_player import VideoPlayer log.debug('Video Player loaded') except Exception, e: VideoPlayer = None log.error('Video Player loading error: %s', str(e)) try: from wyrecord import WyRecord wr = WyRecord() wr.setMaximumTimeshiftDuration((user_config['tv']['timeshift_length'] * 60)) wr.setRecordPadding((user_config['tv']['epg_margin'] * 60)) def _on_record_event(*args, **kw): from pygui.facilities.wylight import WyLed if wr.scheduler.IsSomeRecordingRunning(): WyLed().ask_led_action(1) else: WyLed().ask_led_action(25) return None wr.callbacks.recording_event.register(_on_record_event) from pygui.item.parameters.tv import wyscanserver wyscan = wyscanserver() from pygui.menu.players.tv_player import TVPlayer
# Author: Polo35 ([email protected]) # # Licenced under Academic Free License version 3.0 # Review WyGui README & LICENSE files for further details. from __future__ import absolute_import from peewee.debug import PRINT_EXCEPTION, DEBUG from pygui.facilities.l10n import UnicodeDict from pygui.item.containers import GenericContainer from pygui.item.core import Item from time import time from wyrecord import WyRecord from wyrecord.recordscheduler import RECORDING_FLAG_SCHEDULED, RECORDING_FLAG_CANCELED, RECORDING_FLAG_COMPLETED, RECORDING_FLAG_ALL _wyrec = WyRecord() PERIODICITY = UnicodeDict({'daily': 'Every day', 'weekly': 'Every week'}) class ScheduledRecordRootItem(GenericContainer): def __init__(self, menu=None, display_type=None, parent=None): Item.__init__(self, _('My scheduled recordings'), 'schedule_dir', menu, display_type, parent) return None # Return all the scheduled records. # # If scheduled_only is True (default), only the scheduled records # are returned. Otherwise, completed, canceled and other bogus # records are included in the result set. def browse(self, scheduled_only=True, preview=False):
def _rename_record(self, kbd): WyRecord().scheduler.UpdateRecordingName(self.scheduled_record.id, kbd.text) kbd.hide() pygui_globs['menustack'].back_one_menu() return None