/** * Add an Album to the database or get its key if it exists * @param name str: the name of the album to add * @return int: the primary key added or found */ public function addAlbum($name) { //is this name already in the collection? $q = Doctrine_Query::create()->select('a.id')->from('Album a')->where('a.name = ?', $name); $result = $q->fetchOne(); if (is_object($result) && $result->id > 0) { $retId = $result->id; unset($q, $result); return (int) $retId; } else { $item = new Album(); $item->name = $name; if ($name == 'Unknown Album') { $item->has_art = 1; //there's no point scanning an unknown album for art } $item->scan_id = 1; $item->save(); $id = $item->getId(); $item->free(); unset($item, $q, $result); return (int) $id; } }
/** * Return the count position of a Photo relative to the position in an Album * * @access public * @param Photo $photo Current photo * @param Album $album * @param array $options (Optional) Read documentation on parseOptions for details * @return int */ public function countPosition(Photo $photo, Album $album, $options = null) { $this->resetQueryStrings(); $this->query_reset_lock = true; $this->query_where = "WHERE {$this->tableName}.id <= ? AND {$this->tableName}.albumId = ?"; $this->query_params = array($photo->getId(), $album->getId()); $this->query_select = "COUNT({$this->columns[0]}) AS count"; $result = $this->count($options); $this->query_reset_lock = false; return $result; }
public function run() { // first of all - try to guess if this dir should be // treated as an album or as a bunch of loose tracks // further this method is adding score to several attributes which will be migrated to production db-table $this->setHandleAsAlbum(); #print_r($this->r); cliLog("handleAsAlbumScore " . $this->handleAsAlbumScore, 3, 'purple'); #die(); #if($this->tracks[0]['relativePath'] == 'newroot/crse002cd--Calibre-Musique_Concrete-2CD-CRSE002CD-2001-sour/101-calibre-deep_everytime.mp3') { #print_r($this->r); die(); #} // extract some attributes from tracks // those will be used for album stuff $mergedFromTracks = array('artist' => array(), 'genre' => array(), 'label' => array(), 'catalogNr' => array()); foreach (array_keys($mergedFromTracks) as $what) { foreach ($this->tracks as $idx => $rawTagData) { $mergedFromTracks[$what][] = $this->getMostScored($idx, $what); } $mergedFromTracks[$what][] = $this->getMostScored('album', $what); $mergedFromTracks[$what] = join(',', array_unique($mergedFromTracks[$what])); } $albumArtists = count(trimExplode(",", $mergedFromTracks['artist'])) > 3 ? 'Various Artists' : $mergedFromTracks['artist']; $a = new Album(); $a->setArtistId(join(",", Artist::getIdsByString($albumArtists))); $a->setGenreId(join(",", Genre::getIdsByString($mergedFromTracks['genre']))); #$a->setLabelId(join(",", Label::getIdsByString($mergedFromTracks['label']))); $a->setCatalogNr($this->mostScored['album']['catalogNr']); $a->setRelativePath($this->getRelativeDirectoryPath()); $a->setRelativePathHash($this->getRelativeDirectoryPathHash()); $a->setAdded($this->getDirectoryMtime()); $a->setFilemtime($this->getDirectoryMtime()); $a->setTitle($this->mostScored['album']['title']); $a->setYear($this->mostScored['album']['year']); $a->setIsJumble($this->handleAsAlbum === TRUE ? 0 : 1); $a->setTrackCount(count($this->tracks)); #print_r($a); die(); $a->update(); $albumId = $a->getId(); // add the whole bunch of valid and indvalid attributes to albumindex table $this->updateAlbumIndex($albumId); foreach ($this->tracks as $idx => $rawTagData) { $t = $this->migrateNonGuessableData($rawTagData); $t->setArtistId($this->mostScored[$idx]['artist']); // currently the string insted of an artistId $t->setTitle($this->mostScored[$idx]['title']); $t->setFeaturedArtistsAndRemixers(); # setFeaturedArtistsAndRemixers() is processing: # $t->setArtistId(); # $t->setFeaturingId(); # $t->setRemixerId(); $t->setGenreId(join(",", Genre::getIdsByString($this->getMostScored($idx, 'genre')))); $t->setLabelId(join(",", Label::getIdsByString($this->getMostScored($idx, 'label')))); $t->setCatalogNr($this->mostScored[$idx]['catalogNr']); $t->setDisc($this->mostScored[$idx]['disc']); $t->setNumber($this->mostScored[$idx]['number']); $t->setComment($this->mostScored[$idx]['comment']); $t->setYear($this->mostScored[$idx]['year']); $t->setAlbumId($albumId); // make sure to use identical ids in table:rawtagdata and table:track \Slimpd\Track::ensureRecordIdExists($t->getId()); $t->update(); // make sure extracted images will be referenced to an album \Slimpd\Bitmap::addAlbumIdToTrackId($t->getId(), $albumId); # // add the whole bunch of valid and indvalid attributes to trackindex table $this->updateTrackIndex($t->getId(), $idx); } unset($this->r['album']); if ($this->handleAsAlbum === TRUE) { // try to guess if all tracks of this album has obviously invalid fixable attributes } return; print_r($this->r); #die(); }
$log->add("ERROR saving artist"); } } } // ************************* // ************************* // OBTENGO DATOS DEL ALBUM $log->add("getting album id..."); if ($artistId != NULL) { $album = new Album("brasil"); $log->add("searching db for icpn=" . $track->getIcpn()); $album->loadFromIcpn($dbc, $track->getIcpn()); // veo si ya esta ingresado en la db if ($album->getMaches() == "1") { // ya esta ingresado, obtengo id $albumId = $album->getId(); $log->add("found album={$albumId}"); } else { $log->add("album not found"); $log->add("fetching album info for icpn=" . $track->getIcpn()); $album->setArtistId($artistId); $album->fetchXML($track->getIcpn(), $log); $savedAlbum = $album->save($dbc, "albums"); if ($savedAlbum === TRUE) { $albumId = $album->getId(); } else { $albumId = NULL; $log->add("ERROR saving album"); } } }
public function getNextAlbum(Album $album, $myMemberId) { $q = $this->createQuery()->andWhere('member_id = ?', $album->getMemberId())->andWhere('id > ?', $album->getId())->orderBy('id ASC'); $this->addPublicFlagQuery($q, $this->getPublicFlagByMemberId($album->getMemberId(), $myMemberId)); return $q->fetchOne(); }
/** * Picks from database albums with same album artist. * Used in /album/templates/showSuccess * * @param Album $album ex: Gone in 60 seconds * @return Array(Album) */ public static function getOtherAlbums($album) { $q = Doctrine_Query::create()->select('DISTINCT a.id')->from('Album a')->where('a.album_artist = ?', $album->getAlbumArtist())->andwhere('a.id != ?', $album->getId())->orderBy('a.title ASC'); return $q->execute(); }
/** * Load all instances of Album entities from the database except for the album passed. * Exclusion is based on album id * * @access public * @param Album $album * @param array $options (Optional) Read documentation on parseOptions for details * @return array */ public function allExclude(Album $album, $options = null) { $this->resetQueryStrings(); $this->query_reset_lock = true; $this->query_where = "WHERE " . $this->getTableName() . ".id != ?"; $this->query_params = array($album->getId()); $result_array = $this->all($options); $this->query_reset_lock = false; return $result_array; }
/** * Ensure the album cache ($this->albums) is filled with albums of this library */ protected function ensureAlbums() { if (is_null($this->albums)) { $this->albums = array(); foreach ($this->data['List of Albums'] as &$albumData) { $album = new Album($this, $albumData); $this->albums[$album->getId()] = $album; } } }
public static function storeArtworkFromAPI($album, $size = "mega") { $db = $_SESSION['db']; $album = new Album($album); $artist = $album->getMainArtist(); $artist_name = strtr($artist->getName(), array('.' => '', ',' => '')); $album_name = strtr($album->getName(), array('.' => '', ',' => '')); if (file_put_contents("img/albums/" . $album->getId() . ".jpg", file_get_contents(LastFMArtwork::getArtwork(utf8_encode($artist_name), utf8_encode($album_name), true, $size)))) { return true; } return false; }
public function selectFeaturedImageForAlbumQuery(Album $album) { return "select images.* from images join albums on images.id=albums.featuredimageid where albums.id={$album->getId()} limit 1"; }