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 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 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 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 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 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 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 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 }