<commit_before><?php

class DVRUI_HDHRjson {
	private $myhdhrurl = 'http://ipv4.my.hdhomerun.com/discover';
	private $hdhrkey_devID = 'DeviceID';
	private $hdhrkey_localIP = 'LocalIP';
	private $hdhrkey_baseURL = 'BaseURL';
	private $hdhrkey_discoverURL = 'DiscoverURL';
	private $hdhrkey_lineupURL = 'LineupURL';
	private $hdhrkey_modelNum = 'ModelNumber';
	private $hdhrkey_modelName = 'FriendlyName';
	private $hdhrkey_auth = 'DeviceAuth';
	private $hdhrkey_fwVer = 'FirmwareVersion';
	private $hdhrkey_fwName = 'FirmwareName';
	private $hdhrkey_tuners = 'TunerCount';

	private $hdhrkey_storageID = 'StorageID';
	private $hdhrkey_storageURL = 'StorageURL';
	private $hdhrlist = array();
	private $hdhrlist_key_channelcount = 'ChannelCount';

	public function DVRUI_HDHRjson() {
		$storageURL = "??";
		$myip = getHostByName(getHostName());
		$json = file_get_contents($this->myhdhrurl);
		$hdhr_data = json_decode($json, true);
		for ($i=0;$i<count($hdhr_data);$i++) {
			$hdhr = $hdhr_data[$i];
			$hdhr_base = $hdhr[$this->hdhrkey_baseURL];
			$hdhr_ip = $hdhr[$this->hdhrkey_localIP];
			
			if (!array_key_exists($this->hdhrkey_discoverURL,$hdhr)) {
				// Skip this HDHR - it doesn't support the newer HTTP interface
				// for DVR
				continue;
			}

			if (array_key_exists($this->hdhrkey_storageURL,$hdhr)) {
				// this is a record engine!
				
				//get the IP address of record engine.
				$hdhr_ip = $hdhr[$this->hdhrkey_localIP];
				// Split IP and port
				if (preg_match('/^(\d[\d.]+):(\d+)\b/', $hdhr_ip, $matches)) {
				    $ip = $matches[1];
				    $port = $matches[2];
				    // if IP of record engine matches the IP of this server
				    // return storageURL
				    if($ip == $myip){	
					$this->storageURL = $hdhr[$this->hdhrkey_storageURL];
					continue;
				    }
				}
			}
			$hdhr_info_json = file_get_contents($hdhr[$this->hdhrkey_discoverURL]);
			$hdhr_info = json_decode($hdhr_info_json, true);
			$hdhr_lineup_json = file_get_contents($hdhr[$this->hdhrkey_lineupURL]);
			$hdhr_lineup = json_decode($hdhr_lineup_json, true);
		
			if (array_key_exists($this->hdhrkey_tuners,$hdhr_info)) {
				$this->hdhrlist[] = array( $this->hdhrkey_devID => $hdhr[$this->hdhrkey_devID],
											$this->hdhrkey_modelNum => $hdhr_info[$this->hdhrkey_modelNum],
											$this->hdhrlist_key_channelcount => count($hdhr_lineup),
											$this->hdhrkey_baseURL => $hdhr_base,
											$this->hdhrkey_lineupURL => $hdhr[$this->hdhrkey_lineupURL],
											$this->hdhrkey_modelName =>$hdhr_info[$this->hdhrkey_modelName],
											$this->hdhrkey_auth =>$hdhr_info[$this->hdhrkey_auth],
											$this->hdhrkey_fwVer => $hdhr_info[$this->hdhrkey_fwVer],
											$this->hdhrkey_tuners => $hdhr_info[$this->hdhrkey_tuners],
											$this->hdhrkey_fwName => $hdhr_info[$this->hdhrkey_fwName]);<commit_msg>Changes required to decouple the UI from the recording engine management<commit_after><?php

class DVRUI_HDHRjson {
	private $myhdhrurl = 'http://ipv4.my.hdhomerun.com/discover';
	private $hdhrkey_devID = 'DeviceID';
	private $hdhrkey_localIP = 'LocalIP';
	private $hdhrkey_baseURL = 'BaseURL';
	private $hdhrkey_discoverURL = 'DiscoverURL';
	private $hdhrkey_lineupURL = 'LineupURL';
	private $hdhrkey_modelNum = 'ModelNumber';
	private $hdhrkey_modelName = 'FriendlyName';
	private $hdhrkey_auth = 'DeviceAuth';
	private $hdhrkey_fwVer = 'FirmwareVersion';
	private $hdhrkey_fwName = 'FirmwareName';
	private $hdhrkey_tuners = 'TunerCount';

	private $hdhrkey_storageID = 'StorageID';
	private $hdhrkey_storageURL = 'StorageURL';
	private $hdhrlist = array();
	private $hdhrlist_key_channelcount = 'ChannelCount';

	public function DVRUI_HDHRjson() {
		$storageURL = "??";
		$myip = getHostByName(getHostName());
		$json = file_get_contents($this->myhdhrurl);
		$hdhr_data = json_decode($json, true);
		for ($i=0;$i<count($hdhr_data);$i++) {
			$hdhr = $hdhr_data[$i];
			$hdhr_base = $hdhr[$this->hdhrkey_baseURL];
			$hdhr_ip = $hdhr[$this->hdhrkey_localIP];
			
			if (!array_key_exists($this->hdhrkey_discoverURL,$hdhr)) {
				// Skip this HDHR - it doesn't support the newer HTTP interface
				// for DVR
				continue;
			}

			if (array_key_exists($this->hdhrkey_storageURL,$hdhr)) {
				// this is a record engine!
				$this->storageURL = $hdhr[$this->hdhrkey_storageURL];
				continue;
			}
			$hdhr_info_json = file_get_contents($hdhr[$this->hdhrkey_discoverURL]);
			$hdhr_info = json_decode($hdhr_info_json, true);
			$hdhr_lineup_json = file_get_contents($hdhr[$this->hdhrkey_lineupURL]);
			$hdhr_lineup = json_decode($hdhr_lineup_json, true);
		
			if (array_key_exists($this->hdhrkey_tuners,$hdhr_info)) {
				$this->hdhrlist[] = array( $this->hdhrkey_devID => $hdhr[$this->hdhrkey_devID],
											$this->hdhrkey_modelNum => $hdhr_info[$this->hdhrkey_modelNum],
											$this->hdhrlist_key_channelcount => count($hdhr_lineup),
											$this->hdhrkey_baseURL => $hdhr_base,
											$this->hdhrkey_lineupURL => $hdhr[$this->hdhrkey_lineupURL],
											$this->hdhrkey_modelName =>$hdhr_info[$this->hdhrkey_modelName],
											$this->hdhrkey_auth =>$hdhr_info[$this->hdhrkey_auth],
											$this->hdhrkey_fwVer => $hdhr_info[$this->hdhrkey_fwVer],
											$this->hdhrkey_tuners => $hdhr_info[$this->hdhrkey_tuners],
											$this->hdhrkey_fwName => $hdhr_info[$this->hdhrkey_fwName]);
{'fraction_non_alphanumeric': 0.15254237288135594, 'fraction_numerical': 0.0011175265412553548, 'mean_word_length': 4.413306451612903, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 82, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4530047', 'n_tokens_mistral': 2362, 'n_tokens_neox': 2040, 'n_words': 303}