def epg_process(config, location): dummy_xml(config, location) try: while True: time.sleep(config["main"]["epg_update_frequency"]) print("Fetching EPG for DMA " + str(location["DMA"]) + ".") generate_epg_file(config, location) except KeyboardInterrupt: clean_exit()
def get_config_path(self, script_dir, args): if args.cfg: self.config_file = pathlib.Path(str(args.cfg)) else: for x in ['config/config.ini', 'config.ini']: poss_config = pathlib.Path(script_dir).joinpath(x) print(poss_config) if os.path.exists(poss_config): self.config_file = poss_config break if not self.config_file or not os.path.exists(self.config_file): print("Config file missing, Exiting...") clean_exit(1) print("Loading Configuration File: " + str(self.config_file))
def stations_process(config, locast, location): try: while True: time.sleep(config["main"]["fcc_delay"]) # Work in eastern time, since that is what the FCC is using to determine maintenance times currentTime = datetime.datetime.now(tz=EST5EDT()) # if we find we're returning from delay at a time that the FCC is doing maintenance, sleep a bit more... if (currentTime.hour >= 3) and (currentTime.hour <= 5): # get the exact time we need to wait until we can grab the FCC data sleepTime = ((6 - currentTime.hour) * 60 * 60) sleepTime = (sleepTime - (currentTime.minute + 60)) sleepTime = (sleepTime - currentTime.second) time.sleep(sleepTime) refresh_dma_stations_and_channels(config, locast, location) except KeyboardInterrupt: clean_exit()
def __init__(self, config): self.mock_location = config["main"]["mock_location"] self.zipcode = config["main"]["override_zipcode"] # Check for user's location # Find the users location via lat\long or zipcode if specified,(lat\lon # taking precedence if both are provided) otherwise use IP. Attempts to # mirror the geolocation found at locast.org\dma. Also allows for a # check that Locast reports the area as active. if self.find_location(): print("Got location as {} - DMA {} - Lat\Lon {}\{}".format( self.location['city'], self.location['DMA'], self.location['latitude'], self.location['longitude'])) else: print("Could not acertain location. Exiting...") clean_exit(1) # Check that Locast reports this market is currently active and available. if not self.location['active']: print( "Locast reports that this DMA\Market area is not currently active!" ) clean_exit(1)
def config_adjustments(self, opersystem, script_dir): if not self.data["main"]["locast_username"] or not self.data["main"][ "locast_password"]: print("Locast Login Credentials Missing. Exiting...") clean_exit(1) # Tuner Count Cannot be greater than 3 try: TUNER_COUNT = int(self.data["main"]["tuner_count"]) if not 1 <= TUNER_COUNT <= 4: print( "Tuner count set outside of 1-4 range. Setting to default" ) self.data["main"]["tuner_count"] = 3 except ValueError: print("tuner_count value is not valid. Setting to default") self.data["main"]["tuner_count"] = 3 print("Tuner count set to " + str(self.data["main"]["tuner_count"])) print("Server is set to run on " + str(self.data["main"]["plex_accessible_ip"]) + ":" + str(self.data["main"]["plex_accessible_port"])) if os.path.exists(pathlib.Path(script_dir).joinpath('is_container')): self.data["main"]["bind_ip"] = "0.0.0.0" self.data["main"]["bind_port"] = "6077" else: self.data["main"]["bind_ip"] = self.data["main"][ "plex_accessible_ip"] self.data["main"]["bind_port"] = self.data["main"][ "plex_accessible_port"] # generate UUID here for when we are not using docker if self.data["main"]["uuid"] is None: print("No UUID found. Generating one now...") # from https://pynative.com/python-generate-random-string/ # create a string that wouldn't be a real device uuid for self.data["main"]["uuid"] = ''.join( random.choice("hijklmnopqrstuvwxyz") for i in range(8)) self.write('main', 'uuid', self.data["main"]["uuid"]) print("UUID set to: " + self.data["main"]["uuid"] + "...") if (self.data["main"]["override_latitude"] is not None) and (self.data["main"]["override_longitude"] is not None): self.data["main"]["mock_location"] = { "latitude": self.data["main"]["override_latitude"], "longitude": self.data["main"]["override_longitude"] } if not self.data["main"]["ffmpeg_path"]: if opersystem in ["Windows"]: base_ffmpeg_dir = pathlib.Path(script_dir).joinpath('ffmpeg') self.data["main"]["ffmpeg_path"] = pathlib.Path( base_ffmpeg_dir).joinpath('ffmpeg.exe') else: self.data["main"]["ffmpeg_path"] = "ffmpeg" if not self.data["main"]["cache_dir"]: self.data["main"]["cache_dir"] = pathlib.Path(script_dir).joinpath( 'cache') else: self.data["main"]["cache_dir"] = pathlib.Path( self.data["main"]["cache_dir"]) if not self.data["main"]["cache_dir"].is_dir(): print("Invalid Cache Directory. Exiting...") clean_exit(1)
script_dir = pathlib.Path(os.path.dirname(os.path.abspath(__file__))) # Open Configuration File print("Opening and Verifying Configuration File.") config = get_config(script_dir, opersystem, args) print("Getting user location...") location_info = location.DMAFinder(config) locast = locast_service.LocastService(location_info.location) if (not locast.login(config["main"]["locast_username"], config["main"]["locast_password"])) or ( not locast.validate_user()): print("Invalid Locast Login Credentials. Exiting...") clean_exit(1) try: fcc_cache_dir = pathlib.Path( config["main"]["cache_dir"]).joinpath("stations") if not fcc_cache_dir.is_dir(): fcc_cache_dir.mkdir() print("Starting First time Stations refresh...") stations.refresh_dma_stations_and_channels(config, locast, location_info.location) print("Starting Stations thread...") stations_server = Process(target=stations.stations_process, args=(config, locast, location_info.location))