<commit_before><?php
namespace Slimpd;

class Discogsitem extends AbstractModel
{
	protected $id;
	protected $tstamp;
	protected $type;
	protected $extid;
	protected $response;
	public $trackstrings;
	public $albumAttributes;
	
	public static $tableName = 'discogsapicache';
	
	public function __construct($releaseId = FALSE) {
		if($releaseId === FALSE) {
			return $this;
		}
		if(is_numeric($releaseId) === FALSE || $releaseId < 1) {
			\Slim\Slim::getInstance()->flashNow('error', \Slim\Slim::getInstance()->ll->str('error.discogsid'));
			return;
		}
		$this->setType('release');
		$this->setExtid((int)$releaseId);
		
		$this->fetch();
		
		#var_dump($this);
		#die('nutte');
		$this->extractTracknames();
		$this->extractAlbumAttributes();
		
		return $this;
	}
	
	public function extractTracknames() {
		$data = $this->getResponse(TRUE);
		$counter = 0;
		foreach($data['tracklist'] as $t) {
			$counter++;
			$trackindex = $this->getExtid() . '-' . $counter; 
			$trackstring = $t['position'] . '. ';
			$trackArtists = (isset($t['artists']) === TRUE) ? $t['artists'] : $data['artists'];
			foreach($trackArtists as $a) {
				$trackstring .= $a['name'];
			}
			
			$trackstring .= ' - ' . $t['title'];#
			if(strlen($t['duration']) > 0) {
				$trackstring .= ' [' . $t['duration'] . ']';
			}
			$this->trackstrings[$trackindex] = $trackstring;
		}
	}
	
	public function extractAlbumAttributes() {
		$data = $this->getResponse(TRUE);
		#echo "<pre>" . print_r($data,1); die();
		$this->albumAttributes['artist'] = '';
		foreach($data['artists'] as $a) {
			$this->albumAttributes['artist'] .= $a['name'] . ",";
		}
		
		$data['styles'] = (isset($data['styles']) === TRUE) ? $data['styles'] : array();
		$this->albumAttributes['artist'] = substr($this->albumAttributes['artist'],0,-1);
		$this->albumAttributes['title'] = $data['title'];
		$this->albumAttributes['genre'] = join(",", array_merge($data['genres'], $data['styles']));
		$this->albumAttributes['year'] = $data['released'];
		
		// only take the first label/CatNo - no matter how many are provided by discogs
		if(isset($data['labels'][0]) === TRUE) {
			$this->albumAttributes['label'] = $data['labels'][0]['name'];
			$this->albumAttributes['catalogNr'] = $data['labels'][0]['catno'];
		}
		return;
		
		echo "<pre>" . print_r($data,1); die();
		$counter = 0;
		foreach($data['tracklist'] as $t) {
			$counter++;
			$trackindex = $this->getExtid() . '-' . $counter; 
			$trackstring = $t['position'] . '. ';
			$trackArtists = (isset($t['artists']) === TRUE) ? $t['artists'] : $data['artists'];
			foreach($trackArtists as $a) {<commit_msg>variable check in discogs api response<commit_after><?php
namespace Slimpd;

class Discogsitem extends AbstractModel
{
	protected $id;
	protected $tstamp;
	protected $type;
	protected $extid;
	protected $response;
	public $trackstrings;
	public $albumAttributes;
	
	public static $tableName = 'discogsapicache';
	
	public function __construct($releaseId = FALSE) {
		if($releaseId === FALSE) {
			return $this;
		}
		if(is_numeric($releaseId) === FALSE || $releaseId < 1) {
			\Slim\Slim::getInstance()->flashNow('error', \Slim\Slim::getInstance()->ll->str('error.discogsid'));
			return;
		}
		$this->setType('release');
		$this->setExtid((int)$releaseId);
		
		$this->fetch();
		
		#var_dump($this);
		#die('nutte');
		$this->extractTracknames();
		$this->extractAlbumAttributes();
		
		return $this;
	}
	
	public function extractTracknames() {
		$data = $this->getResponse(TRUE);
		$counter = 0;
		foreach($data['tracklist'] as $t) {
			$counter++;
			$trackindex = $this->getExtid() . '-' . $counter; 
			$trackstring = $t['position'] . '. ';
			$trackArtists = (isset($t['artists']) === TRUE) ? $t['artists'] : $data['artists'];
			foreach($trackArtists as $a) {
				$trackstring .= $a['name'];
			}
			
			$trackstring .= ' - ' . $t['title'];#
			if(strlen($t['duration']) > 0) {
				$trackstring .= ' [' . $t['duration'] . ']';
			}
			$this->trackstrings[$trackindex] = $trackstring;
		}
	}
	
	public function extractAlbumAttributes() {
		$data = $this->getResponse(TRUE);
		#echo "<pre>" . print_r($data,1); die();
		$this->albumAttributes['artist'] = '';
		foreach($data['artists'] as $a) {
			$this->albumAttributes['artist'] .= $a['name'] . ",";
		}
		
		$data['styles'] = (isset($data['styles']) === TRUE) ? $data['styles'] : array();
		$this->albumAttributes['artist'] = substr($this->albumAttributes['artist'],0,-1);
		$this->albumAttributes['title'] = isset($data['title']) ? $data['title'] : "";
		$this->albumAttributes['genre'] = join(",", array_merge($data['genres'], $data['styles']));
		$this->albumAttributes['year'] = isset($data['released']) ? $data['released'] : "";
		
		// only take the first label/CatNo - no matter how many are provided by discogs
		if(isset($data['labels'][0]) === TRUE) {
			$this->albumAttributes['label'] = $data['labels'][0]['name'];
			$this->albumAttributes['catalogNr'] = $data['labels'][0]['catno'];
		}
		return;
		
		echo "<pre>" . print_r($data,1); die();
		$counter = 0;
		foreach($data['tracklist'] as $t) {
			$counter++;
			$trackindex = $this->getExtid() . '-' . $counter; 
			$trackstring = $t['position'] . '. ';
			$trackArtists = (isset($t['artists']) === TRUE) ? $t['artists'] : $data['artists'];
			foreach($trackArtists as $a) {
{'fraction_non_alphanumeric': 0.23042168674698796, 'fraction_numerical': 0.004141566265060241, 'mean_word_length': 4.443647540983607, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 53, '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': '6856867', 'n_tokens_mistral': 2042, 'n_tokens_neox': 1816, 'n_words': 319}