def get_programs(start=0, stop=0, channel_id=None): kwargs = {'time': (start, stop)} if channel_id is not None: if isinstance(channel_id, (list, tuple)): selected_channels = [] channels = [] for channel in channel_id: if isinstance(channel, TvChannel): channel = channel.id channels.append(kaa.epg.get_channel_by_tuner_id(channel)) selected_channels.append(channel) kwargs['channel'] = channels else: if isinstance(channel_id, TvChannel): channel_id = channel_id.id kwargs['channel'] = kaa.epg.get_channel_by_tuner_id(channel_id) selected_channels = [channel_id] else: selected_channels = None try: progs = kaa.epg.search(**kwargs).wait() except EPGError: progs = [] channel_dict = {} for prog in progs: tuner_id = prog.channel.tuner_id[0] tv_prog = DbTvProgram(prog) channel_dict.setdefault(tuner_id, []).append(tv_prog) channels = [] for channel_details in config.TV_CHANNELS: if selected_channels is None or channel_details[0] in selected_channels: channel = TvChannel(channel_details[0], channel_details[1], channel_details[2]) if channel_details[0] in channel_dict: channel.programs = channel_dict[channel_details[0]] channels.append(channel) return channels
def get_programs(start=0, stop=0, channel_id=None): kwargs = { 'time': (start,stop)} if channel_id is not None: if isinstance(channel_id, (list,tuple)): selected_channels = [] channels = [] for channel in channel_id: if isinstance(channel, TvChannel): channel = channel.id channels.append(kaa.epg.get_channel_by_tuner_id(channel)) selected_channels.append(channel) kwargs['channel'] = channels else: if isinstance(channel_id, TvChannel): channel_id = channel_id.id kwargs['channel'] = kaa.epg.get_channel_by_tuner_id(channel_id) selected_channels = [channel_id] else: selected_channels = None try: progs = kaa.epg.search(**kwargs).wait() except EPGError: progs = [] channel_dict = {} for prog in progs: tuner_id = prog.channel.tuner_id[0] tv_prog = DbTvProgram(prog) channel_dict.setdefault(tuner_id, []).append(tv_prog) channels = [] for channel_details in config.TV_CHANNELS: if selected_channels is None or channel_details[0] in selected_channels: channel = TvChannel(channel_details[0], channel_details[1], channel_details[2]) if channel_details[0] in channel_dict: channel.programs = channel_dict[channel_details[0]] channels.append(channel) return channels
if config.HELPER_APP in ['recordserver', 'tvmanager']: print 'Starting EPG server' kaa.epg.listen(('', 10000), config.RECORDSERVER_SECRET) else: print 'Connecting to EPG server' kaa.epg.connect((config.RECORDSERVER_IP, 10000), config.RECORDSERVER_SECRET) EPG_LOCAL = False channels = [] channels_by_id = {} channels_by_tuner_id = {} channels_by_display_name = {} for channel_details in config.TV_CHANNELS: channel = TvChannel(channel_details[0], channel_details[1], channel_details[2]) if len(channel_details) > 3 and len(channel_details[3:4]) == 3: for (days, start_time, stop_time) in channel_details[3:4]: channel.times.append((days, int(start_time), int(stop_time))) channels.append(channel) channels_by_id[channel_details[0]] = channel channels_by_tuner_id[channel.tunerid] = channel channels_by_display_name[channel.displayname] = channel def get_grid(start, stop, channels): import tv.record_client rpc_channel = tv.record_client.RecordClient().channel if rpc_channel.status != kaa.rpc.CONNECTED:
def load_guide(XMLTV_FILE=None, popup_dialog=None): """ Load a guide from the raw XMLTV file using the xmltv.py support lib. Returns a TvGuide or None if an error occurred """ if not XMLTV_FILE: XMLTV_FILE = config.XMLTV_FILE # Create a new guide guide = TvGuide() # Is there a file to read from? if os.path.isfile(XMLTV_FILE): gotfile = 1 guide.timestamp = os.path.getmtime(XMLTV_FILE) else: logger.debug('XMLTV file (%s) missing!', XMLTV_FILE) gotfile = 0 if popup_dialog: popup_dialog.update_progress(_('Reading channels'), 0.0) # Add the channels that are in the config list, or all if the # list is empty if config.TV_CHANNELS: logger.debug('Only adding channels in TV_CHANNELS to TvGuide') for data in config.TV_CHANNELS: (id, displayname, tunerid) = data[:3] c = TvChannel(id, displayname, tunerid) # Handle the optional time-dependent station info c.times = [] if len(data) > 3 and len(data[3:4]) == 3: for (days, start_time, stop_time) in data[3:4]: c.times.append((days, int(start_time), int(stop_time))) guide.add_channel(c) else: # Add all channels in the XMLTV file logger.debug('Adding all channels to TvGuide') xmltv_channels = None if gotfile: # Don't read the channel info unless we have to, takes a long time! xmltv_channels = xmltv.read_channels(util.gzopen(XMLTV_FILE)) # Was the guide read successfully? if not xmltv_channels: return None # No for chan in xmltv_channels: id = chan['id'].encode(config.LOCALE, 'ignore') if ' ' in id: # Assume the format is "TUNERID CHANNELNAME" tunerid = id.split()[0] # XXX Educated guess displayname = id.split()[1] # XXX Educated guess else: display_name = chan['display-name'][0][0] if ' ' in display_name: tunerid = display_name.split()[0] displayname = display_name.split()[1] else: tunerid = _('REPLACE WITH TUNERID FOR %s') % display_name displayname = display_name c = TvChannel(id, displayname, tunerid) guide.add_channel(c) if popup_dialog: popup_dialog.update_progress(_('Reading programmes'), 0.25) xmltv_programs = None if gotfile: logger.debug('reading \"%s\" xmltv data', XMLTV_FILE) f = util.gzopen(XMLTV_FILE) xmltv_programs = xmltv.read_programmes(f) f.close() # Was the guide read successfully? if not xmltv_programs: return guide # Return the guide, it has the channels at least... needed_ids = [] for chan in guide.chan_dict: needed_ids.append(chan) logger.debug('creating guide for %s', needed_ids) if popup_dialog: popup_dialog.update_progress(_('Processing programmes'), 0.50) for p in xmltv_programs: if not p['channel'] in needed_ids: continue try: channel_id = p['channel'] date = 'date' in p and Unicode(p['date']) or '' start = '' pdc_start = '' stop = '' title = Unicode(p['title'][0][0]) desc = 'desc' in p and Unicode(util.format_text(p['desc'][0][0])) or '' sub_title = 'sub-title' in p and Unicode(p['sub-title'][0][0]) or '' categories = 'category' in p and [ cat[0] for cat in p['category'] ] or '' advisories = [] ratings = {} # Add credits to the description if 'credits' in p: desc += Unicode('\n\n') desc += _('Credits :\n') credits = p['credits'] if 'actor' in credits: desc += Unicode('\n') desc += _('Actors :\n') for actor in credits['actor']: desc += Unicode(actor + '\n') if 'director' in credits: desc += Unicode('\n') directors = credits['director'] if len(directors) == 1: desc += _('Director : %s') % directors[0] else: desc += _('Directors :\n') for d in directors: desc += Unicode(d + '\n') if 'rating' in p: for r in p['rating']: if r.get('system') == 'advisory': advisories.append(String(r.get('value'))) continue ratings[String(r.get('system'))] = String(r.get('value')) try: start = timestr2secs_utc(p['start']) pdc_start = 'pdc_start' in p and timestr2secs_utc(p['pdc_start']) or start try: stop = timestr2secs_utc(p['stop']) except: # Fudging end time stop = timestr2secs_utc(p['start'][0:8] + '235900' + p['start'][14:18]) except EpgException, why: logger.warning('EpgException: %s', why) continue # fix bad German titles to make favorites work if title.endswith('. Teil'): title = title[:-6] if title.rfind(' ') > 0: try: part = int(title[title.rfind(' ')+1:]) title = title[:title.rfind(' ')].rstrip() if sub_title: sub_title = u'Teil %s: %s' % (part, sub_title) else: sub_title = u'Teil %s' % part except Exception, e: print 'Teil:', e prog = TvProgram(channel_id, start, pdc_start, stop, title, sub_title, desc, categories, ratings) prog.advisories = advisories prog.date = date guide.add_program(prog)