def getCurrentTsidOnid(self, from_retune=False): adapter = 0 demuxer_device = "/dev/dvb/adapter%d/demux%d" % (adapter, self.demuxer_id) start = time.time() # for debug info sdt_pid = 0x11 sdt_current_table_id = 0x42 mask = 0xff tsidOnidTimeout = 5 # maximum time allowed to read the service descriptor table (seconds) self.tsid = None self.onid = None fd = dvbreader.open(demuxer_device, sdt_pid, sdt_current_table_id, mask, self.selectedNIM) if fd < 0: print( "[ABM-FrequencyFinder][getCurrentTsidOnid] Cannot open the demuxer" ) return None timeout = datetime.datetime.now() timeout += datetime.timedelta(0, tsidOnidTimeout) while True: if datetime.datetime.now() > timeout: print("[ABM-FrequencyFinder][getCurrentTsidOnid] Timed out") break section = dvbreader.read_sdt(fd, sdt_current_table_id, 0x00) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == sdt_current_table_id: self.tsid = section["header"]["transport_stream_id"] self.onid = section["header"]["original_network_id"] break print( "[ABM-FrequencyFinder][getCurrentTsidOnid] Read time %.1f seconds." % (time.time() - start)) dvbreader.close(fd)
def getCurrentTsidOnid(self, from_retune = False): adapter = 0 demuxer_device = "/dev/dvb/adapter%d/demux%d" % (adapter, self.demuxer_id) start = time.time() # for debug info sdt_pid = 0x11 sdt_current_table_id = 0x42 mask = 0xff tsidOnidTimeout = 5 # maximum time allowed to read the service descriptor table (seconds) self.tsid = None self.onid = None fd = dvbreader.open(demuxer_device, sdt_pid, sdt_current_table_id, mask, self.selectedNIM) if fd < 0: print "[TerrestrialScan][getCurrentTsidOnid] Cannot open the demuxer" return None timeout = datetime.datetime.now() timeout += datetime.timedelta(0, tsidOnidTimeout) while True: if datetime.datetime.now() > timeout: print "[TerrestrialScan][getCurrentTsidOnid] Timed out" break section = dvbreader.read_sdt(fd, sdt_current_table_id, 0x00) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == sdt_current_table_id: self.tsid = section["header"]["transport_stream_id"] self.onid = section["header"]["original_network_id"] break print "[TerrestrialScan][getCurrentTsidOnid] Read time %.1f seconds." % (time.time() - start) dvbreader.close(fd)
def updateAndReadServicesLCN(self, namespace, transponders, servicehacks, transport_stream_id_list, logical_channel_number_dict, service_dict_tmp): print>>log, "[DvbScanner] Reading services..." if self.sdt_other_table_id == 0x00: mask = 0xff else: mask = self.sdt_current_table_id ^ self.sdt_other_table_id ^ 0xff fd = dvbreader.open(self.demuxer_device, self.sdt_pid, self.sdt_current_table_id, mask, self.frontend) if fd < 0: print>>log, "[DvbScanner] Cannot open the demuxer" return None sdt_secions_status = {} for transport_stream_id in transport_stream_id_list: sdt_secions_status[transport_stream_id] = {} sdt_secions_status[transport_stream_id]["section_version"] = -1 sdt_secions_status[transport_stream_id]["sections_read"] = [] sdt_secions_status[transport_stream_id]["sections_count"] = 0 sdt_secions_status[transport_stream_id]["content"] = [] timeout = datetime.datetime.now() timeout += datetime.timedelta(0, self.TIMEOUT_SEC) while True: if datetime.datetime.now() > timeout: print>>log, "[DvbScanner] Timed out" break section = dvbreader.read_sdt(fd, self.sdt_current_table_id, self.sdt_other_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == self.sdt_current_table_id or section["header"]["table_id"] == self.sdt_other_table_id: if section["header"]["transport_stream_id"] not in transport_stream_id_list: continue transport_stream_id = section["header"]["transport_stream_id"] if section["header"]["version_number"] != sdt_secions_status[transport_stream_id]["section_version"]: sdt_secions_status[transport_stream_id]["section_version"] = section["header"]["version_number"] sdt_secions_status[transport_stream_id]["sections_read"] = [] sdt_secions_status[transport_stream_id]["content"] = [] sdt_secions_status[transport_stream_id]["sections_count"] = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in sdt_secions_status[transport_stream_id]["sections_read"]: sdt_secions_status[transport_stream_id]["sections_read"].append(section["header"]["section_number"]) sdt_secions_status[transport_stream_id]["content"] += section["content"] if len(sdt_secions_status[transport_stream_id]["sections_read"]) == sdt_secions_status[transport_stream_id]["sections_count"]: transport_stream_id_list.remove(transport_stream_id) if len(transport_stream_id_list) == 0: break if len(transport_stream_id_list) > 0: print>>log, "[DvbScanner] Cannot fetch SDT for the following transport_stream_id list: ", transport_stream_id_list dvbreader.close(fd) service_count = 0 tmp_services_dict = {} for key in sdt_secions_status: for section in sdt_secions_status[key]["content"]: service = section key = "%x:%x:%x" % (service["transport_stream_id"], service["original_network_id"], service["service_id"]) if logical_channel_number_dict and (key not in logical_channel_number_dict or logical_channel_number_dict[key]["visible_service_flag"] == 0): continue if service_dict_tmp and key not in service_dict_tmp: continue service["namespace"] = namespace service["flags"] = 0 if not logical_channel_number_dict: service["number"] = service["logical_channel_number"] if service["service_type"] == 1 and (service["service_group_id"] == 17 or service["service_group_id"] == 21): service["service_type"] = 17 else: service["number"] = logical_channel_number_dict[key]["logical_channel_number"] if key in tmp_services_dict: tmp_services_dict[key]["numbers"].append(service["number"]) else: service["numbers"] = [service["number"]] tmp_services_dict[key] = service service_count += 1 print>>log, "[DvbScanner] Read %d services" % service_count video_services = {} radio_services = {} service_extra_count = 0 for key in tmp_services_dict: service = tmp_services_dict[key] if len(servicehacks) > 0: skip = False exec(servicehacks) if skip: continue tpkey = "%x:%x:%x" % (service["namespace"], service["transport_stream_id"], service["original_network_id"]) if tpkey not in transponders: continue transponders[tpkey]["services"][service["service_id"]] = service service_extra_count += 1 if service["service_type"] in DvbScanner.VIDEO_ALLOWED_TYPES or service["service_type"] in DvbScanner.INTERACTIVE_ALLOWED_TYPES: for number in service["numbers"]: if number not in video_services: video_services[number] = service else: for number in service["numbers"]: if number not in radio_services: radio_services[number] = service print>>log, "[DvbScanner] %d valid services" % service_extra_count return { "video": video_services, "radio": radio_services }
def updateTransponders(self, transponders, read_other_section = False, netid = None, bouquettype = None): print>>log, "[DvbScanner] Reading transponders..." if self.nit_other_table_id == 0x00: mask = 0xff else: mask = self.nit_current_table_id ^ self.nit_other_table_id ^ 0xff print>>log, "[DvbScanner] demuxer_device", str(self.demuxer_device) print>>log, "[DvbScanner] nit_pid", str(self.nit_pid) print>>log, "[DvbScanner] nit_current_table_id", str(self.nit_current_table_id) print>>log, "[DvbScanner] mask", str(mask) print>>log, "[DvbScanner] frontend", str(self.frontend) fd = dvbreader.open(self.demuxer_device, self.nit_pid, self.nit_current_table_id, mask, self.frontend) if fd < 0: print>>log, "[DvbScanner] Cannot open the demuxer" return None nit_current_section_version = -1 nit_current_section_network_id = -1 nit_current_sections_read = [] nit_current_sections_count = 0 nit_current_content = [] nit_current_completed = False nit_other_section_version = -1 nit_other_section_network_id = -1 nit_other_sections_read = [] nit_other_sections_count = 0 nit_other_content = [] nit_other_completed = not read_other_section or self.nit_other_table_id == 0x00 timeout = datetime.datetime.now() timeout += datetime.timedelta(0, self.TIMEOUT_SEC) while True: if datetime.datetime.now() > timeout: print>>log, "[DvbScanner] Timed out" break section = dvbreader.read_nit(fd, self.nit_current_table_id, self.nit_other_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if (section["header"]["table_id"] == self.nit_current_table_id and self.dvbtype != 'dvbc' and not nit_current_completed): if (section["header"]["version_number"] != nit_current_section_version or section["header"]["network_id"] != nit_current_section_network_id): nit_current_section_version = section["header"]["version_number"] nit_current_section_network_id = section["header"]["network_id"] nit_current_sections_read = [] nit_current_content = [] nit_current_sections_count = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in nit_current_sections_read: nit_current_sections_read.append(section["header"]["section_number"]) nit_current_content += section["content"] if len(nit_current_sections_read) == nit_current_sections_count: nit_current_completed = True elif (str(section["header"]["network_id"]) == str(netid) and self.dvbtype == 'dvbc' and not nit_current_completed): if (section["header"]["version_number"] != nit_current_section_version or section["header"]["network_id"] != nit_current_section_network_id): nit_current_section_version = section["header"]["version_number"] nit_current_section_network_id = section["header"]["network_id"] nit_current_sections_read = [] nit_current_content = [] nit_current_sections_count = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in nit_current_sections_read: nit_current_sections_read.append(section["header"]["section_number"]) nit_current_content += section["content"] if len(nit_current_sections_read) == nit_current_sections_count: nit_current_completed = True nit_other_completed = True elif section["header"]["table_id"] == self.nit_other_table_id and not nit_other_completed: if (section["header"]["version_number"] != nit_other_section_version or section["header"]["network_id"] != nit_other_section_network_id): nit_other_section_version = section["header"]["version_number"] nit_other_section_network_id = section["header"]["network_id"] nit_other_sections_read = [] nit_other_content = [] nit_other_sections_count = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in nit_other_sections_read: nit_other_sections_read.append(section["header"]["section_number"]) nit_other_content += section["content"] if len(nit_other_sections_read) == nit_other_sections_count: nit_other_completed = True if nit_current_completed and nit_other_completed: print>>log, "[DvbScanner] Scan complete, netid: ", str(netid) break dvbreader.close(fd) nit_content = nit_current_content nit_content += nit_other_content transport_stream_id_list = [] logical_channel_number_dict = {} logical_channel_number_dict_tmp = {} hd_logical_channel_number_dict_tmp = {} service_dict_tmp ={} transponders_count = 0 for transponder in nit_content: if len(transponder) == 4: # service key = "%x:%x:%x" % (transponder["transport_stream_id"], transponder["original_network_id"], transponder["service_id"]) service_dict_tmp[key] = transponder continue if len(transponder) == 5: # lcn key = "%x:%x:%x" % (transponder["transport_stream_id"], transponder["original_network_id"], transponder["service_id"]) logical_channel_number_dict_tmp[key] = transponder continue if len(transponder) == 6: # HD lcn key = "%x:%x:%x" % (transponder["transport_stream_id"], transponder["original_network_id"], transponder["service_id"]) hd_logical_channel_number_dict_tmp[key] = transponder continue transponder["services"] = {} transponder["dvb_type"] = self.dvbtype transponder["bouquet_type"] = bouquettype if transponder["dvb_type"] == 'dvbc': # DVB-C transponder["symbol_rate"] = transponder["symbol_rate"] * 100 transponder["flags"] = 0 if transponder["fec_inner"] != 15 and transponder["fec_inner"] > 9: transponder["fec_inner"] = 0 transponder["frequency"] = transponder["frequency"] / 10 transponder["namespace"] = 0xFFFF0000 transponder["inversion"] = transponder["fec_outer"] transponder["modulation_system"] = 0 elif transponder["dvb_type"] == 'dvbt': # DVB-T transponder["namespace"] = 0xEEEE0000 transponder["frequency"] = transponder["frequency"] * 10 transponder["inversion"] = 0 transponder["plpid"] = 0 transponder["flags"] = 0 transponder["system"] = 0 elif transponder["dvb_type"] == 'dvbs': # DVB-S transponder["symbol_rate"] = transponder["symbol_rate"] * 100 transponder["flags"] = 0 if transponder["fec_inner"] != 15 and transponder["fec_inner"] > 9: transponder["fec_inner"] = 0 transponder["frequency"] = transponder["frequency"] * 10 orbital_position = ((transponder["orbital_position"] >> 12) & 0x0F) * 1000 orbital_position += ((transponder["orbital_position"] >> 8) & 0x0F) * 100 orbital_position += ((transponder["orbital_position"] >> 4) & 0x0F) * 10 orbital_position += transponder["orbital_position"] & 0x0F if orbital_position != 0 and transponder["west_east_flag"] == 0: orbital_position = 3600 - orbital_position transponder["orbital_position"] = orbital_position transponder["pilot"] = 2 if transponder["modulation_system"] == 0 and transponder["modulation_type"] == 2: transponder["modulation_type"] = 1 transponder["inversion"] = 2 transponder["namespace"] = self.buildNamespace(transponder) key = "%x:%x:%x" % (transponder["namespace"], transponder["transport_stream_id"], transponder["original_network_id"]) if key in transponders: transponder["services"] = transponders[key]["services"] transponders[key] = transponder transponders_count += 1 if transponder["transport_stream_id"] not in transport_stream_id_list: transport_stream_id_list.append(transponder["transport_stream_id"]) if read_other_section: print>>log, "[DvbScanner] Added/Updated %d transponders with network_id = 0x%x and network_id = 0x%x" % (transponders_count, nit_current_section_network_id, nit_other_section_network_id) else: print>>log, "[DvbScanner] Added/Updated %d transponders with network_id = 0x%x" % (transponders_count, nit_current_section_network_id) if len(hd_logical_channel_number_dict_tmp) > 0 and bouquettype == 'hd': for id in logical_channel_number_dict_tmp: if id in hd_logical_channel_number_dict_tmp: lcntofind = hd_logical_channel_number_dict_tmp[id]["logical_channel_number"] lcnreplace = logical_channel_number_dict_tmp[id]["logical_channel_number"] for id2 in logical_channel_number_dict_tmp: if logical_channel_number_dict_tmp[id2]["logical_channel_number"] == lcntofind: logical_channel_number_dict[id] = logical_channel_number_dict_tmp[id2] logical_channel_number_dict[id]["logical_channel_number"] = lcnreplace logical_channel_number_dict[id] = hd_logical_channel_number_dict_tmp[id] else: logical_channel_number_dict[id] = logical_channel_number_dict_tmp[id] else: for id in logical_channel_number_dict_tmp: logical_channel_number_dict[id] = logical_channel_number_dict_tmp[id] return { "transport_stream_id_list": transport_stream_id_list, "logical_channel_number_dict": logical_channel_number_dict, "service_dict_tmp": service_dict_tmp }
def readSDT(self): adapter = 0 demuxer_device = "/dev/dvb/adapter%d/demux%d" % (adapter, self.demuxer_id) self.tsid = None self.onid = None sdt_pid = 0x11 sdt_current_table_id = 0x42 mask = 0xff sdtTimeout = 5 # maximum time allowed to read the service descriptor table (seconds) sdt_current_version_number = -1 sdt_current_sections_read = [] sdt_current_sections_count = 0 sdt_current_content = [] sdt_current_completed = False fd = dvbreader.open(demuxer_device, sdt_pid, sdt_current_table_id, mask, self.selectedNIM) if fd < 0: print "[MakeBouquet][readSDT] Cannot open the demuxer" return None timeout = datetime.datetime.now() timeout += datetime.timedelta(0, sdtTimeout) while True: if datetime.datetime.now() > timeout: print "[Satfinder][getCurrentTsidOnid] Timed out" break section = dvbreader.read_sdt(fd, sdt_current_table_id, 0x00) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == sdt_current_table_id and not sdt_current_completed: if section["header"]["version_number"] != sdt_current_version_number: sdt_current_version_number = section["header"]["version_number"] sdt_current_sections_read = [] sdt_current_sections_count = section["header"]["last_section_number"] + 1 sdt_current_content = [] if section["header"]["section_number"] not in sdt_current_sections_read: sdt_current_sections_read.append(section["header"]["section_number"]) sdt_current_content += section["content"] if self.tsid is None or self.onid is None: # save first read of tsid and onid, although data in self.transponder should already be correct. self.tsid = self.transponder["tsid"] = section["header"]["transport_stream_id"] self.onid = self.transponder["onid"] = section["header"]["original_network_id"] if len(sdt_current_sections_read) == sdt_current_sections_count: sdt_current_completed = True if sdt_current_completed: break dvbreader.close(fd) if not sdt_current_content: print "[MakeBouquet][readSDT] no services found on transponder" return for i in range(len(sdt_current_content)): service = sdt_current_content[i] if self.FTA_only and service["free_ca"] != 0: continue if service["service_type"] not in self.VIDEO_ALLOWED_TYPES and service["service_type"] not in self.AUDIO_ALLOWED_TYPES: continue servicekey = "%x:%x:%x" % (service["transport_stream_id"], service["original_network_id"], service["service_id"]) self.tmp_services_dict[servicekey] = service
def updateAndReadServicesFreeSat(self, bouquet_id, region_id, namespace, transponders, servicehacks): print >> log, "[DvbScanner] Reading services..." fd = dvbreader.open(self.demuxer_device, self.bat_pid, self.bat_table_id, 0xFF, self.frontend) if fd < 0: print >> log, "[DvbScanner] Cannot open the demuxer" return None bat_section_version = -1 bat_sections_read = [] bat_sections_count = 0 bat_content = [] timeout = datetime.datetime.now() timeout += datetime.timedelta(0, self.TIMEOUT_SEC) while True: if datetime.datetime.now() > timeout: print >> log, "[DvbScanner] Timed out" break section = dvbreader.read_bat(fd, self.bat_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == self.bat_table_id: if section["header"]["bouquet_id"] != bouquet_id: continue if section["header"]["version_number"] != bat_section_version: bat_section_version = section["header"]["version_number"] bat_sections_read = [] bat_content = [] bat_sections_count = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in bat_sections_read: bat_sections_read.append(section["header"]["section_number"]) bat_content += section["content"] if len(bat_sections_read) == bat_sections_count: break dvbreader.close(fd) service_count = 0 transport_stream_id_list = [] tmp_services_dict = {} for service in bat_content: if service["descriptor_tag"] != 0xD3: continue if service["region_id"] != region_id and service["region_id"] != 0xFFFF: continue service["service_type"] = 1 service["free_ca"] = 1 service["service_name"] = "Unknown" service["provider_name"] = "Unknown" service["namespace"] = namespace service["flags"] = 0 key = "%x:%x:%x" % (service["transport_stream_id"], service["original_network_id"], service["service_id"]) if key in tmp_services_dict: tmp_services_dict[key]["numbers"].append(service["number"]) else: service["numbers"] = [service["number"]] tmp_services_dict[key] = service service_count += 1 if service["transport_stream_id"] not in transport_stream_id_list: transport_stream_id_list.append(service["transport_stream_id"]) for service in bat_content: if service["descriptor_tag"] != 0x41: continue if ( service["service_type"] not in DvbScanner.VIDEO_ALLOWED_TYPES and service["service_type"] not in DvbScanner.AUDIO_ALLOWED_TYPES and service["service_type"] not in DvbScanner.INTERACTIVE_ALLOWED_TYPES ): continue if service["service_type"] == 0x05: service["service_type"] = 0x01 # enigma2 doesn't like 0x05 VOD key = "%x:%x:%x" % (service["transport_stream_id"], service["original_network_id"], service["service_id"]) if key in tmp_services_dict: tmp_services_dict[key]["service_type"] = service["service_type"] print >> log, "[DvbScanner] Read %d services with bouquet_id = 0x%x" % (service_count, bouquet_id) print >> log, "[DvbScanner] Reading services extra info..." if self.sdt_other_table_id == 0x00: mask = 0xFF else: mask = self.sdt_current_table_id ^ self.sdt_other_table_id ^ 0xFF fd = dvbreader.open(self.demuxer_device, self.sdt_pid, self.sdt_current_table_id, mask, self.frontend) if fd < 0: print >> log, "[DvbScanner] Cannot open the demuxer" return None sdt_secions_status = {} for transport_stream_id in transport_stream_id_list: sdt_secions_status[transport_stream_id] = {} sdt_secions_status[transport_stream_id]["section_version"] = -1 sdt_secions_status[transport_stream_id]["sections_read"] = [] sdt_secions_status[transport_stream_id]["sections_count"] = 0 sdt_secions_status[transport_stream_id]["content"] = [] timeout = datetime.datetime.now() timeout += datetime.timedelta(0, self.TIMEOUT_SEC) while True: if datetime.datetime.now() > timeout: print >> log, "[DvbScanner] Timed out" break section = dvbreader.read_sdt(fd, self.sdt_current_table_id, self.sdt_other_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if ( section["header"]["table_id"] == self.sdt_current_table_id or section["header"]["table_id"] == self.sdt_other_table_id ): if section["header"]["transport_stream_id"] not in transport_stream_id_list: continue transport_stream_id = section["header"]["transport_stream_id"] if section["header"]["version_number"] != sdt_secions_status[transport_stream_id]["section_version"]: sdt_secions_status[transport_stream_id]["section_version"] = section["header"]["version_number"] sdt_secions_status[transport_stream_id]["sections_read"] = [] sdt_secions_status[transport_stream_id]["content"] = [] sdt_secions_status[transport_stream_id]["sections_count"] = ( section["header"]["last_section_number"] + 1 ) if section["header"]["section_number"] not in sdt_secions_status[transport_stream_id]["sections_read"]: sdt_secions_status[transport_stream_id]["sections_read"].append(section["header"]["section_number"]) sdt_secions_status[transport_stream_id]["content"] += section["content"] if ( len(sdt_secions_status[transport_stream_id]["sections_read"]) == sdt_secions_status[transport_stream_id]["sections_count"] ): transport_stream_id_list.remove(transport_stream_id) if len(transport_stream_id_list) == 0: break if len(transport_stream_id_list) > 0: print >> log, "[DvbScanner] Cannot fetch SDT for the following transport_stream_id list: ", transport_stream_id_list dvbreader.close(fd) for key in sdt_secions_status: for section in sdt_secions_status[key]["content"]: srvkey = "%x:%x:%x" % ( section["transport_stream_id"], section["original_network_id"], section["service_id"], ) if srvkey not in tmp_services_dict: continue service = tmp_services_dict[srvkey] service["free_ca"] = section["free_ca"] service["service_name"] = section["service_name"] service["provider_name"] = section["provider_name"] video_services = {} radio_services = {} service_extra_count = 0 for key in tmp_services_dict: service = tmp_services_dict[key] if len(servicehacks) > 0: skip = False exec (servicehacks) if skip: continue tpkey = "%x:%x:%x" % (service["namespace"], service["transport_stream_id"], service["original_network_id"]) if tpkey not in transponders: continue transponders[tpkey]["services"][service["service_id"]] = service service_extra_count += 1 if ( service["service_type"] in DvbScanner.VIDEO_ALLOWED_TYPES or service["service_type"] in DvbScanner.INTERACTIVE_ALLOWED_TYPES ): for number in service["numbers"]: if service["region_id"] == 0xFFFF: if number not in video_services: video_services[number] = service else: video_services[number] = service else: for number in service["numbers"]: if number not in radio_services: radio_services[number] = service print >> log, "[DvbScanner] Read extra info for %d services" % service_extra_count return {"video": video_services, "radio": radio_services}
def updateAndReadServicesLCN( self, namespace, transponders, servicehacks, transport_stream_id_list, logical_channel_number_dict ): print >> log, "[DvbScanner] Reading services..." if self.sdt_other_table_id == 0x00: mask = 0xFF else: mask = self.sdt_current_table_id ^ self.sdt_other_table_id ^ 0xFF fd = dvbreader.open(self.demuxer_device, self.sdt_pid, self.sdt_current_table_id, mask, self.frontend) if fd < 0: print >> log, "[DvbScanner] Cannot open the demuxer" return None sdt_secions_status = {} for transport_stream_id in transport_stream_id_list: sdt_secions_status[transport_stream_id] = {} sdt_secions_status[transport_stream_id]["section_version"] = -1 sdt_secions_status[transport_stream_id]["sections_read"] = [] sdt_secions_status[transport_stream_id]["sections_count"] = 0 sdt_secions_status[transport_stream_id]["content"] = [] timeout = datetime.datetime.now() timeout += datetime.timedelta(0, self.TIMEOUT_SEC) while True: if datetime.datetime.now() > timeout: print >> log, "[DvbScanner] Timed out" break section = dvbreader.read_sdt(fd, self.sdt_current_table_id, self.sdt_other_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if ( section["header"]["table_id"] == self.sdt_current_table_id or section["header"]["table_id"] == self.sdt_other_table_id ): if section["header"]["transport_stream_id"] not in transport_stream_id_list: continue transport_stream_id = section["header"]["transport_stream_id"] if section["header"]["version_number"] != sdt_secions_status[transport_stream_id]["section_version"]: sdt_secions_status[transport_stream_id]["section_version"] = section["header"]["version_number"] sdt_secions_status[transport_stream_id]["sections_read"] = [] sdt_secions_status[transport_stream_id]["content"] = [] sdt_secions_status[transport_stream_id]["sections_count"] = ( section["header"]["last_section_number"] + 1 ) if section["header"]["section_number"] not in sdt_secions_status[transport_stream_id]["sections_read"]: sdt_secions_status[transport_stream_id]["sections_read"].append(section["header"]["section_number"]) sdt_secions_status[transport_stream_id]["content"] += section["content"] if ( len(sdt_secions_status[transport_stream_id]["sections_read"]) == sdt_secions_status[transport_stream_id]["sections_count"] ): transport_stream_id_list.remove(transport_stream_id) if len(transport_stream_id_list) == 0: break if len(transport_stream_id_list) > 0: print >> log, "[DvbScanner] Cannot fetch SDT for the following transport_stream_id list: ", transport_stream_id_list dvbreader.close(fd) service_count = 0 tmp_services_dict = {} for key in sdt_secions_status: for section in sdt_secions_status[key]["content"]: service = section key = "%x:%x:%x" % ( service["transport_stream_id"], service["original_network_id"], service["service_id"], ) if key not in logical_channel_number_dict: continue if logical_channel_number_dict[key]["visible_service_flag"] == 0: continue service["namespace"] = namespace service["flags"] = 0 service["number"] = logical_channel_number_dict[key]["logical_channel_number"] if key in tmp_services_dict: tmp_services_dict[key]["numbers"].append(service["number"]) else: service["numbers"] = [service["number"]] tmp_services_dict[key] = service service_count += 1 print >> log, "[DvbScanner] Read %d services" % service_count video_services = {} radio_services = {} service_extra_count = 0 for key in tmp_services_dict: service = tmp_services_dict[key] if len(servicehacks) > 0: skip = False exec (servicehacks) if skip: continue tpkey = "%x:%x:%x" % (service["namespace"], service["transport_stream_id"], service["original_network_id"]) if tpkey not in transponders: continue transponders[tpkey]["services"][service["service_id"]] = service service_extra_count += 1 if ( service["service_type"] in DvbScanner.VIDEO_ALLOWED_TYPES or service["service_type"] in DvbScanner.INTERACTIVE_ALLOWED_TYPES ): for number in service["numbers"]: if number not in video_services: video_services[number] = service else: for number in service["numbers"]: if number not in radio_services: radio_services[number] = service print >> log, "[DvbScanner] %d valid services" % service_extra_count return {"video": video_services, "radio": radio_services}
def readNIT(self): adapter = 0 demuxer_device = "/dev/dvb/adapter%d/demux%d" % (adapter, self.demuxer_id) start = time.time() # for debug info nit_current_pid = 0x10 nit_current_table_id = 0x40 nit_other_table_id = 0x00 # don't read other table self.network_name = None self.custom_transponder_needed = True if nit_other_table_id == 0x00: mask = 0xff else: mask = nit_current_table_id ^ nit_other_table_id ^ 0xff nit_current_timeout = 20 # maximum time allowed to read the network information table (seconds) nit_current_version_number = -1 nit_current_sections_read = [] nit_current_sections_count = 0 nit_current_content = [] nit_current_completed = False fd = dvbreader.open(demuxer_device, nit_current_pid, nit_current_table_id, mask, self.selectedNIM) if fd < 0: print "[ABM-FrequencyFinder][readNIT] Cannot open the demuxer" return timeout = datetime.datetime.now() timeout += datetime.timedelta(0, nit_current_timeout) while True: if datetime.datetime.now() > timeout: print "[ABM-FrequencyFinder][readNIT] Timed out reading NIT" break section = dvbreader.read_nit(fd, nit_current_table_id, nit_other_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"][ "table_id"] == nit_current_table_id and not nit_current_completed: if section["header"][ "version_number"] != nit_current_version_number: nit_current_version_number = section["header"][ "version_number"] nit_current_sections_read = [] nit_current_sections_count = section["header"][ "last_section_number"] + 1 nit_current_content = [] if section["header"][ "section_number"] not in nit_current_sections_read: nit_current_sections_read.append( section["header"]["section_number"]) nit_current_content += section["content"] if 'network_name' in section["header"] and section[ "header"]["network_name"] != "Unknown": self.network_name = section["header"]["network_name"] if len(nit_current_sections_read ) == nit_current_sections_count: nit_current_completed = True if nit_current_completed: break dvbreader.close(fd) if not nit_current_content: print "[ABM-FrequencyFinder][readNIT] current transponder not found" return print "[ABM-FrequencyFinder][readNIT] NIT read time %.1f seconds." % ( time.time() - start) # descriptor_tag 0x5A is DVB-T, descriptor_tag 0x7f is DVB-T transponders = [ t for t in nit_current_content if "descriptor_tag" in t and t["descriptor_tag"] in ( 0x5A, 0x7f) and t["original_network_id"] == self.onid and t["transport_stream_id"] == self.tsid ] # this should only ever have a length of one transponder print "[ABM-FrequencyFinder][readNIT] transponders", transponders if transponders: if transponders[0]["descriptor_tag"] == 0x5A: # DVB-T self.system = eDVBFrontendParametersTerrestrial.System_DVB_T else: # must be DVB-T2 self.system = eDVBFrontendParametersTerrestrial.System_DVB_T2 if "frequency" in transponders[0] and abs( (transponders[0]["frequency"] * 10) - self.frequency) < 1000000: self.custom_transponder_needed = False if self.frequency != transponders[0]["frequency"] * 10: print "[ABM-FrequencyFinder][readNIT] updating transponder frequency from %.03f MHz to %.03f MHz" % ( self.frequency / 1000000, transponders[0]["frequency"] / 100000) self.frequency = transponders[0]["frequency"] * 10
def readSDT(self): adapter = 0 demuxer_device = "/dev/dvb/adapter%d/demux%d" % (adapter, self.demuxer_id) self.tsid = None self.onid = None sdt_pid = 0x11 sdt_current_table_id = 0x42 mask = 0xff sdtTimeout = 5 # maximum time allowed to read the service descriptor table (seconds) sdt_current_version_number = -1 sdt_current_sections_read = [] sdt_current_sections_count = 0 sdt_current_content = [] sdt_current_completed = False fd = dvbreader.open(demuxer_device, sdt_pid, sdt_current_table_id, mask, self.selectedNIM) if fd < 0: print("[MakeBouquet][readSDT] Cannot open the demuxer") return None timeout = datetime.datetime.now() timeout += datetime.timedelta(0, sdtTimeout) while True: if datetime.datetime.now() > timeout: print("[Satfinder][getCurrentTsidOnid] Timed out") break section = dvbreader.read_sdt(fd, sdt_current_table_id, 0x00) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"][ "table_id"] == sdt_current_table_id and not sdt_current_completed: if section["header"][ "version_number"] != sdt_current_version_number: sdt_current_version_number = section["header"][ "version_number"] sdt_current_sections_read = [] sdt_current_sections_count = section["header"][ "last_section_number"] + 1 sdt_current_content = [] if section["header"][ "section_number"] not in sdt_current_sections_read: sdt_current_sections_read.append( section["header"]["section_number"]) sdt_current_content += section["content"] if self.tsid is None or self.onid is None: # save first read of tsid and onid, although data in self.transponder should already be correct. self.tsid = self.transponder["tsid"] = section[ "header"]["transport_stream_id"] self.onid = self.transponder["onid"] = section[ "header"]["original_network_id"] if len(sdt_current_sections_read ) == sdt_current_sections_count: sdt_current_completed = True if sdt_current_completed: break dvbreader.close(fd) if not sdt_current_content: print("[MakeBouquet][readSDT] no services found on transponder") return for i in range(len(sdt_current_content)): service = sdt_current_content[i] if self.FTA_only and service["free_ca"] != 0: continue if service[ "service_type"] not in self.VIDEO_ALLOWED_TYPES and service[ "service_type"] not in self.AUDIO_ALLOWED_TYPES: continue servicekey = "%x:%x:%x" % (service["transport_stream_id"], service["original_network_id"], service["service_id"]) service["signalQuality"] = self.transponder[ "signalQuality"] # Used for sorting of duplicate LCNs self.tmp_services_dict[servicekey] = service
def readBouquet(bouquet_id): print "[DvbScanner] Reading bouquet_id = 0x%x..." % bouquet_id fd = dvbreader.open("/dev/dvb/adapter0/demux0", bat_pid, bat_table, mask, frontend) if fd < 0: print "[DvbScanner] Cannot open the demuxer" return None bat_section_version = -1 bat_sections_read = [] bat_sections_count = 0 bat_content = [] timeout = datetime.datetime.now() timeout += datetime.timedelta(0, TIMEOUT_SEC) while True: if datetime.datetime.now() > timeout: print "[DvbScanner] Timed out" break section = dvbreader.read_bat(fd, bat_table) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == bat_table: if section["header"]["bouquet_id"] != bouquet_id: continue if section["header"]["version_number"] != bat_section_version: bat_section_version = section["header"]["version_number"] bat_sections_read = [] bat_content = [] bat_sections_count = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in bat_sections_read: bat_sections_read.append(section["header"]["section_number"]) bat_content += section["content"] if len(bat_sections_read) == bat_sections_count: break dvbreader.close(fd) bouquet_name = None for section in bat_content: if section["descriptor_tag"] == 0x47: bouquet_name = section["description"] break if bouquet_name is None: print "[DvbScanner] Canno get bouquet name for bouquet_id = 0x%x" % bouquet_id return for section in bat_content: if section["descriptor_tag"] == 0xd4: bouquet = { "name": bouquet_name + " - " + section["description"], "region": section["region_id"], "bouquet": bouquet_id } bouquets_list.append(bouquet) print "[DvbScanner] Done"
def updateTransponders(self, transponders, read_other_section = False): print>>log, "[DvbScanner] Reading transponders..." if self.nit_other_table_id == 0x00: mask = 0xff else: mask = self.nit_current_table_id ^ self.nit_other_table_id ^ 0xff fd = dvbreader.open(self.demuxer_device, self.nit_pid, self.nit_current_table_id, mask, self.frontend) if fd < 0: print>>log, "[DvbScanner] Cannot open the demuxer" return None nit_current_section_version = -1 nit_current_section_network_id = -1 nit_current_sections_read = [] nit_current_sections_count = 0 nit_current_content = [] nit_current_completed = False nit_other_section_version = -1 nit_other_section_network_id = -1 nit_other_sections_read = [] nit_other_sections_count = 0 nit_other_content = [] nit_other_completed = not read_other_section or self.nit_other_table_id == 0x00 timeout = datetime.datetime.now() timeout += datetime.timedelta(0, self.TIMEOUT_SEC) while True: if datetime.datetime.now() > timeout: print>>log, "[DvbScanner] Timed out" break section = dvbreader.read_nit(fd, self.nit_current_table_id, self.nit_other_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == self.nit_current_table_id and not nit_current_completed: if (section["header"]["version_number"] != nit_current_section_version or section["header"]["network_id"] != nit_current_section_network_id): nit_current_section_version = section["header"]["version_number"] nit_current_section_network_id = section["header"]["network_id"] nit_current_sections_read = [] nit_current_content = [] nit_current_sections_count = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in nit_current_sections_read: nit_current_sections_read.append(section["header"]["section_number"]) nit_current_content += section["content"] if len(nit_current_sections_read) == nit_current_sections_count: nit_current_completed = True elif section["header"]["table_id"] == self.nit_other_table_id and not nit_other_completed: if (section["header"]["version_number"] != nit_other_section_version or section["header"]["network_id"] != nit_other_section_network_id): nit_other_section_version = section["header"]["version_number"] nit_other_section_network_id = section["header"]["network_id"] nit_other_sections_read = [] nit_other_content = [] nit_other_sections_count = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in nit_other_sections_read: nit_other_sections_read.append(section["header"]["section_number"]) nit_other_content += section["content"] if len(nit_other_sections_read) == nit_other_sections_count: nit_other_completed = True if nit_current_completed and nit_other_completed: break dvbreader.close(fd) nit_content = nit_current_content nit_content += nit_other_content transport_stream_id_list = [] logical_channel_number_dict = {} transponders_count = 0 for transponder in nit_content: if len(transponder) == 5: # lcn key = "%x:%x:%x" % (transponder["transport_stream_id"], transponder["original_network_id"], transponder["service_id"]) logical_channel_number_dict[key] = transponder continue transponder["services"] = {} transponder["dvb_type"] = "s" transponder["frequency"] = transponder["frequency"] * 10 transponder["symbol_rate"] = transponder["symbol_rate"] * 100 if transponder["fec_inner"] != 15 and transponder["fec_inner"] > 9: transponder["fec_inner"] = 0 orbital_position = ((transponder["orbital_position"] >> 12) & 0x0F) * 1000 orbital_position += ((transponder["orbital_position"] >> 8) & 0x0F) * 100 orbital_position += ((transponder["orbital_position"] >> 4) & 0x0F) * 10 orbital_position += transponder["orbital_position"] & 0x0F if orbital_position != 0 and transponder["west_east_flag"] == 0: orbital_position = 3600 - orbital_position transponder["orbital_position"] = orbital_position if transponder["modulation_system"] == 0 and transponder["modulation_type"] == 2: transponder["modulation_type"] = 1 transponder["namespace"] = self.buildNamespace(transponder) transponder["inversion"] = 2 transponder["flags"] = 0 transponder["pilot"] = 2 key = "%x:%x:%x" % (transponder["namespace"], transponder["transport_stream_id"], transponder["original_network_id"]) if key in transponders: transponder["services"] = transponders[key]["services"] transponders[key] = transponder transponders_count += 1 if transponder["transport_stream_id"] not in transport_stream_id_list: transport_stream_id_list.append(transponder["transport_stream_id"]) if read_other_section: print>>log, "[DvbScanner] Added/Updated %d transponders with network_id = 0x%x and network_id = 0x%x" % (transponders_count, nit_current_section_network_id, nit_other_section_network_id) else: print>>log, "[DvbScanner] Added/Updated %d transponders with network_id = 0x%x" % (transponders_count, nit_current_section_network_id) return { "transport_stream_id_list": transport_stream_id_list, "logical_channel_number_dict": logical_channel_number_dict }
def updateAndReadServicesFreeSat(self, bouquet_id, region_id, namespace, bouquet_key, transponders, servicehacks): print>>log, "[DvbScanner] Reading services..." fd = dvbreader.open(self.demuxer_device, self.bat_pid, self.bat_table_id, 0xff, self.frontend) if fd < 0: print>>log, "[DvbScanner] Cannot open the demuxer" return None bat_section_version = -1 bat_sections_read = [] bat_sections_count = 0 bat_content = [] timeout = datetime.datetime.now() timeout += datetime.timedelta(0, self.TIMEOUT_SEC) transport_stream_id_list = [] while True: if datetime.datetime.now() > timeout: print>>log, "[DvbScanner] Timed out" break section = dvbreader.read_bat(fd, self.bat_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == self.bat_table_id: if section["header"]["bouquet_id"] != bouquet_id: if config.autobouquetsmaker.showextraservices.value: for content_tmp in section["content"]: if content_tmp["descriptor_tag"] == 0xd3 and content_tmp["transport_stream_id"] not in transport_stream_id_list: transport_stream_id_list.append(content_tmp["transport_stream_id"]) continue if section["header"]["version_number"] != bat_section_version: bat_section_version = section["header"]["version_number"] bat_sections_read = [] bat_content = [] bat_sections_count = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in bat_sections_read: bat_sections_read.append(section["header"]["section_number"]) bat_content += section["content"] if len(bat_sections_read) == bat_sections_count: break dvbreader.close(fd) service_count = 0 tmp_services_dict = {} for service in bat_content: if service["descriptor_tag"] != 0xd3: continue if service["transport_stream_id"] not in transport_stream_id_list: transport_stream_id_list.append(service["transport_stream_id"]) if service["region_id"] != region_id and service["region_id"] != 0xffff: continue service["service_type"] = 1 service["free_ca"] = 1 service["service_name"] = "Unknown" service["provider_name"] = "Unknown" service["namespace"] = namespace service["flags"] = 0 key = "%x:%x:%x" % (service["transport_stream_id"], service["original_network_id"], service["service_id"]) if key in tmp_services_dict: tmp_services_dict[key]["numbers"].append(service["number"]) else: service["numbers"] = [service["number"]] tmp_services_dict[key] = service service_count += 1 for service in bat_content: if service["descriptor_tag"] != 0x41: continue if service["service_type"] not in DvbScanner.VIDEO_ALLOWED_TYPES and service["service_type"] not in DvbScanner.AUDIO_ALLOWED_TYPES and service["service_type"] not in DvbScanner.INTERACTIVE_ALLOWED_TYPES: continue if service["service_type"] == 0x05: service["service_type"] = 0x01; # enigma2 doesn't like 0x05 VOD key = "%x:%x:%x" % (service["transport_stream_id"], service["original_network_id"], service["service_id"]) if key in tmp_services_dict: tmp_services_dict[key]["service_type"] = service["service_type"] print>>log, "[DvbScanner] Read %d services with bouquet_id = 0x%x" % (service_count, bouquet_id) print>>log, "[DvbScanner] Reading services extra info..." #Clear double LCN values tmp_numbers =[] tmp_double_numbers = [] for key in tmp_services_dict: if len(tmp_services_dict[key]["numbers"]) > 1: if tmp_services_dict[key]["numbers"][0] not in tmp_numbers: tmp_numbers.append (tmp_services_dict[key]["numbers"][0]) else: tmp_double_numbers.append (tmp_services_dict[key]["numbers"][0]) if tmp_services_dict[key]["numbers"][1] not in tmp_numbers: tmp_numbers.append (tmp_services_dict[key]["numbers"][1]) else: tmp_double_numbers.append (tmp_services_dict[key]["numbers"][1]) for key in tmp_services_dict: if len(tmp_services_dict[key]["numbers"]) > 1: if tmp_services_dict[key]["numbers"][0] in tmp_double_numbers: print>>log, "[DvbScanner] Deleted double LCN: %d" % (tmp_services_dict[key]["numbers"][0]) del tmp_services_dict[key]["numbers"][0] #remove other duplicates (single and dual LCN values) tmp_numbers =[] for key in tmp_services_dict: if tmp_services_dict[key]["region_id"] != 0xffff: for number in tmp_services_dict[key]["numbers"]: tmp_numbers.append(number) for key in tmp_services_dict.keys(): if tmp_services_dict[key]["region_id"] == 0xffff: for number in tmp_services_dict[key]["numbers"]: if number in tmp_numbers: del tmp_services_dict[key]["numbers"][tmp_services_dict[key]["numbers"].index(number)] if len(tmp_services_dict[key]["numbers"]) == 0: del tmp_services_dict[key] if self.sdt_other_table_id == 0x00: mask = 0xff else: mask = self.sdt_current_table_id ^ self.sdt_other_table_id ^ 0xff fd = dvbreader.open(self.demuxer_device, self.sdt_pid, self.sdt_current_table_id, mask, self.frontend) if fd < 0: print>>log, "[DvbScanner] Cannot open the demuxer" return None sdt_secions_status = {} for transport_stream_id in transport_stream_id_list: sdt_secions_status[transport_stream_id] = {} sdt_secions_status[transport_stream_id]["section_version"] = -1 sdt_secions_status[transport_stream_id]["sections_read"] = [] sdt_secions_status[transport_stream_id]["sections_count"] = 0 sdt_secions_status[transport_stream_id]["content"] = [] timeout = datetime.datetime.now() timeout += datetime.timedelta(0, self.SDT_TIMEOUT) while True: if datetime.datetime.now() > timeout: print>>log, "[DvbScanner] Timed out" break section = dvbreader.read_sdt(fd, self.sdt_current_table_id, self.sdt_other_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == self.sdt_current_table_id or section["header"]["table_id"] == self.sdt_other_table_id: if section["header"]["transport_stream_id"] not in transport_stream_id_list: continue transport_stream_id = section["header"]["transport_stream_id"] if section["header"]["version_number"] != sdt_secions_status[transport_stream_id]["section_version"]: sdt_secions_status[transport_stream_id]["section_version"] = section["header"]["version_number"] sdt_secions_status[transport_stream_id]["sections_read"] = [] sdt_secions_status[transport_stream_id]["content"] = [] sdt_secions_status[transport_stream_id]["sections_count"] = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in sdt_secions_status[transport_stream_id]["sections_read"]: sdt_secions_status[transport_stream_id]["sections_read"].append(section["header"]["section_number"]) sdt_secions_status[transport_stream_id]["content"] += section["content"] if len(sdt_secions_status[transport_stream_id]["sections_read"]) == sdt_secions_status[transport_stream_id]["sections_count"]: transport_stream_id_list.remove(transport_stream_id) if len(transport_stream_id_list) == 0: break if len(transport_stream_id_list) > 0: print>>log, "[DvbScanner] Cannot fetch SDT for the following transport_stream_id list: ", transport_stream_id_list dvbreader.close(fd) extras = [] for key in sdt_secions_status: for section in sdt_secions_status[key]["content"]: srvkey = "%x:%x:%x" % (section["transport_stream_id"], section["original_network_id"], section["service_id"]) if srvkey not in tmp_services_dict: if config.autobouquetsmaker.showextraservices.value: extras.append(section) continue service = tmp_services_dict[srvkey] service["free_ca"] = section["free_ca"] service["service_name"] = section["service_name"] service["provider_name"] = section["provider_name"] video_services = {} radio_services = {} service_extra_count = 0 tmp_services_dict, LCNs_in_use = self.extrasHelper(tmp_services_dict, extras, namespace, False) for key in self.LCN_order(tmp_services_dict): service = tmp_services_dict[key] if len(servicehacks) > 0: skip = False exec(servicehacks) if skip: continue tpkey = "%x:%x:%x" % (service["namespace"], service["transport_stream_id"], service["original_network_id"]) if tpkey not in transponders: continue transponders[tpkey]["services"][service["service_id"]] = service service_extra_count += 1 if service["service_type"] in DvbScanner.VIDEO_ALLOWED_TYPES or service["service_type"] in DvbScanner.INTERACTIVE_ALLOWED_TYPES: for number in service["numbers"]: if service["region_id"] == 0xffff: if number not in video_services: video_services[number] = service else: video_services[number] = service else: for number in service["numbers"]: if number not in radio_services: radio_services[number] = service print>>log, "[DvbScanner] Read extra info for %d services" % service_extra_count return { "video": video_services, "radio": radio_services }
def updateAndReadServicesFastscan(self, namespace, transponders, servicehacks, transport_stream_id_list, logical_channel_number_dict): print>>log, "[DvbScanner] Reading services..." fd = dvbreader.open(self.demuxer_device, self.fastscan_pid, self.fastscan_table_id, 0xff, self.frontend) if fd < 0: print>>log, "[DvbScanner] Cannot open the demuxer" return None fastscan_section_version = -1 fastscan_section_id = -1 fastscan_sections_read = [] fastscan_sections_count = 0 fastscan_content = [] timeout = datetime.datetime.now() timeout += datetime.timedelta(0, self.TIMEOUT_SEC) while True: if datetime.datetime.now() > timeout: print>>log, "[DvbScanner] Timed out" break section = dvbreader.read_fastscan(fd, self.fastscan_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == self.fastscan_table_id: if (section["header"]["version_number"] != fastscan_section_version or section["header"]["fastscan_id"] != fastscan_section_id): fastscan_section_version = section["header"]["version_number"] fastscan_section_id = section["header"]["fastscan_id"] fastscan_sections_read = [] fastscan_content = [] fastscan_sections_count = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in fastscan_sections_read: fastscan_sections_read.append(section["header"]["section_number"]) fastscan_content += section["content"] if len(fastscan_sections_read) == fastscan_sections_count: break dvbreader.close(fd) # to ignore services on not configured satellites if config.autobouquetsmaker.skipservices.value: from Components.NimManager import nimmanager nims = nimmanager.getNimListOfType("DVB-S") orbitals_configured = [] for nim in nims: sats = nimmanager.getSatListForNim(nim) for sat in sats: if sat[0] not in orbitals_configured: orbitals_configured.append(sat[0]) service_count = 0 tmp_services_dict = {} for section in fastscan_content: service = section key = "%x:%x:%x" % (service["transport_stream_id"], service["original_network_id"], service["service_id"]) if key not in logical_channel_number_dict: continue if logical_channel_number_dict[key]["visible_service_flag"] == 0: continue if not hasattr(service, "free_ca"): service["free_ca"] = 1 if not hasattr(service, "namespace"): try: service["namespace"] = service["namespace"] = logical_channel_number_dict[key]["transponder"]["namespace"] except: service["namespace"] = namespace if not hasattr(service, "flags"): service["flags"] = 0 service["number"] = logical_channel_number_dict[key]["logical_channel_number"] service["orbital_position"] = service["namespace"] / (16**4) if key in tmp_services_dict: tmp_services_dict[key]["numbers"].append(service["number"]) else: service["numbers"] = [service["number"]] tmp_services_dict[key] = service service_count += 1 print>>log, "[DvbScanner] Read %d services" % service_count video_services = {} radio_services = {} service_extra_count = 0 services_without_transponders = 0 for key in self.LCN_order(tmp_services_dict): service = tmp_services_dict[key] if config.autobouquetsmaker.skipservices.value and service["orbital_position"] not in orbitals_configured: continue if len(servicehacks) > 0: skip = False exec(servicehacks) if skip: continue tpkey = "%x:%x:%x" % (service["namespace"], service["transport_stream_id"], service["original_network_id"]) if tpkey not in transponders: services_without_transponders += 1 continue transponders[tpkey]["services"][service["service_id"]] = service service_extra_count += 1 if service["service_type"] in DvbScanner.VIDEO_ALLOWED_TYPES or service["service_type"] in DvbScanner.INTERACTIVE_ALLOWED_TYPES: for number in service["numbers"]: if number not in video_services: video_services[number] = service else: for number in service["numbers"]: if number not in radio_services: radio_services[number] = service print>>log, "[DvbScanner] %d valid services" % service_extra_count if services_without_transponders: print>>log, "[DvbScanner] %d services omitted as there is no corresponding transponder" % services_without_transponders return { "video": video_services, "radio": radio_services }
def updateAndReadServicesLCN(self, namespace, transponders, servicehacks, transport_stream_id_list, logical_channel_number_dict, service_dict_tmp, protocol): print>>log, "[DvbScanner] Reading services..." if self.sdt_other_table_id == 0x00: mask = 0xff else: mask = self.sdt_current_table_id ^ self.sdt_other_table_id ^ 0xff fd = dvbreader.open(self.demuxer_device, self.sdt_pid, self.sdt_current_table_id, mask, self.frontend) if fd < 0: print>>log, "[DvbScanner] Cannot open the demuxer" return None sdt_secions_status = {} for transport_stream_id in transport_stream_id_list: sdt_secions_status[transport_stream_id] = {} sdt_secions_status[transport_stream_id]["section_version"] = -1 sdt_secions_status[transport_stream_id]["sections_read"] = [] sdt_secions_status[transport_stream_id]["sections_count"] = 0 sdt_secions_status[transport_stream_id]["content"] = [] timeout = datetime.datetime.now() timeout += datetime.timedelta(0, self.SDT_TIMEOUT) while True: if datetime.datetime.now() > timeout: print>>log, "[DvbScanner] Timed out" break section = dvbreader.read_sdt(fd, self.sdt_current_table_id, self.sdt_other_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == self.sdt_current_table_id or section["header"]["table_id"] == self.sdt_other_table_id: if section["header"]["transport_stream_id"] not in transport_stream_id_list: continue transport_stream_id = section["header"]["transport_stream_id"] if section["header"]["version_number"] != sdt_secions_status[transport_stream_id]["section_version"]: sdt_secions_status[transport_stream_id]["section_version"] = section["header"]["version_number"] sdt_secions_status[transport_stream_id]["sections_read"] = [] sdt_secions_status[transport_stream_id]["content"] = [] sdt_secions_status[transport_stream_id]["sections_count"] = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in sdt_secions_status[transport_stream_id]["sections_read"]: sdt_secions_status[transport_stream_id]["sections_read"].append(section["header"]["section_number"]) sdt_secions_status[transport_stream_id]["content"] += section["content"] if len(sdt_secions_status[transport_stream_id]["sections_read"]) == sdt_secions_status[transport_stream_id]["sections_count"]: transport_stream_id_list.remove(transport_stream_id) if len(transport_stream_id_list) == 0: break if len(transport_stream_id_list) > 0: print>>log, "[DvbScanner] Cannot fetch SDT for the following transport_stream_id list: ", transport_stream_id_list dvbreader.close(fd) # When no LCN available, create fake LCN numbers (service-id) and use customlcn file for final channel numbers if len(logical_channel_number_dict) == 0 and protocol == "nolcn": lcn_temp = {} for key in sdt_secions_status: for section_content in sdt_secions_status[key]["content"]: service = section_content key = "%x:%x:%x" % (service["transport_stream_id"], service["original_network_id"], service["service_id"]) lcn_temp[key] = service for key in lcn_temp: if lcn_temp[key]["service_type"] in DvbScanner.VIDEO_ALLOWED_TYPES or lcn_temp[key]["service_type"] in DvbScanner.AUDIO_ALLOWED_TYPES or lcn_temp[key]["service_type"] in DvbScanner.INTERACTIVE_ALLOWED_TYPES: lcn_temp[key]["logical_channel_number"] = lcn_temp[key]["service_id"] lcn_temp[key]["visible_service_flag"] = 1 else: lcn_temp[key]["visible_service_flag"] = 0 logical_channel_number_dict = lcn_temp service_count = 0 tmp_services_dict = {} for key in sdt_secions_status: for section in sdt_secions_status[key]["content"]: service = section key = "%x:%x:%x" % (service["transport_stream_id"], service["original_network_id"], service["service_id"]) if logical_channel_number_dict and (key not in logical_channel_number_dict or logical_channel_number_dict[key]["visible_service_flag"] == 0): continue if service_dict_tmp and key not in service_dict_tmp and protocol != "lcn2": continue service["namespace"] = namespace service["flags"] = 0 if not logical_channel_number_dict: service["number"] = service["logical_channel_number"] if service["service_type"] == 1 and (service["service_group_id"] == 17 or service["service_group_id"] == 21): service["service_type"] = 17 else: service["number"] = logical_channel_number_dict[key]["logical_channel_number"] if key in tmp_services_dict: tmp_services_dict[key]["numbers"].append(service["number"]) else: service["numbers"] = [service["number"]] tmp_services_dict[key] = service service_count += 1 print>>log, "[DvbScanner] Read %d services" % service_count video_services = {} radio_services = {} service_extra_count = 0 for key in self.LCN_order(tmp_services_dict): service = tmp_services_dict[key] if len(servicehacks) > 0: skip = False exec(servicehacks) if skip: continue tpkey = "%x:%x:%x" % (service["namespace"], service["transport_stream_id"], service["original_network_id"]) if tpkey not in transponders: continue transponders[tpkey]["services"][service["service_id"]] = service service_extra_count += 1 if service["service_type"] in DvbScanner.VIDEO_ALLOWED_TYPES or service["service_type"] in DvbScanner.INTERACTIVE_ALLOWED_TYPES: for number in service["numbers"]: if number not in video_services: video_services[number] = service else: for number in service["numbers"]: if number not in radio_services: radio_services[number] = service print>>log, "[DvbScanner] %d valid services" % service_extra_count return { "video": video_services, "radio": radio_services }
def updateAndReadServicesFastscan(self, namespace, transponders, servicehacks, transport_stream_id_list, logical_channel_number_dict): print>>log, "[DvbScanner] Reading services..." fd = dvbreader.open(self.demuxer_device, self.fastscan_pid, self.fastscan_table_id, 0xff, self.frontend) if fd < 0: print>>log, "[DvbScanner] Cannot open the demuxer" return None fastscan_section_version = -1 fastscan_section_id = -1 fastscan_sections_read = [] fastscan_sections_count = 0 fastscan_content = [] timeout = datetime.datetime.now() timeout += datetime.timedelta(0, self.TIMEOUT_SEC) while True: if datetime.datetime.now() > timeout: print>>log, "[DvbScanner] Timed out" break section = dvbreader.read_fastscan(fd, self.fastscan_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == self.fastscan_table_id: if (section["header"]["version_number"] != fastscan_section_version or section["header"]["fastscan_id"] != fastscan_section_id): fastscan_section_version = section["header"]["version_number"] fastscan_section_id = section["header"]["fastscan_id"] fastscan_sections_read = [] fastscan_content = [] fastscan_sections_count = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in fastscan_sections_read: fastscan_sections_read.append(section["header"]["section_number"]) fastscan_content += section["content"] if len(fastscan_sections_read) == fastscan_sections_count: break dvbreader.close(fd) service_count = 0 tmp_services_dict = {} for section in fastscan_content: service = section key = "%x:%x:%x" % (service["transport_stream_id"], service["original_network_id"], service["service_id"]) if key not in logical_channel_number_dict: continue if logical_channel_number_dict[key]["visible_service_flag"] == 0: continue service["free_ca"] = 1 service["namespace"] = namespace service["flags"] = 0 service["number"] = logical_channel_number_dict[key]["logical_channel_number"] if key in tmp_services_dict: tmp_services_dict[key]["numbers"].append(service["number"]) else: service["numbers"] = [service["number"]] tmp_services_dict[key] = service service_count += 1 print>>log, "[DvbScanner] Read %d services" % service_count video_services = {} radio_services = {} service_extra_count = 0 for key in tmp_services_dict: service = tmp_services_dict[key] if len(servicehacks) > 0: skip = False exec(servicehacks) if skip: continue tpkey = "%x:%x:%x" % (service["namespace"], service["transport_stream_id"], service["original_network_id"]) if tpkey not in transponders: continue transponders[tpkey]["services"][service["service_id"]] = service service_extra_count += 1 if service["service_type"] in DvbScanner.VIDEO_ALLOWED_TYPES or service["service_type"] in DvbScanner.INTERACTIVE_ALLOWED_TYPES: for number in service["numbers"]: if number not in video_services: video_services[number] = service else: for number in service["numbers"]: if number not in radio_services: radio_services[number] = service print>>log, "[DvbScanner] %d valid services" % service_extra_count return { "video": video_services, "radio": radio_services }
def updateAndReadServicesFreeSat(self, bouquet_id, region_id, namespace, transponders, servicehacks): print>>log, "[DvbScanner] Reading services..." fd = dvbreader.open(self.demuxer_device, self.bat_pid, self.bat_table_id, 0xff, self.frontend) if fd < 0: print>>log, "[DvbScanner] Cannot open the demuxer" return None bat_section_version = -1 bat_sections_read = [] bat_sections_count = 0 bat_content = [] timeout = datetime.datetime.now() timeout += datetime.timedelta(0, self.TIMEOUT_SEC) while True: if datetime.datetime.now() > timeout: print>>log, "[DvbScanner] Timed out" break section = dvbreader.read_bat(fd, self.bat_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == self.bat_table_id: if section["header"]["bouquet_id"] != bouquet_id: continue if section["header"]["version_number"] != bat_section_version: bat_section_version = section["header"]["version_number"] bat_sections_read = [] bat_content = [] bat_sections_count = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in bat_sections_read: bat_sections_read.append(section["header"]["section_number"]) bat_content += section["content"] if len(bat_sections_read) == bat_sections_count: break dvbreader.close(fd) service_count = 0 transport_stream_id_list = [] tmp_services_dict = {} for service in bat_content: if service["descriptor_tag"] != 0xd3: continue if service["region_id"] != region_id and service["region_id"] != 0xffff: continue service["service_type"] = 1 service["free_ca"] = 1 service["service_name"] = "Unknown" service["provider_name"] = "Unknown" service["namespace"] = namespace service["flags"] = 0 key = "%x:%x:%x" % (service["transport_stream_id"], service["original_network_id"], service["service_id"]) if key in tmp_services_dict: tmp_services_dict[key]["numbers"].append(service["number"]) else: service["numbers"] = [service["number"]] tmp_services_dict[key] = service service_count += 1 if service["transport_stream_id"] not in transport_stream_id_list: transport_stream_id_list.append(service["transport_stream_id"]) for service in bat_content: if service["descriptor_tag"] != 0x41: continue if service["service_type"] not in DvbScanner.VIDEO_ALLOWED_TYPES and service["service_type"] not in DvbScanner.AUDIO_ALLOWED_TYPES and service["service_type"] not in DvbScanner.INTERACTIVE_ALLOWED_TYPES: continue if service["service_type"] == 0x05: service["service_type"] = 0x01; # enigma2 doesn't like 0x05 VOD key = "%x:%x:%x" % (service["transport_stream_id"], service["original_network_id"], service["service_id"]) if key in tmp_services_dict: tmp_services_dict[key]["service_type"] = service["service_type"] print>>log, "[DvbScanner] Read %d services with bouquet_id = 0x%x" % (service_count, bouquet_id) print>>log, "[DvbScanner] Reading services extra info..." #Clear double LCN values tmp_numbers =[] tmp_double_numbers = [] for key in tmp_services_dict: if len(tmp_services_dict[key]["numbers"]) > 1: if tmp_services_dict[key]["numbers"][0] not in tmp_numbers: tmp_numbers.append (tmp_services_dict[key]["numbers"][0]) else: tmp_double_numbers.append (tmp_services_dict[key]["numbers"][0]) if tmp_services_dict[key]["numbers"][1] not in tmp_numbers: tmp_numbers.append (tmp_services_dict[key]["numbers"][1]) else: tmp_double_numbers.append (tmp_services_dict[key]["numbers"][1]) for key in tmp_services_dict: if len(tmp_services_dict[key]["numbers"]) > 1: if tmp_services_dict[key]["numbers"][0] in tmp_double_numbers: print>>log, "[DvbScanner] Deleted double LCN: %d" % (tmp_services_dict[key]["numbers"][0]) del tmp_services_dict[key]["numbers"][0] if self.sdt_other_table_id == 0x00: mask = 0xff else: mask = self.sdt_current_table_id ^ self.sdt_other_table_id ^ 0xff fd = dvbreader.open(self.demuxer_device, self.sdt_pid, self.sdt_current_table_id, mask, self.frontend) if fd < 0: print>>log, "[DvbScanner] Cannot open the demuxer" return None sdt_secions_status = {} for transport_stream_id in transport_stream_id_list: sdt_secions_status[transport_stream_id] = {} sdt_secions_status[transport_stream_id]["section_version"] = -1 sdt_secions_status[transport_stream_id]["sections_read"] = [] sdt_secions_status[transport_stream_id]["sections_count"] = 0 sdt_secions_status[transport_stream_id]["content"] = [] timeout = datetime.datetime.now() timeout += datetime.timedelta(0, self.TIMEOUT_SEC) while True: if datetime.datetime.now() > timeout: print>>log, "[DvbScanner] Timed out" break section = dvbreader.read_sdt(fd, self.sdt_current_table_id, self.sdt_other_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == self.sdt_current_table_id or section["header"]["table_id"] == self.sdt_other_table_id: if section["header"]["transport_stream_id"] not in transport_stream_id_list: continue transport_stream_id = section["header"]["transport_stream_id"] if section["header"]["version_number"] != sdt_secions_status[transport_stream_id]["section_version"]: sdt_secions_status[transport_stream_id]["section_version"] = section["header"]["version_number"] sdt_secions_status[transport_stream_id]["sections_read"] = [] sdt_secions_status[transport_stream_id]["content"] = [] sdt_secions_status[transport_stream_id]["sections_count"] = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in sdt_secions_status[transport_stream_id]["sections_read"]: sdt_secions_status[transport_stream_id]["sections_read"].append(section["header"]["section_number"]) sdt_secions_status[transport_stream_id]["content"] += section["content"] if len(sdt_secions_status[transport_stream_id]["sections_read"]) == sdt_secions_status[transport_stream_id]["sections_count"]: transport_stream_id_list.remove(transport_stream_id) if len(transport_stream_id_list) == 0: break if len(transport_stream_id_list) > 0: print>>log, "[DvbScanner] Cannot fetch SDT for the following transport_stream_id list: ", transport_stream_id_list dvbreader.close(fd) for key in sdt_secions_status: for section in sdt_secions_status[key]["content"]: srvkey = "%x:%x:%x" % (section["transport_stream_id"], section["original_network_id"], section["service_id"]) if srvkey not in tmp_services_dict: continue service = tmp_services_dict[srvkey] service["free_ca"] = section["free_ca"] service["service_name"] = section["service_name"] service["provider_name"] = section["provider_name"] video_services = {} radio_services = {} service_extra_count = 0 for key in tmp_services_dict: service = tmp_services_dict[key] if len(servicehacks) > 0: skip = False exec(servicehacks) if skip: continue tpkey = "%x:%x:%x" % (service["namespace"], service["transport_stream_id"], service["original_network_id"]) if tpkey not in transponders: continue transponders[tpkey]["services"][service["service_id"]] = service service_extra_count += 1 if service["service_type"] in DvbScanner.VIDEO_ALLOWED_TYPES or service["service_type"] in DvbScanner.INTERACTIVE_ALLOWED_TYPES: for number in service["numbers"]: if service["region_id"] == 0xffff: if number not in video_services: video_services[number] = service else: video_services[number] = service else: for number in service["numbers"]: if number not in radio_services: radio_services[number] = service print>>log, "[DvbScanner] Read extra info for %d services" % service_extra_count return { "video": video_services, "radio": radio_services }
def readNIT(self): adapter = 0 demuxer_device = "/dev/dvb/adapter%d/demux%d" % (adapter, self.demuxer_id) nit_current_pid = 0x10 nit_current_table_id = 0x40 nit_other_table_id = 0x00 # don't read other table if nit_other_table_id == 0x00: mask = 0xff else: mask = nit_current_table_id ^ nit_other_table_id ^ 0xff nit_current_timeout = 20 # maximum time allowed to read the network information table (seconds) nit_current_version_number = -1 nit_current_sections_read = [] nit_current_sections_count = 0 nit_current_content = [] nit_current_completed = False fd = dvbreader.open(demuxer_device, nit_current_pid, nit_current_table_id, mask, self.selectedNIM) if fd < 0: print("[MakeBouquet][readNIT] Cannot open the demuxer") return timeout = datetime.datetime.now() timeout += datetime.timedelta(0, nit_current_timeout) while True: if datetime.datetime.now() > timeout: print("[MakeBouquet][readNIT] Timed out reading NIT") break section = dvbreader.read_nit(fd, nit_current_table_id, nit_other_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"][ "table_id"] == nit_current_table_id and not nit_current_completed: if section["header"][ "version_number"] != nit_current_version_number: nit_current_version_number = section["header"][ "version_number"] nit_current_sections_read = [] nit_current_sections_count = section["header"][ "last_section_number"] + 1 nit_current_content = [] if section["header"][ "section_number"] not in nit_current_sections_read: nit_current_sections_read.append( section["header"]["section_number"]) nit_current_content += section["content"] if len(nit_current_sections_read ) == nit_current_sections_count: nit_current_completed = True if nit_current_completed: break dvbreader.close(fd) if not nit_current_content: print("[MakeBouquet][readNIT] current transponder not found") return # descriptor_tag 0x5A is DVB-T, descriptor_tag 0x7f is DVB-T transponders = [ t for t in nit_current_content if "descriptor_tag" in t and t["descriptor_tag"] in (0x5A, 0x7f) and t["original_network_id"] == self.transponder["onid"] and t["transport_stream_id"] == self.transponder["tsid"] ] # this should only ever have a length of one transponder print("[MakeBouquet][readNIT] transponders", transponders) if transponders: if transponders[0]["descriptor_tag"] == 0x5A: # DVB-T self.transponder[ "system"] = eDVBFrontendParametersTerrestrial.System_DVB_T else: # must be DVB-T2 self.transponder[ "system"] = eDVBFrontendParametersTerrestrial.System_DVB_T2 if "frequency" in transponders[0] and abs( (transponders[0]["frequency"] * 10) - self. transponder["frequency"]) < 1000000 and self.transponder[ "frequency"] != transponders[0]["frequency"] * 10: print( "[MakeBouquet][readNIT] updating transponder frequency from %.03f MHz to %.03f MHz" % (self.transponder["frequency"] // 1000000, transponders[0]["frequency"] // 100000)) self.transponder[ "frequency"] = transponders[0]["frequency"] * 10 # LCNs = [t for t in nit_current_content if "descriptor_tag" in t and t["descriptor_tag"] == self.lcndescriptor and t["original_network_id"] == self.transponder["onid"]] LCNs = [ t for t in nit_current_content if "descriptor_tag" in t and t["descriptor_tag"] == self.lcndescriptor and ( self.lcndescriptor == 0x83 or (self.lcndescriptor == 0x87 and ( "channel_list_id" in t and t["channel_list_id"] == self.channel_list_id or self.channel_list_id == 0))) and t["original_network_id"] == self.transponder["onid"] ] print("[MakeBouquet][readNIT] LCNs", LCNs) if LCNs: for LCN in LCNs: LCNkey = "%x:%x:%x" % (LCN["transport_stream_id"], LCN["original_network_id"], LCN["service_id"]) if not self.ignore_visible_service_flag and "visible_service_flag" in LCN and LCN[ "visible_service_flag"] == 0: continue # Only write to the dict if there is no entry, or override the entry if the data comes from the same transponder the channel is located on. if LCNkey not in self.logical_channel_number_dict or LCN[ "transport_stream_id"] == self.transponder["tsid"]: self.logical_channel_number_dict[LCNkey] = LCN namespace = 0xEEEE0000 if self.namespace_complete_terrestrial: namespace |= (self.transponder['frequency'] // 1000000) & 0xFFFF namespacekey = "%x:%x" % (self.transponder["tsid"], self.transponder["onid"]) self.namespace_dict[namespacekey] = namespace
def updateTransponders(self, transponders, read_other_section=False, netid=None, bouquettype=None): print >> log, "[DvbScanner] Reading transponders..." if self.nit_other_table_id == 0x00: mask = 0xFF else: mask = self.nit_current_table_id ^ self.nit_other_table_id ^ 0xFF print >> log, "[DvbScanner] demuxer_device", str(self.demuxer_device) print >> log, "[DvbScanner] nit_pid", str(self.nit_pid) print >> log, "[DvbScanner] nit_current_table_id", str(self.nit_current_table_id) print >> log, "[DvbScanner] mask", str(mask) print >> log, "[DvbScanner] frontend", str(self.frontend) fd = dvbreader.open(self.demuxer_device, self.nit_pid, self.nit_current_table_id, mask, self.frontend) if fd < 0: print >> log, "[DvbScanner] Cannot open the demuxer" return None nit_current_section_version = -1 nit_current_section_network_id = -1 nit_current_sections_read = [] nit_current_sections_count = 0 nit_current_content = [] nit_current_completed = False nit_other_section_version = -1 nit_other_section_network_id = -1 nit_other_sections_read = [] nit_other_sections_count = 0 nit_other_content = [] nit_other_completed = not read_other_section or self.nit_other_table_id == 0x00 timeout = datetime.datetime.now() timeout += datetime.timedelta(0, self.TIMEOUT_SEC) while True: if datetime.datetime.now() > timeout: print >> log, "[DvbScanner] Timed out" break section = dvbreader.read_nit(fd, self.nit_current_table_id, self.nit_other_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if ( section["header"]["table_id"] == self.nit_current_table_id and self.dvbtype != "dvbc" and not nit_current_completed ): if ( section["header"]["version_number"] != nit_current_section_version or section["header"]["network_id"] != nit_current_section_network_id ): nit_current_section_version = section["header"]["version_number"] nit_current_section_network_id = section["header"]["network_id"] nit_current_sections_read = [] nit_current_content = [] nit_current_sections_count = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in nit_current_sections_read: nit_current_sections_read.append(section["header"]["section_number"]) nit_current_content += section["content"] if len(nit_current_sections_read) == nit_current_sections_count: nit_current_completed = True elif ( str(section["header"]["network_id"]) == str(netid) and self.dvbtype == "dvbc" and not nit_current_completed ): if ( section["header"]["version_number"] != nit_current_section_version or section["header"]["network_id"] != nit_current_section_network_id ): nit_current_section_version = section["header"]["version_number"] nit_current_section_network_id = section["header"]["network_id"] nit_current_sections_read = [] nit_current_content = [] nit_current_sections_count = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in nit_current_sections_read: nit_current_sections_read.append(section["header"]["section_number"]) nit_current_content += section["content"] if len(nit_current_sections_read) == nit_current_sections_count: nit_current_completed = True nit_other_completed = True elif section["header"]["table_id"] == self.nit_other_table_id and not nit_other_completed: if ( section["header"]["version_number"] != nit_other_section_version or section["header"]["network_id"] != nit_other_section_network_id ): nit_other_section_version = section["header"]["version_number"] nit_other_section_network_id = section["header"]["network_id"] nit_other_sections_read = [] nit_other_content = [] nit_other_sections_count = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in nit_other_sections_read: nit_other_sections_read.append(section["header"]["section_number"]) nit_other_content += section["content"] if len(nit_other_sections_read) == nit_other_sections_count: nit_other_completed = True if nit_current_completed and nit_other_completed: print >> log, "[DvbScanner] Scan complete, netid: ", str(netid) break dvbreader.close(fd) nit_content = nit_current_content nit_content += nit_other_content transport_stream_id_list = [] logical_channel_number_dict = {} logical_channel_number_dict_tmp = {} hd_logical_channel_number_dict_tmp = {} transponders_count = 0 for transponder in nit_content: print "LINE:", transponder if len(transponder) == 5: # lcn key = "%x:%x:%x" % ( transponder["transport_stream_id"], transponder["original_network_id"], transponder["service_id"], ) logical_channel_number_dict_tmp[key] = transponder continue if len(transponder) == 6: # HD lcn key = "%x:%x:%x" % ( transponder["transport_stream_id"], transponder["original_network_id"], transponder["service_id"], ) hd_logical_channel_number_dict_tmp[key] = transponder continue transponder["services"] = {} transponder["dvb_type"] = self.dvbtype transponder["bouquet_type"] = bouquettype if transponder["dvb_type"] == "dvbc": # DVB-C transponder["symbol_rate"] = transponder["symbol_rate"] * 100 transponder["flags"] = 0 if transponder["fec_inner"] != 15 and transponder["fec_inner"] > 9: transponder["fec_inner"] = 0 transponder["frequency"] = transponder["frequency"] / 10 transponder["namespace"] = 0xFFFF0000 transponder["inversion"] = transponder["fec_outer"] transponder["modulation_system"] = 0 elif transponder["dvb_type"] == "dvbt": # DVB-T transponder["namespace"] = 0xEEEE0000 transponder["frequency"] = transponder["frequency"] * 10 transponder["inversion"] = 0 transponder["plpid"] = 0 transponder["flags"] = 0 transponder["system"] = 0 elif transponder["dvb_type"] == "dvbs": # DVB-S transponder["symbol_rate"] = transponder["symbol_rate"] * 100 transponder["flags"] = 0 if transponder["fec_inner"] != 15 and transponder["fec_inner"] > 9: transponder["fec_inner"] = 0 transponder["frequency"] = transponder["frequency"] * 10 orbital_position = ((transponder["orbital_position"] >> 12) & 0x0F) * 1000 orbital_position += ((transponder["orbital_position"] >> 8) & 0x0F) * 100 orbital_position += ((transponder["orbital_position"] >> 4) & 0x0F) * 10 orbital_position += transponder["orbital_position"] & 0x0F if orbital_position != 0 and transponder["west_east_flag"] == 0: orbital_position = 3600 - orbital_position transponder["orbital_position"] = orbital_position transponder["pilot"] = 2 if transponder["modulation_system"] == 0 and transponder["modulation_type"] == 2: transponder["modulation_type"] = 1 transponder["inversion"] = 2 transponder["namespace"] = self.buildNamespace(transponder) key = "%x:%x:%x" % ( transponder["namespace"], transponder["transport_stream_id"], transponder["original_network_id"], ) if key in transponders: transponder["services"] = transponders[key]["services"] transponders[key] = transponder transponders_count += 1 if transponder["transport_stream_id"] not in transport_stream_id_list: transport_stream_id_list.append(transponder["transport_stream_id"]) if read_other_section: print >> log, "[DvbScanner] Added/Updated %d transponders with network_id = 0x%x and network_id = 0x%x" % ( transponders_count, nit_current_section_network_id, nit_other_section_network_id, ) else: print >> log, "[DvbScanner] Added/Updated %d transponders with network_id = 0x%x" % ( transponders_count, nit_current_section_network_id, ) if len(hd_logical_channel_number_dict_tmp) > 0 and bouquettype == "hd": for id in logical_channel_number_dict_tmp: if id in hd_logical_channel_number_dict_tmp: lcntofind = hd_logical_channel_number_dict_tmp[id]["logical_channel_number"] lcnreplace = logical_channel_number_dict_tmp[id]["logical_channel_number"] for id2 in logical_channel_number_dict_tmp: if logical_channel_number_dict_tmp[id2]["logical_channel_number"] == lcntofind: logical_channel_number_dict[id] = logical_channel_number_dict_tmp[id2] logical_channel_number_dict[id]["logical_channel_number"] = lcnreplace logical_channel_number_dict[id] = hd_logical_channel_number_dict_tmp[id] else: logical_channel_number_dict[id] = logical_channel_number_dict_tmp[id] else: for id in logical_channel_number_dict_tmp: logical_channel_number_dict[id] = logical_channel_number_dict_tmp[id] return { "transport_stream_id_list": transport_stream_id_list, "logical_channel_number_dict": logical_channel_number_dict, }
def readSDT(self): adapter = 0 demuxer_device = "/dev/dvb/adapter%d/demux%d" % (adapter, self.demuxer_id) self.tsid = None self.onid = None sdt_pid = 0x11 sdt_current_table_id = 0x42 mask = 0xff # only read SDT actual, not SDT other. sdtTimeout = 5 # maximum time allowed to read the service descriptor table (seconds) sdt_current_version_number = -1 sdt_current_sections_read = [] sdt_current_sections_count = 0 sdt_current_content = [] sdt_current_completed = False fd = dvbreader.open(demuxer_device, sdt_pid, sdt_current_table_id, mask, self.selectedNIM) if fd < 0: print "[MisPlsLcnScan][readSDT] Cannot open the demuxer" return None timeout = datetime.datetime.now() timeout += datetime.timedelta(0, sdtTimeout) while True: if datetime.datetime.now() > timeout: print "[MisPlsLcnScan][readSDT] Timed out" break section = dvbreader.read_sdt(fd, sdt_current_table_id, 0x00) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"][ "table_id"] == sdt_current_table_id and not sdt_current_completed: if section["header"][ "version_number"] != sdt_current_version_number: sdt_current_version_number = section["header"][ "version_number"] sdt_current_sections_read = [] sdt_current_sections_count = section["header"][ "last_section_number"] + 1 sdt_current_content = [] if section["header"][ "section_number"] not in sdt_current_sections_read: sdt_current_sections_read.append( section["header"]["section_number"]) sdt_current_content += section["content"] if self.tsid is None or self.onid is None: # save first read of tsid and onid. self.tsid = section["header"]["transport_stream_id"] self.onid = section["header"]["original_network_id"] if self.onid not in PROVIDERS[ config.plugins.MisPlsLcnScan.provider. value]["onids"]: dvbreader.close(fd) return if len(sdt_current_sections_read ) == sdt_current_sections_count: sdt_current_completed = True if sdt_current_completed: break dvbreader.close(fd) if not sdt_current_content: print "[MisPlsLcnScan][readSDT] no services found on transponder" return for i in range(len(sdt_current_content)): service = sdt_current_content[i] if self.FTA_only and service["free_ca"] != 0: continue if service[ "service_type"] not in self.VIDEO_ALLOWED_TYPES and service[ "service_type"] not in self.AUDIO_ALLOWED_TYPES: continue servicekey = "%x:%x:%x" % (service["transport_stream_id"], service["original_network_id"], service["service_id"]) self.tmp_services_dict[servicekey] = service
def updateAndReadServicesFastscan( self, namespace, transponders, servicehacks, transport_stream_id_list, logical_channel_number_dict ): print >> log, "[DvbScanner] Reading services..." fd = dvbreader.open(self.demuxer_device, self.fastscan_pid, self.fastscan_table_id, 0xFF, self.frontend) if fd < 0: print >> log, "[DvbScanner] Cannot open the demuxer" return None fastscan_section_version = -1 fastscan_section_id = -1 fastscan_sections_read = [] fastscan_sections_count = 0 fastscan_content = [] timeout = datetime.datetime.now() timeout += datetime.timedelta(0, self.TIMEOUT_SEC) while True: if datetime.datetime.now() > timeout: print >> log, "[DvbScanner] Timed out" break section = dvbreader.read_fastscan(fd, self.fastscan_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == self.fastscan_table_id: if ( section["header"]["version_number"] != fastscan_section_version or section["header"]["fastscan_id"] != fastscan_section_id ): fastscan_section_version = section["header"]["version_number"] fastscan_section_id = section["header"]["fastscan_id"] fastscan_sections_read = [] fastscan_content = [] fastscan_sections_count = section["header"]["last_section_number"] + 1 if section["header"]["section_number"] not in fastscan_sections_read: fastscan_sections_read.append(section["header"]["section_number"]) fastscan_content += section["content"] if len(fastscan_sections_read) == fastscan_sections_count: break dvbreader.close(fd) service_count = 0 tmp_services_dict = {} for section in fastscan_content: service = section key = "%x:%x:%x" % (service["transport_stream_id"], service["original_network_id"], service["service_id"]) if key not in logical_channel_number_dict: continue if logical_channel_number_dict[key]["visible_service_flag"] == 0: continue service["free_ca"] = 1 service["namespace"] = namespace service["flags"] = 0 service["number"] = logical_channel_number_dict[key]["logical_channel_number"] if key in tmp_services_dict: tmp_services_dict[key]["numbers"].append(service["number"]) else: service["numbers"] = [service["number"]] tmp_services_dict[key] = service service_count += 1 print >> log, "[DvbScanner] Read %d services" % service_count video_services = {} radio_services = {} service_extra_count = 0 for key in tmp_services_dict: service = tmp_services_dict[key] if len(servicehacks) > 0: skip = False exec (servicehacks) if skip: continue tpkey = "%x:%x:%x" % (service["namespace"], service["transport_stream_id"], service["original_network_id"]) if tpkey not in transponders: continue transponders[tpkey]["services"][service["service_id"]] = service service_extra_count += 1 if ( service["service_type"] in DvbScanner.VIDEO_ALLOWED_TYPES or service["service_type"] in DvbScanner.INTERACTIVE_ALLOWED_TYPES ): for number in service["numbers"]: if number not in video_services: video_services[number] = service else: for number in service["numbers"]: if number not in radio_services: radio_services[number] = service print >> log, "[DvbScanner] %d valid services" % service_extra_count return {"video": video_services, "radio": radio_services}
def readNIT(self): adapter = 0 demuxer_device = "/dev/dvb/adapter%d/demux%d" % (adapter, self.demuxer_id) nit_current_pid = 0x10 nit_current_table_id = 0x40 nit_other_table_id = 0x00 # don't read other table if nit_other_table_id == 0x00: mask = 0xff else: mask = nit_current_table_id ^ nit_other_table_id ^ 0xff nit_current_timeout = 20 # maximum time allowed to read the network information table (seconds) nit_current_version_number = -1 nit_current_sections_read = [] nit_current_sections_count = 0 nit_current_content = [] nit_current_completed = False fd = dvbreader.open(demuxer_device, nit_current_pid, nit_current_table_id, mask, self.selectedNIM) if fd < 0: print "[MakeBouquet][readNIT] Cannot open the demuxer" return timeout = datetime.datetime.now() timeout += datetime.timedelta(0, nit_current_timeout) while True: if datetime.datetime.now() > timeout: print "[MakeBouquet][readNIT] Timed out reading NIT" break section = dvbreader.read_nit(fd, nit_current_table_id, nit_other_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"][ "table_id"] == nit_current_table_id and not nit_current_completed: if section["header"][ "version_number"] != nit_current_version_number: nit_current_version_number = section["header"][ "version_number"] nit_current_sections_read = [] nit_current_sections_count = section["header"][ "last_section_number"] + 1 nit_current_content = [] if section["header"][ "section_number"] not in nit_current_sections_read: nit_current_sections_read.append( section["header"]["section_number"]) nit_current_content += section["content"] if len(nit_current_sections_read ) == nit_current_sections_count: nit_current_completed = True if nit_current_completed: break dvbreader.close(fd) if not nit_current_content: print "[MakeBouquet][readNIT] current transponder not found" return LCNs = [ t for t in nit_current_content if "descriptor_tag" in t and t["descriptor_tag"] == 0x83 and t["original_network_id"] in PROVIDERS[ config.plugins.MisPlsLcnScan.provider.value]["onids"] ] print "[MakeBouquet][readNIT] LCNs", LCNs if LCNs: for LCN in LCNs: LCNkey = "%x:%x:%x" % (LCN["transport_stream_id"], LCN["original_network_id"], LCN["service_id"]) if not self.ignore_visible_service_flag and "visible_service_flag" in LCN and LCN[ "visible_service_flag"] == 0: continue # Only write to the dict if there is no entry, or override the entry if the data comes from the same transponder the channel is located on. if LCNkey not in self.logical_channel_number_dict or LCN[ "transport_stream_id"] == self.tsid: self.logical_channel_number_dict[LCNkey] = LCN namespace = self.transpondercurrent.orbital_position << 16 if self.namespace_complete: namespace |= ( (self.transpondercurrent.frequency / 1000) & 0xFFFF) | ( (self.transpondercurrent.polarisation & 1) << 15) namespacekey = "%x:%x" % (self.tsid, self.onid) self.namespace_dict[namespacekey] = namespace
def readBouquet(bouquet_id): print("[DvbScanner] Reading bouquet_id = 0x%x..." % bouquet_id) fd = dvbreader.open("/dev/dvb/adapter0/demux0", bat_pid, bat_table, mask, frontend) if fd < 0: print("[DvbScanner] Cannot open the demuxer") return None bat_section_version = -1 bat_sections_read = [] bat_sections_count = 0 bat_content = [] timeout = datetime.datetime.now() timeout += datetime.timedelta(0, TIMEOUT_SEC) while True: if datetime.datetime.now() > timeout: print("[DvbScanner] Timed out") break section = dvbreader.read_bat(fd, bat_table) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == bat_table: if section["header"]["bouquet_id"] != bouquet_id: continue if section["header"]["version_number"] != bat_section_version: bat_section_version = section["header"]["version_number"] bat_sections_read = [] bat_content = [] bat_sections_count = section["header"][ "last_section_number"] + 1 if section["header"]["section_number"] not in bat_sections_read: bat_sections_read.append(section["header"]["section_number"]) bat_content += section["content"] if len(bat_sections_read) == bat_sections_count: break dvbreader.close(fd) bouquet_name = None for section in bat_content: if section["descriptor_tag"] == 0x47: bouquet_name = section["description"] break if bouquet_name is None: print("[DvbScanner] Cannot get bouquet name for bouquet_id = 0x%x" % bouquet_id) return for section in bat_content: if section["descriptor_tag"] == 0xd4: bouquet = { "name": bouquet_name + " - " + section["description"], "region": section["region_id"], "bouquet": bouquet_id } bouquets_list.append(bouquet) print("[DvbScanner] Done")
def updateTransponders(self, transponders, read_other_section=False): print >> log, "[DvbScanner] Reading transponders..." if self.nit_other_table_id == 0x00: mask = 0xff else: mask = self.nit_current_table_id ^ self.nit_other_table_id ^ 0xff fd = dvbreader.open(self.demuxer_device, self.nit_pid, self.nit_current_table_id, mask, self.frontend) if fd < 0: print >> log, "[DvbScanner] Cannot open the demuxer" return None nit_current_section_version = -1 nit_current_section_network_id = -1 nit_current_sections_read = [] nit_current_sections_count = 0 nit_current_content = [] nit_current_completed = False nit_other_section_version = -1 nit_other_section_network_id = -1 nit_other_sections_read = [] nit_other_sections_count = 0 nit_other_content = [] nit_other_completed = not read_other_section or self.nit_other_table_id == 0x00 timeout = datetime.datetime.now() timeout += datetime.timedelta(0, self.TIMEOUT_SEC) while True: if datetime.datetime.now() > timeout: print >> log, "[DvbScanner] Timed out" break section = dvbreader.read_nit(fd, self.nit_current_table_id, self.nit_other_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"][ "table_id"] == self.nit_current_table_id and not nit_current_completed: if (section["header"]["version_number"] != nit_current_section_version or section["header"]["network_id"] != nit_current_section_network_id): nit_current_section_version = section["header"][ "version_number"] nit_current_section_network_id = section["header"][ "network_id"] nit_current_sections_read = [] nit_current_content = [] nit_current_sections_count = section["header"][ "last_section_number"] + 1 if section["header"][ "section_number"] not in nit_current_sections_read: nit_current_sections_read.append( section["header"]["section_number"]) nit_current_content += section["content"] if len(nit_current_sections_read ) == nit_current_sections_count: nit_current_completed = True elif section["header"][ "table_id"] == self.nit_other_table_id and not nit_other_completed: if (section["header"]["version_number"] != nit_other_section_version or section["header"]["network_id"] != nit_other_section_network_id): nit_other_section_version = section["header"][ "version_number"] nit_other_section_network_id = section["header"][ "network_id"] nit_other_sections_read = [] nit_other_content = [] nit_other_sections_count = section["header"][ "last_section_number"] + 1 if section["header"][ "section_number"] not in nit_other_sections_read: nit_other_sections_read.append( section["header"]["section_number"]) nit_other_content += section["content"] if len(nit_other_sections_read ) == nit_other_sections_count: nit_other_completed = True if nit_current_completed and nit_other_completed: break dvbreader.close(fd) nit_content = nit_current_content nit_content += nit_other_content transport_stream_id_list = [] logical_channel_number_dict = {} transponders_count = 0 for transponder in nit_content: if len(transponder) == 5: # lcn key = "%x:%x:%x" % (transponder["transport_stream_id"], transponder["original_network_id"], transponder["service_id"]) logical_channel_number_dict[key] = transponder continue transponder["services"] = {} transponder["dvb_type"] = "s" transponder["frequency"] = transponder["frequency"] * 10 transponder["symbol_rate"] = transponder["symbol_rate"] * 100 if transponder["fec_inner"] != 15 and transponder["fec_inner"] > 9: transponder["fec_inner"] = 0 orbital_position = ( (transponder["orbital_position"] >> 12) & 0x0F) * 1000 orbital_position += ( (transponder["orbital_position"] >> 8) & 0x0F) * 100 orbital_position += ( (transponder["orbital_position"] >> 4) & 0x0F) * 10 orbital_position += transponder["orbital_position"] & 0x0F if orbital_position != 0 and transponder["west_east_flag"] == 0: orbital_position = 3600 - orbital_position transponder["orbital_position"] = orbital_position if transponder["modulation_system"] == 0 and transponder[ "modulation_type"] == 2: transponder["modulation_type"] = 1 transponder["namespace"] = self.buildNamespace(transponder) transponder["inversion"] = 2 transponder["flags"] = 0 transponder["pilot"] = 2 key = "%x:%x:%x" % (transponder["namespace"], transponder["transport_stream_id"], transponder["original_network_id"]) if key in transponders: transponder["services"] = transponders[key]["services"] transponders[key] = transponder transponders_count += 1 if transponder[ "transport_stream_id"] not in transport_stream_id_list: transport_stream_id_list.append( transponder["transport_stream_id"]) if read_other_section: print >> log, "[DvbScanner] Added/Updated %d transponders with network_id = 0x%x and network_id = 0x%x" % ( transponders_count, nit_current_section_network_id, nit_other_section_network_id) else: print >> log, "[DvbScanner] Added/Updated %d transponders with network_id = 0x%x" % ( transponders_count, nit_current_section_network_id) return { "transport_stream_id_list": transport_stream_id_list, "logical_channel_number_dict": logical_channel_number_dict }
def readNIT(self): adapter = 0 demuxer_device = "/dev/dvb/adapter%d/demux%d" % (adapter, self.demuxer_id) nit_current_pid = 0x10 nit_current_table_id = 0x40 nit_other_table_id = 0x00 # don't read other table if nit_other_table_id == 0x00: mask = 0xff else: mask = nit_current_table_id ^ nit_other_table_id ^ 0xff nit_current_timeout = 20 # maximum time allowed to read the network information table (seconds) nit_current_version_number = -1 nit_current_sections_read = [] nit_current_sections_count = 0 nit_current_content = [] nit_current_completed = False fd = dvbreader.open(demuxer_device, nit_current_pid, nit_current_table_id, mask, self.selectedNIM) if fd < 0: print "[MakeBouquet][readNIT] Cannot open the demuxer" return timeout = datetime.datetime.now() timeout += datetime.timedelta(0, nit_current_timeout) while True: if datetime.datetime.now() > timeout: print "[MakeBouquet][readNIT] Timed out reading NIT" break section = dvbreader.read_nit(fd, nit_current_table_id, nit_other_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == nit_current_table_id and not nit_current_completed: if section["header"]["version_number"] != nit_current_version_number: nit_current_version_number = section["header"]["version_number"] nit_current_sections_read = [] nit_current_sections_count = section["header"]["last_section_number"] + 1 nit_current_content = [] if section["header"]["section_number"] not in nit_current_sections_read: nit_current_sections_read.append(section["header"]["section_number"]) nit_current_content += section["content"] if len(nit_current_sections_read) == nit_current_sections_count: nit_current_completed = True if nit_current_completed: break dvbreader.close(fd) if not nit_current_content: print "[MakeBouquet][readNIT] current transponder not found" return # descriptor_tag 0x5A is DVB-T, descriptor_tag 0x7f is DVB-T transponders = [t for t in nit_current_content if "descriptor_tag" in t and t["descriptor_tag"] in (0x5A, 0x7f) and t["original_network_id"] == self.transponder["onid"] and t["transport_stream_id"] == self.transponder["tsid"]] # this should only ever have a length of one transponder print "[MakeBouquet][readNIT] transponders", transponders if transponders: if transponders[0]["descriptor_tag"] == 0x5A: # DVB-T self.transponder["system"] = eDVBFrontendParametersTerrestrial.System_DVB_T else: # must be DVB-T2 self.transponder["system"] = eDVBFrontendParametersTerrestrial.System_DVB_T2 if "frequency" in transponders[0] and abs((transponders[0]["frequency"]*10) - self.transponder["frequency"]) < 1000000 and self.transponder["frequency"] != transponders[0]["frequency"]*10: print "[MakeBouquet][readNIT] updating transponder frequency from %.03f MHz to %.03f MHz" % (self.transponder["frequency"]/1000000, transponders[0]["frequency"]/100000) self.transponder["frequency"] = transponders[0]["frequency"]*10 LCNs = [t for t in nit_current_content if "descriptor_tag" in t and t["descriptor_tag"] == 0x83 and t["original_network_id"] == self.transponder["onid"]] print "[MakeBouquet][readNIT] LCNs", LCNs if LCNs: for LCN in LCNs: LCNkey = "%x:%x:%x" % (LCN["transport_stream_id"], LCN["original_network_id"], LCN["service_id"]) if not self.ignore_visible_service_flag and "visible_service_flag" in LCN and LCN["visible_service_flag"] == 0: continue # Only write to the dict if there is no entry, or override the entry if the data comes from the same transponder the channel is located on. if LCNkey not in self.logical_channel_number_dict or LCN["transport_stream_id"] == self.transponder["tsid"]: self.logical_channel_number_dict[LCNkey] = LCN namespace = 0xEEEE0000 if self.namespace_complete_terrestrial: namespace |= (self.transponder['frequency']/1000000)&0xFFFF namespacekey = "%x:%x" % (self.transponder["tsid"], self.transponder["onid"]) self.namespace_dict[namespacekey] = namespace
def readNIT(self): adapter = 0 demuxer_device = "/dev/dvb/adapter%d/demux%d" % (adapter, self.demuxer_id) start = time.time() # for debug info nit_current_pid = 0x10 nit_current_table_id = 0x40 nit_other_table_id = 0x00 # don't read other table self.network_name = None self.custom_transponder_needed = True if nit_other_table_id == 0x00: mask = 0xff else: mask = nit_current_table_id ^ nit_other_table_id ^ 0xff nit_current_timeout = 20 # maximum time allowed to read the network information table (seconds) nit_current_version_number = -1 nit_current_sections_read = [] nit_current_sections_count = 0 nit_current_content = [] nit_current_completed = False fd = dvbreader.open(demuxer_device, nit_current_pid, nit_current_table_id, mask, self.selectedNIM) if fd < 0: print "[ABM-FrequencyFinder][readNIT] Cannot open the demuxer" return timeout = datetime.datetime.now() timeout += datetime.timedelta(0, nit_current_timeout) while True: if datetime.datetime.now() > timeout: print "[ABM-FrequencyFinder][readNIT] Timed out reading NIT" break section = dvbreader.read_nit(fd, nit_current_table_id, nit_other_table_id) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == nit_current_table_id and not nit_current_completed: if section["header"]["version_number"] != nit_current_version_number: nit_current_version_number = section["header"]["version_number"] nit_current_sections_read = [] nit_current_sections_count = section["header"]["last_section_number"] + 1 nit_current_content = [] if section["header"]["section_number"] not in nit_current_sections_read: nit_current_sections_read.append(section["header"]["section_number"]) nit_current_content += section["content"] if 'network_name' in section["header"] and section["header"]["network_name"] != "Unknown": self.network_name = section["header"]["network_name"] if len(nit_current_sections_read) == nit_current_sections_count: nit_current_completed = True if nit_current_completed: break dvbreader.close(fd) if not nit_current_content: print "[ABM-FrequencyFinder][readNIT] current transponder not found" return print "[ABM-FrequencyFinder][readNIT] NIT read time %.1f seconds." % (time.time() - start) # descriptor_tag 0x5A is DVB-T, descriptor_tag 0x7f is DVB-T transponders = [t for t in nit_current_content if "descriptor_tag" in t and t["descriptor_tag"] in (0x5A, 0x7f) and t["original_network_id"] == self.onid and t["transport_stream_id"] == self.tsid] # this should only ever have a length of one transponder print "[ABM-FrequencyFinder][readNIT] transponders", transponders if transponders: if transponders[0]["descriptor_tag"] == 0x5A: # DVB-T self.system = eDVBFrontendParametersTerrestrial.System_DVB_T else: # must be DVB-T2 self.system = eDVBFrontendParametersTerrestrial.System_DVB_T2 if "frequency" in transponders[0] and abs((transponders[0]["frequency"]*10) - self.frequency) < 1000000: self.custom_transponder_needed = False if self.frequency != transponders[0]["frequency"]*10: print "[ABM-FrequencyFinder][readNIT] updating transponder frequency from %.03f MHz to %.03f MHz" % (self.frequency/1000000, transponders[0]["frequency"]/100000) self.frequency = transponders[0]["frequency"]*10