def __init__(self, standalone=False): """ init the upsoon plugin """ _debug_('upsoon.PluginInterface.__init__()', 2) plugin.DaemonPlugin.__init__(self) plugin.register(self, 'upsoon') self.standalone = standalone self.lock = thread.allocate_lock() self.running = True self.timer = Timer(self.timer_handler).start(15) self.event = EventHandler(self.event_handler) #self.event.register(('VIDEO_START', 'VIDEO_END')) self.event.register() self.recordclient = RecordClient() self.fc = FreevoChannels() self.rdev = config.RADIO_DEVICE self.next_program = None self.seconds_before_announce = 120 self.seconds_before_start = 60 self.pending_lockfile = config.FREEVO_CACHEDIR + '/record.soon' self.tv_lockfile = None # lockfile of recordserver self.stopped = None # flag that tells upsoon what stopped
def __init__(self, standalone=False): """ init the upsoon plugin """ logger.log( 9, 'upsoon.PluginInterface.__init__()') plugin.DaemonPlugin.__init__(self) plugin.register(self, 'upsoon') self.standalone = standalone self.lock = thread.allocate_lock() self.running = True self.timer = Timer(self.timer_handler).start(15) self.event = EventHandler(self.event_handler) #self.event.register(('VIDEO_START', 'VIDEO_END')) self.event.register() self.recordclient = RecordClient() self.fc = FreevoChannels() self.rdev = config.RADIO_DEVICE self.next_program = None self.announced = False self.seconds_before_announce = config.TV_UPSOON_ANNOUNCE self.seconds_before_start = config.TV_UPSOON_BEFORE_START self.pending_lockfile = config.FREEVO_CACHEDIR + '/record.soon' self.tv_lockfile = None # lockfile of recordserver self.stopped = None # flag that tells upsoon what stopped if os.path.exists(self.pending_lockfile): os.remove(self.pending_lockfile) logger.debug('%r lockfile removed', self.pending_lockfile)
def search_for_more(arg=None, menuw=None): parent, title = arg # this might take some time, thus we open a popup messages logger.log( 9, String('searching for: %s', title)) pop = dialog.show_working_indicator(_('Searching, please wait...')) # do the search (status, matches) = RecordClient().findMatchesNow(title) pop.hide() if status: items = [] logger.log( 9, 'search found %s matches', len(matches)) # sort by start times f = lambda a, b: cmp(a.start, b.start) matches.sort(f) for prog in matches: items.append(ProgramItem(parent, prog, context='search')) elif matches == 'no matches': # there have been no matches msgtext = _('No matches found for %s') % self.title dialog.show_alert(msgtext) return else: # something else went wrong msgtext = _('Search failed') +(':\n%s' % matches) dialog.show_alert(msgtext) return # create a menu from the search result search_menu = Menu(_('Search Results'), items, item_types='tv program menu') # do not return from the search list to the submenu # where the search was initiated menuw.delete_submenu(refresh = False) menuw.pushmenu(search_menu) menuw.refresh()
def __init__(self, start_time, player, menuw): _debug_( 'TVGuide.__init__(start_time=%r, player=%r, menuw=%r)' % (start_time, player, menuw), 2) Item.__init__(self) # get skin definitions of the TVGuide self.n_items, self.hours_per_page = skin.items_per_page(('tv', self)) # end of visible guide stop_time = start_time + self.hours_per_page * 60 * 60 # constructing the guide takes some time msgtext = _('Preparing the program guide') guide = tv.epg_xmltv.get_guide(PopupBox(text=msgtext)) # getting channels channels = guide.get_programs(start_time + 1, stop_time - 1) if not channels: AlertBox(text=_('TV Guide is corrupt!')).show() return # select the first available program selected = None for chan in channels: if chan.programs: self.selected = chan.programs[0] break self.recordclient = RecordClient() self.col_time = 30 # each col represents 30 minutes self.n_cols = (stop_time - start_time) / 60 / self.col_time self.player = player self.type = 'tv' self.menuw = menuw self.visible = True self.select_time = start_time self.last_update = 0 self.lastinput_value = None self.lastinput_time = None self.update_schedules(force=True) self.event_context = 'tvmenu' self.rebuild(start_time, stop_time, guide.chan_list[0].id, selected) menuw.pushmenu(self)
def __init__(self, parent, fav, fav_action='edit'): """ """ Item.__init__(self, parent, skin_type='video') _debug_('FavoriteItem.__init__(parent=%r, fav=%r, fav_action=%r)' % (parent, fav, fav_action), 2) self.recordclient = RecordClient() self.fav = fav self.name = self.origname = fav.name self.title = fav.title self.fav_action = fav_action # twisted needs FALSE and TRUE, it does not know False and True if hasattr(fav,'allowDuplicates') and not fav.allowDuplicates: self.allowDuplicates = fav.allowDuplicates = FALSE else: self.allowDuplicates = fav.allowDuplicates = TRUE # twisted needs FALSE and TRUE, it does not know False and True if hasattr(fav,'onlyNew') and fav.onlyNew: self.onlyNew = fav.onlyNew = TRUE else: self.onlyNew = fav.onlyNew = FALSE self.week_days = (_('Mon'), _('Tue'), _('Wed'), _('Thu'), _('Fri'), _('Sat'), _('Sun')) if fav.channel == 'ANY': self.channel = _('ANY CHANNEL') else: self.channel = fav.channel if fav.dow == 'ANY': self.dow = _('ANY DAY') else: self.dow = self.week_days[int(fav.dow)] if fav.mod == 'ANY': self.mod = _('ANY TIME') else: try: self.mod = time.strftime(config.TV_TIME_FORMAT, time.gmtime(float(int(fav.mod) * 60))) except: print 'Cannot add "%s" to favorites' % fav.name # needed by the inputbox handler self.menuw = None self.red_action = (self.display_submenu,_('Edit favorite')) self.green_action = (self.rem_favorite, _('Remove favorite'))
def __init__(self, parent, prog, context='menu'): Item.__init__(self, parent, skin_type='video') logger.log(9, '__init__(parent=%r, prog=%r, context=%r)', parent, prog, context) # prog is a TvProgram object as we get it from the recordserver self.prog = prog self.context = context if hasattr(prog, 'name'): self.name = self.title = prog.name if hasattr(prog, 'title'): self.title = self.name = Unicode(prog.title) if hasattr(prog, 'sub_title'): self.sub_title = prog.sub_title if hasattr(prog, 'desc'): self.description = prog.desc if hasattr(prog, 'categories'): self.categories = prog.categories if hasattr(prog, 'ratings'): self.ratings = prog.ratings if hasattr(prog, 'advisories'): self.advisories = prog.advisories self.channel = tv_util.get_chan_displayname(prog.channel_id) if hasattr(prog, 'scheduled'): self.scheduled = prog.scheduled else: self.scheduled = False self.favorite = False if hasattr(prog, 'allowDuplicates'): self.allowDuplicates = prog.allowDuplicates else: self.allowDuplicates = 1 if hasattr(prog, 'onlyNew'): self.onlyNew = prog.onlyNew else: self.onlyNew = 0 self.overlap = prog.overlap self.start = time.strftime(config.TV_DATETIME_FORMAT, time.localtime(prog.start)) self.stop = time.strftime(config.TV_DATETIME_FORMAT, time.localtime(prog.stop)) self.recordclient = RecordClient()
def __init__(self, parent, fav, fav_action='edit'): """ """ Item.__init__(self, parent, skin_type='video') logger.log(9, 'FavoriteItem.__init__(parent=%r, fav=%r, fav_action=%r)', parent, fav, fav_action) self.recordclient = RecordClient() self.fav = fav self.name = self.origname = fav.name self.title = fav.title self.fav_action = fav_action if hasattr(fav, 'allowDuplicates'): self.allowDuplicates = int(fav.allowDuplicates) if hasattr(self.fav, 'onlyNew'): self.onlyNew = int(fav.onlyNew) self.week_days = (_('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday'), _('Sunday')) if fav.channel == 'ANY': self.channel = _('ANY CHANNEL') else: self.channel = fav.channel if fav.dow == 'ANY': self.dow = _('ANY DAY') else: self.dow = self.week_days[int(fav.dow)] if fav.mod == 'ANY': self.mod = _('ANY TIME') else: try: self.mod = time.strftime(config.TV_TIME_FORMAT, time.gmtime(float(int(fav.mod) * 60))) except: print 'Cannot add "%s" to favorites' % fav.name # needed by the inputbox handler self.menuw = None
def __init__(self, parent): _debug_('manual_record.ManualRecordItem.__init__(parent)', 2) Item.__init__(self, parent, skin_type='video') self.name = _("Manual Record") self.recordclient = RecordClient() # maxinum number of days we can record self.MAXDAYS = 7 # minimum amount of time it would take record_server.py # to pick us up in seconds by default it is one minute plus # a few seconds just in case self.MINPICKUP = 70 self.months = [ _('Jan'), _('Feb'), _('Mar'), _('Apr'), _('May'), _('Jun'), _('Jul'), _('Aug'), _('Sep'), _('Oct'), _('Nov'), _('Dec') ] now = time.time() now += 300 self.startnow = now self.starttime = time.localtime(now) now += 1900 self.stopnow = now self.stoptime = time.localtime(now)
def __init__(self, parent): _debug_('ViewFavoritesItem.__init__(parent=%r)' % (parent,), 2) Item.__init__(self, parent, skin_type='tv') self.name = _('View Favorites') self.menuw = None self.recordclient = RecordClient()
def comingup(items=None, scheduledRecordings=None): """ Coming Up for TV schedule """ from tv.record_client import RecordClient import time import codecs result = u'' cachefile = '%s/upsoon' % (config.FREEVO_CACHEDIR) if not scheduledRecordings: if os.path.exists(cachefile) and abs( time.time() - os.path.getmtime(cachefile)) < 600: cache = codecs.open(cachefile, 'r', config.encoding) for a in cache.readlines(): result = result + a cache.close() return result (status, schedule) = RecordClient().getScheduledRecordingsNow() if not status: return schedule else: (status, schedule) = scheduledRecordings if not status: return schedule # in this case the schedule is the reason progs = schedule.getProgramList() f = lambda a, b: cmp(a.start, b.start) progl = progs.values() progl.sort(f) today = [] tomorrow = [] later = [] for what in progl: if time.localtime(what.start)[2] == time.localtime()[2]: today.append(what) if time.localtime(what.start)[2] == (time.localtime()[2] + 1): tomorrow.append(what) if time.localtime(what.start)[2] > (time.localtime()[2] + 1): later.append(what) if len(today) > 0: result = result + _('Today') + u':\n' for m in today: sub_title = '' if hasattr(m, 'sub_title') and m.sub_title: sub_title = u' "' + Unicode(m.sub_title) + u'" ' result = result + u"- %s%s " % \ ( Unicode(m.title), Unicode(sub_title) ) \ + _('at') + u" %s\n" % \ Unicode(time.strftime(config.TV_TIME_FORMAT, time.localtime(m.start))) if len(tomorrow) > 0: result = result + _('Tomorrow') + u':\n' for m in tomorrow: sub_title = '' if hasattr(m, 'sub_title') and m.sub_title: sub_title = ' "' + m.sub_title + '" ' result = result + u"- %s%s " % \ ( Unicode(m.title), Unicode(sub_title) ) \ + _('at') + u" %s\n" % \ Unicode(time.strftime(config.TV_TIME_FORMAT, time.localtime(m.start))) if len(later) > 0: result = result + _('This Week') + u':\n' for m in later: sub_title = '' if hasattr(m, 'sub_title') and m.sub_title: sub_title = ' "' + m.sub_title + '" ' result = result + u"- %s%s " % ( Unicode(m.title), Unicode(sub_title) ) \ + _('at') + u" %s\n" % Unicode(time.strftime(config.TV_DATE_FORMAT, time.localtime(m.start))) if not result: result = _('No recordings are scheduled') if os.path.isfile(cachefile): os.unlink(cachefile) cache = codecs.open(cachefile, 'w', config.encoding) cache.write(result) cache.close() return result
import os import time import sys import glob import commands import config import plugin import menu import event as em from item import Item from gui import ConfirmBox from gui.AlertBox import AlertBox from tv.record_client import RecordClient from plugins.shutdown import ShutdownModes, shutdown recordclient = RecordClient() class ExInternalError: pass class ExNoRecordServer(Exception): pass class ExRecordServerRemote(Exception): pass class ExNoDefaultWakeup(Exception):
def __init__(self, parent): logger.log(9, 'ViewFavoritesItem.__init__(parent=%r)', parent) Item.__init__(self, parent, skin_type='tv') self.name = _('View Favorites') self.menuw = None self.recordclient = RecordClient()
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # ----------------------------------------------------------------------- import config import kaa from tv.record_client import RecordClient def handler(result): if result: print _('Updated recording schedule') else: print _('Not updated recording schedule') raise SystemExit rc = RecordClient() try: kaa.inprogress(rc.channel).wait() except Exception, why: print 'Cannot connect to record server' raise SystemExit print _('Updating recording schedule') if not rc.updateFavoritesSchedule(handler): print rc.recordserverdown raise SystemExit kaa.main.run()
def comingup(): """ What's coming up in the TV recording schedule """ import time import codecs from tv.record_client import RecordClient result = u'' (status, progs) = RecordClient().getScheduledRecordingsNow() if status is None: result = RecordClient().recordserverdown return result elif status is False: result = _('No recordings are scheduled') return result progs.sort(lambda a, b: cmp(a.start, b.start)) today = [] tomorrow = [] later = [] for what in progs: if time.localtime(what.start)[2] == time.localtime()[2]: today.append(what) if time.localtime(what.start)[2] == (time.localtime()[2] + 1): tomorrow.append(what) if time.localtime(what.start)[2] > (time.localtime()[2] + 1): later.append(what) if len(today) > 0: result = result + _('Today') + u':\n' for m in today: sub_title = '' if hasattr(m, 'sub_title') and m.sub_title: sub_title = u' "' + Unicode(m.sub_title) + u'" ' result = result + u"- %s%s " % \ ( Unicode(m.title), Unicode(sub_title) ) \ + _('at') + u" %s\n" % \ Unicode(time.strftime(config.TV_TIME_FORMAT, time.localtime(m.start))) if len(tomorrow) > 0: result = result + _('Tomorrow') + u':\n' for m in tomorrow: sub_title = '' if hasattr(m, 'sub_title') and m.sub_title: sub_title = ' "' + m.sub_title + '" ' result = result + u"- %s%s " % \ ( Unicode(m.title), Unicode(sub_title) ) \ + _('at') + u" %s\n" % \ Unicode(time.strftime(config.TV_TIME_FORMAT, time.localtime(m.start))) if len(later) > 0: result = result + _('This Week') + u':\n' for m in later: sub_title = '' if hasattr(m, 'sub_title') and m.sub_title: sub_title = ' "' + m.sub_title + '" ' result = result + u"- %s%s " % ( Unicode(m.title), Unicode(sub_title) ) \ + _('at') + u" %s\n" % Unicode(time.strftime(config.TV_DATE_FORMAT, time.localtime(m.start))) if not result: result = _('No recordings are scheduled') return result
usage() if len(sys.argv) > 1 and sys.argv[1] == '--query': print print 'searching for station information' chanlist = config.detect_channels() print print 'Possible list of tv channels. If you want to change the station' print 'id, copy the next statement into your local_conf.py and edit it.' print 'You can also remove lines or resort them' print print 'TV_CHANNELS = [' for c in chanlist[:-1]: print ' ( \'%s\', \'%s\', \'%s\' ), ' % c print ' ( \'%s\', \'%s\', \'%s\' ) ] ' % chanlist[-1] sys.exit(0) grab() import kaa from tv.record_client import RecordClient print 'Scheduling favorites for recording: ' if not RecordClient().updateFavoritesSchedule(handler): print RecordClient().recordserverdown raise SystemExit kaa.main.run()
def __init__(self, parent=None, subject=None, left=None, top=None, width=500, height=350, context=None): """ """ _debug_('EditFavorite.__init__(parent=%r, subject=%r, left=%r, top=%r, width=%r, height=%r, context=%r)' % \ (parent, subject, left, top, width, height, context), 1) self.oldname = None if context: self.context = context else: context = 'guide' self.recordclient = RecordClient() if isinstance(subject, TvProgram): (result, favs) = self.recordclient.getFavorites() if result: num_favorites = len(favs) self.priority = num_favorites + 1 else: self.priority = 1 self.fav = Favorite(subject.title, subject, TRUE, TRUE, TRUE, self.priority, TRUE, FALSE) else: self.fav = subject self.oldname = self.fav.name PopupBox.__init__(self, text=_('Edit Favorite'), x=left, y=top, width=width, height=height) self.v_spacing = 15 self.h_margin = 20 self.v_margin = 20 self.internal_h_align = Align.LEFT if not self.left: self.left = self.osd.width/2 - self.width/2 if not self.top: self.top = self.osd.height/2 - self.height/2 guide = epg_xmltv.get_guide() name = Label(_('Name')+':', self, Align.LEFT) self.name_input = LetterBoxGroup(text=self.fav.name) self.name_input.h_align = Align.NONE self.add_child(self.name_input) title = Label(_('Title')+': %s' % self.fav.title, self, Align.LEFT) chan = Label(_('Channel')+':', self, Align.LEFT) self.chan_box = OptionBox('ANY') self.chan_box.h_align = Align.NONE self.chan_box.add_item(text=_('ANY'), value='ANY') i = 1 chan_index = 0 for ch in guide.chan_list: #if ch.id == self.fav.channel_id: if ch.displayname == self.fav.channel: chan_index = i i += 1 self.chan_box.add_item(text=ch.displayname, value=ch.displayname) self.chan_box.toggle_selected_index(chan_index) # This is a hack for setting the OptionBox's label to the current value. # It should be done by OptionBox when drawing, but it doesn't work :( self.chan_box.change_item(None) self.add_child(self.chan_box) dow = Label(_('Day of Week') +':', self, Align.LEFT) self.dow_box = OptionBox('ANY DAY') self.dow_box.h_align = Align.NONE self.dow_box.add_item(text=_('ANY DAY'), value='ANY') i=1 dow_index = 0 for dow in (_('Mon'), _('Tue'), _('Wed'), _('Thu'), _('Fri'), _('Sat'), _('Sun')): val = "%d" % (i-1) self.dow_box.add_item(text=_(dow), value=val ) if val == self.fav.dow: dow_index = i i += 1 self.dow_box.toggle_selected_index(dow_index) # This is a hack for setting the OptionBox's label to the current value. # It should be done by OptionBox when drawing, but it doesn't work :( self.dow_box.change_item(None) self.add_child(self.dow_box) tod = Label(_('Time of Day')+':', self, Align.LEFT) self.tod_box = OptionBox('ANY') self.tod_box.h_align = Align.NONE self.tod_box.add_item(text=_('ANY TIME'), value='ANY') i = 0 tod_index = 0 for h in range(0, 24): for m in (00, 30): val = i*30 # Little hack: we calculate the hours from Jan 1st, 1970 GMT, # and then use strftime to get the string representation text = strftime(config.TV_TIME_FORMAT, gmtime(h * 3600 + 60 * m)) self.tod_box.add_item(text=text, value=val) if val == self.fav.mod: tod_index = i+1 i += 1 self.tod_box.toggle_selected_index(tod_index) # This is a hack for setting the OptionBox's label to the current # value. It should be done by OptionBox when drawing, but it doesn't # work :( self.tod_box.change_item(None) self.add_child(self.tod_box) self.save = Button(_('Save')) self.add_child(self.save) if self.oldname: self.remove = Button(_('Remove')) self.add_child(self.remove) else: self.remove = None self.cancel = Button(_('CANCEL')) self.add_child(self.cancel)
def __init__(self, parent): Item.__init__(self, parent, skin_type='tv') self.name = _('Scheduled Recordings') self.menuw = None self.recordclient = RecordClient()
if not self.standalone: AlertBox( text=_('%s stopped, a recording is about to start!') % self.stopped, height=200).show() self.stopped = None return 0 if __name__ == '__main__': # test code, run with freevo execute /path/to/upsoon.py config.DEBUG = 2 function = None if len(sys.argv) > 1: function = sys.argv[1].lower() server = RecordClient() if function == 'run': #import rc as rctrl #rc = rctrl.get_singleton(False) pi = PluginInterface() kaa.main.run() elif function == 'findnextprogram': def handler(result): print 'findnextprogram=%r' % (result, ) print result.__dict__ raise SystemExit server.findNextProgram(handler)