コード例 #1
0
	def do_epg_alias(self):
		self.log("--- START PROCESSING ---")
		self.log("Loading lamedb indexed by channel name")
		lamedb = scriptlib.lamedb_class()

		self.log("Initialize CrossEPG database")
		crossdb = scriptlib.crossepg_db_class()
		crossdb.open_db()

		total_events = 0

		for src_channel in self.CHANNELLIST :

			dst_channels = self.CHANNELLIST[src_channel].split(',')

			if src_channel.count('-') == 1 :
				src_chname = src_channel.split('-')[0].strip(' \n\r').lower()
				src_provname = src_channel.split('-')[1].strip(' \n\r').lower()

				src_sidbyname = []
				src_sidprovidbyname = lamedb.get_sidprovid_byname(src_chname)
				for p in src_sidprovidbyname:
					if p[1] == src_provname :
						# a channel can have zero or more SID (different channel with same name)
						# return the list [ 0e1f:00820000:0708:00c8:1:0 , 1d20:00820000:2fa8:013e:1:0 , ..... ]
						# return [] if channel name is not in lamedb
						src_sidbyname = p[0]
						ch_sid = lamedb.convert_sid(src_sidbyname)
						if len(ch_sid) == 0 :
							self.log("SID \"%s\" invalid, try next" % src_sidbyname)
							continue

						src_epgdb_channel = crossepg.epgdb_channels_get_by_freq(ch_sid[2],ch_sid[1],ch_sid[0]);
						if not src_epgdb_channel :
							self.log('Source channel "%s" with SID "%s" has not entry in epgdb, try next' % (src_channel,src_sidbyname) )
							continue
						else:
							break

				# if not sid then exit, go ahead with next src_channel
				if len(src_sidbyname) == 0:
					self.log('Source channel "%s" has not SID in lamedb, skip it' % src_channel)
					continue

			elif src_channel.count('-') == 2 :
				tmp = src_channel.split('-')
				src_sidbyname = "%s:xxxxxxxx:%s:%s:x:x" %(tmp[0].strip(' \n\r'),tmp[1].strip(' \n\r'),tmp[2].strip(' \n\r'))

			else:
				self.log("Channel source \"%s\" invalid" % src_channel)
				continue

			# convert "0e1f:00820000:0708:00c8:1:0" to sid,tsid,onid
			# return the list [sid,tsid,onid]
			src_sid = lamedb.convert_sid(src_sidbyname)
			if len(src_sid) == 0 :
				self.log("SID \"%s\" invalid, try next" % src_sidbyname)
				continue

			src_epgdb_channel = crossepg.epgdb_channels_get_by_freq(src_sid[2],src_sid[1],src_sid[0]);
			if not src_epgdb_channel :
				self.log('Source channel "%s" with SID "%s" has not entry in epgdb, skip it' % (src_channel,src_sidbyname) )
				continue

			self.log('Source channel "%s" with SID "%s" found in epgdb, using it' % (src_channel,src_sidbyname) )

			for dst in dst_channels:
				dst = dst.strip(' \n\r').lower()
				dst_sidbyname = lamedb.get_sid_byname(dst)
				if len(dst_sidbyname) == 0:
					self.log('   dest. channel "%s" has not SID in lamedb, skip it' % dst)
					continue

				for dsid in dst_sidbyname:

					# convert "0e1f:00820000:0708:00c8:1:0" to sid,tsid,onid
					# return the list [sid,tsid,onid]
					dst_sid = lamedb.convert_sid(dsid)

					if dst_sid == src_sid:
						# skip if source=destination
						self.log('   dest. channel "%s" is eq. to source, skip it' % dst)
						continue

					num_events = 0
					self.log('   copying EPG data from "%s" to "%s" sid "%s")' % (src_channel,dst,dsid) )
					self.log2video("%s -> %s (%d/%d)" % (src_channel,dst,num_events,total_events))


					# add channel into db
					# doesn't matter if the channel already exist... epgdb do all the work
					# this make a reference to the dest. channel
					crossdb.add_channel(dst_sid)

					title = src_epgdb_channel.title_first;

					while (title != None) :
						#print str(title.start_time)
						#print str(title.length)
						#print str(crossepg.epgdb_read_description(title))
						#print str(crossepg.epgdb_read_long_description(title))
						#print "-----------------------------------"

						e_starttime = int(title.start_time)
						e_length = int(title.length)
						e_title = crossepg.epgdb_read_description(title).encode('utf-8')
						e_summarie = crossepg.epgdb_read_long_description(title).encode('utf-8')
						e_countrycode = "%c%c%c" % (title.iso_639_1, title.iso_639_2, title.iso_639_3)

						# add_event(start_time , duration , title , summarie , ISO639_language_code , strings_encoded_with_UTF-8)
						crossdb.add_event(e_starttime, e_length, e_title, e_summarie, e_countrycode, True )
						num_events += 1
						title = title.next

						if (num_events % 25) == 0:
							self.log2video("%s -> %s (%d/%d)" % (src_channel,dst,num_events,total_events))


					total_events += num_events
					self.log("   copied %d events" % num_events)

		self.log2video("end: copied %d events" % (total_events))
		# end process, close CrossEPG DB saving data
		crossdb.close_db()
		self.log("Copied %d events" % total_events)
		self.log("--- END ---")
コード例 #2
0
ファイル: rai.py プロジェクト: iz0bbz/e2openplugin-CrossEPG
	def process_cache(self):
		self.log.log("--- START PROCESSING CACHE ---")
		self.log.log2video_status("START PROCESSING CACHE")
		if not os.path.exists(self.CONF_CACHEDIR):
			self.log.log("ERROR: %s not present" % self.CONF_CACHEDIR)
			sys.exit(1)

		self.log.log("Loading lamedb")
		lamedb = scriptlib.lamedb_class()

		self.log.log("Initialize CrossEPG database")
		crossdb = scriptlib.crossepg_db_class()
		crossdb.open_db()

		events = []
		previous_id = ''
		channels_name = ''
		total_events = 0

		self.log.log("Start data processing")
		filelist = sorted(os.listdir(self.CONF_CACHEDIR))
		filelist.append('***END***')

		for f in filelist :
			id = f.split(self.FIELD_SEPARATOR)[0]
			if previous_id == '':
				previous_id = id

			if id != previous_id :
				total_events += len(events)
				self.log.log("  ...processing \'%s\' , nr. events %d" % (previous_id,len(events)))
				self.log.log2video_status("processed %d events ..." % total_events )

				for c in channels_name:
					# a channel can have zero or more SID (different channel with same name)
					# return the list [0e1f:00820000:0708:00c8:1:0 , 1d20:00820000:2fa8:013e:1:0 , ..... ]
					# return [] if channel name is not in lamedb
					sidbyname = lamedb.get_sid_byname(c.strip(' \n').lower())

					# process every SID
					for s in sidbyname:
						# convert "0e1f:00820000:0708:00c8:1:0" to sid,tsid,onid
						# return the list [sid,tsid,onid]
						ch_sid = lamedb.convert_sid(s)
						if len(ch_sid) == 0:
							continue

						# add channel into db
						# doesn't matter if the channel already exist... epgdb do all the work
						crossdb.add_channel(ch_sid)

						i = 0
						L = len(events) - 1

						# process events
						for e in events:

							e_starttime = int(e.split(self.FIELD_SEPARATOR)[1])

							if i < L :
								e_length = int(events[i+1].split(self.FIELD_SEPARATOR)[1]) - e_starttime
							else:
								# last event, dummy length 90 min.
								e_length = 5400
							i += 1

							# extract title and encode Python Unicode with UTF-8
							e_title = e.split(self.FIELD_SEPARATOR)[2].encode('utf-8')
							e_summarie = e.split(self.FIELD_SEPARATOR)[3].encode('utf-8')
							# add_event(start_time , duration , title , summarie , ISO639_language_code , strings_encoded_with_UTF-8)
							crossdb.add_event(e_starttime, e_length, e_title, e_summarie, 'ita', True )

				if f == '***END***':
					break

				events = []
				previous_id = id
				channels_name = ''

			if id == previous_id:
				self.log.log("Reading  \'%s\'" % f)
				# read events from cache file using UTF-8 and insert them in events list
				fd = codecs.open(os.path.join(self.CONF_CACHEDIR, f),"r","utf-8")
				lines = fd.readlines()
				fd.close()
				if channels_name == '':
					# first line has channel data (id,name,provider,date)
					channels_name = lines[0].split(self.FIELD_SEPARATOR)[1].split('|')
				# the second line is only a remark
				# add events starting from third line
				events.extend(lines[2:])

		# end process, close CrossEPG DB saving data
		crossdb.close_db()
		self.log.log("TOTAL EPG EVENTS PROCESSED: %d" % total_events)
		self.log.log("--- END ---")
		self.log.log2video_status("END, events processed: %d" % total_events)
		time.sleep(3)
コード例 #3
0
    def process_cache(self):
        self.log("--- START PROCESSING CACHE ---")
        self.log2video("START PROCESSING CACHE")
        if not os.path.exists(self.CONF_CACHEDIR):
            self.log("ERROR: %s not present" % self.CONF_CACHEDIR, 1)
            sys.exit(1)

        self.log("Loading lamedb")
        lamedb = scriptlib.lamedb_class()

        self.log("Initialize CrossEPG database")
        crossdb = scriptlib.crossepg_db_class()
        crossdb.open_db()

        events = []
        previous_id = ''
        channels_name = ''
        total_events = 0

        self.log("Start data processing")
        filelist = sorted(os.listdir(self.CONF_CACHEDIR))
        filelist.append('***END***')

        for f in filelist:
            id = f.split(self.FIELD_SEPARATOR)[0]
            if previous_id == '':
                previous_id = id

            if id != previous_id:
                total_events += len(events)
                self.log("  ...processing \'%s\' , nr. events %d" %
                         (previous_id, len(events)))
                self.log2video("processed %d events ..." % total_events)

                for c in channels_name:
                    # a channel can have zero or more SID (different channel with same name)
                    # return the list [0e1f:00820000:0708:00c8:1:0 , 1d20:00820000:2fa8:013e:1:0 , ..... ]
                    # return [] if channel name is not in lamedb
                    sidbyname = lamedb.get_sid_byname(c.strip(' \n').lower())

                    # process every SID
                    for s in sidbyname:
                        # convert "0e1f:00820000:0708:00c8:1:0" to sid,tsid,onid
                        # return the list [sid,tsid,onid]
                        ch_sid = lamedb.convert_sid(s)
                        if len(ch_sid) == 0:
                            continue

                        # add channel into db
                        # doesn't matter if the channel already exist... epgdb do all the work
                        crossdb.add_channel(ch_sid)

                        i = 0
                        L = len(events) - 1

                        # process events
                        for e in events:

                            items = e.split(self.FIELD_SEPARATOR)
                            e_starttime = int(items[1])

                            if i < L:
                                e_length = int(events[i + 1].split(
                                    self.FIELD_SEPARATOR)[1]) - e_starttime
                            else:
                                # last event, dummy length 90 min.
                                e_length = 5400
                            i += 1

                            # extract title and encode Python Unicode with UTF-8
                            e_title = items[2].encode('utf-8')

                            # extract summarie and encode Python Unicode with UTF-8
                            e_summarie = items[3].encode('utf-8')

                            # add_event(start_time , duration , title , summarie , ISO639_language_code , strings_encoded_with_UTF-8)
                            crossdb.add_event(e_starttime, e_length, e_title,
                                              e_summarie, 'ita', True)

                if f == '***END***':
                    break

                events = []
                previous_id = id
                channels_name = ''

            if id == previous_id:
                self.log("Reading  \'%s\'" % f)
                # read events from cache file using UTF-8 and insert them in events list
                fd = codecs.open(os.path.join(self.CONF_CACHEDIR, f), "r",
                                 "utf-8")
                lines = fd.readlines()
                fd.close()
                if channels_name == '':
                    # first line has channel data (id,name,provider,date)
                    channels_name = lines[0].split(
                        self.FIELD_SEPARATOR)[1].split('|')
                # the second line is only a remark
                # add events starting from third line
                events.extend(lines[2:])

        # end process, close CrossEPG DB saving data
        crossdb.close_db()
        self.log("TOTAL EPG EVENTS PROCESSED: %d" % total_events)
        self.log("--- END ---")
        self.log2video("END , events processed: %d" % total_events)