Skip to content

Commit

Permalink
Find covers for albums without and some fixes
Browse files Browse the repository at this point in the history
 * find covers for albums without cover
 * add album art to playerbar
 * fix clean up cron job
  • Loading branch information
MorrisJobke committed Sep 23, 2013
1 parent 8bd3032 commit d520f74
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 14 deletions.
29 changes: 28 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
v0.1.5-alpha 2013-09-24

* use images in album folders as album art
* first uploaded image to a folder is used as album art
* addition and deletion of covers is detected
* alphabet navigation bar to the left
* highlight available letters (of the artists)
* use flash 8 for fallback player
* fix ogg playback
* play the clicked song of an album and not the first song of the album - fixes #83
* limit metadatascan to audio files
* Adds clean up background job
* find covers for albums without cover
* remove tracks without files, albums without tracks and artists without albums and tracks
* AngularJS 1.0.8
* Various fixes and improvements - especially PostgreSQL
* various fixes, also for PostgreSQL
* cast number to int
* use correct sql statement for checking for albums
* unit test for case when album is null
* move casting to appframework entity
* remove blank lines

Known bugs:
* does not scroll perfect
* non-dynamic creating of the navigation bar

v0.1.4-alpha 2013-09-05

* show track number in track list
Expand All @@ -13,7 +40,7 @@ v0.1.4-alpha 2013-09-05
* disable execution time for rescan
* realign playerbar content and adding whitespace (ref #80)

Known issues
Known bugs:
* clicking a song the first song of the album is played instead of the actual clicked song

v0.1.3-alpha 2013-09-04
Expand Down
1 change: 1 addition & 0 deletions appinfo/database.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<type>integer</type>
<notnull>false</notnull>
<length>4</length>
<default></default>
</field>
</declaration>
</table>
Expand Down
12 changes: 12 additions & 0 deletions businesslayer/albumbusinesslayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,17 @@ public function updateCover($coverFileId, $parentFolderId){
*/
public function removeCover($coverFileId){
$this->mapper->removeCover($coverFileId);
// find new cover
$this->findCovers();
}

/**
* try to find covers from albums without covers
*/
public function findCovers(){
$albums = $this->mapper->getAlbumsWithoutCover();
foreach ($albums as $album) {
$this->mapper->findAlbumCover($album['albumId'], $album['parentFolderId']);
}
}
}
8 changes: 7 additions & 1 deletion css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
cursor: pointer;
}

.albumart {
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}

.album-area > .albumart, .album-area > img {
float: left;
width: 190px;
Expand Down Expand Up @@ -138,7 +144,7 @@
.alphabet-navigation a {
display: block;
font-weight: bold;
line-height: 230%;
line-height: 210%;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=10)";
filter: alpha(opacity = 10);
opacity: .1;
Expand Down
30 changes: 28 additions & 2 deletions db/albummapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function deleteById($albumIds){
public function updateCover($coverFileId, $parentFolderId){
$sql = 'UPDATE `*PREFIX*music_albums`
SET `cover_file_id` = ?
WHERE `cover_file_id` = 0 AND `id` IN (
WHERE `cover_file_id` IS NULL AND `id` IN (
SELECT DISTINCT `tracks`.`album_id`
FROM `*PREFIX*music_tracks` `tracks`
JOIN `*PREFIX*filecache` `files` ON `tracks`.`file_id` = `files`.`fileid`
Expand All @@ -137,9 +137,35 @@ public function updateCover($coverFileId, $parentFolderId){

public function removeCover($coverFileId){
$sql = 'UPDATE `*PREFIX*music_albums`
SET `cover_file_id` = 0
SET `cover_file_id` = NULL
WHERE `cover_file_id` = ?;';
$params = array($coverFileId);
$this->execute($sql, $params);
}

public function getAlbumsWithoutCover(){
$sql = 'SELECT DISTINCT `albums`.`id`, `files`.`parent`
FROM `*PREFIX*music_albums` `albums`
JOIN `*PREFIX*music_tracks` `tracks` ON `albums`.`id` = `tracks`.`album_id`
JOIN `*PREFIX*filecache` `files` ON `tracks`.`file_id` = `files`.`fileid`
WHERE `albums`.`cover_file_id` IS NULL;';
$result = $this->execute($sql);
$return = Array();
while($row = $result->fetchRow()){
array_push($return, Array('albumId' => $row['id'], 'parentFolderId' => $row['parent']));
}
return $return;
}

public function findAlbumCover($albumId, $parentFolderId){
$sql = 'UPDATE `*PREFIX*music_albums`
SET `cover_file_id` = (
SELECT `fileid`
FROM `*PREFIX*filecache`
JOIN `*PREFIX*mimetypes` ON `*PREFIX*mimetypes`.`id` = `*PREFIX*filecache`.`mimetype`
WHERE `parent` = ? AND `*PREFIX*mimetypes`.`mimetype` LIKE "image%" LIMIT 1
) WHERE `id` = ?;';
$params = array($parentFolderId, $albumId);
$this->execute($sql, $params);
}
}
10 changes: 9 additions & 1 deletion js/app/directives/albumart.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,17 @@ angular.module('Music').directive('albumart', function() {
return function(scope, element, attrs, ctrl) {
attrs.$observe('albumart',function() {
if(attrs.cover) {
// remove placeholder stuff
element.html('');
element.css('background-color', '');
// add background image
element.css('-ms-filter', '"progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + attrs.cover + '\', sizingMethod=\'scale\')"');
element.css('background-image', 'url(' + attrs.cover + ')');
element.css('background-size', 'contain');
} else {
// remove background image
element.css('-ms-filter', '');
element.css('background-image', '');
// add placeholder stuff
element.placeholder(attrs.albumart);
}
});
Expand Down
10 changes: 9 additions & 1 deletion js/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,17 @@ angular.module('Music').directive('albumart', function() {
return function(scope, element, attrs, ctrl) {
attrs.$observe('albumart',function() {
if(attrs.cover) {
// remove placeholder stuff
element.html('');
element.css('background-color', '');
// add background image
element.css('-ms-filter', '"progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + attrs.cover + '\', sizingMethod=\'scale\')"');
element.css('background-image', 'url(' + attrs.cover + ')');
element.css('background-size', 'contain');
} else {
// remove background image
element.css('-ms-filter', '');
element.css('background-image', '');
// add placeholder stuff
element.placeholder(attrs.albumart);
}
});
Expand Down
2 changes: 1 addition & 1 deletion templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<img ng-click="next()" class="control small svg" alt="{{ trans('Next') }}" src="{{ image_path('actions/play-next.svg', 'core') }}" />
</div>

<div ng-show="currentAlbum" class="albumart" albumart="[[ currentAlbum.name ]]" title="[[ currentAlbum.name ]]" ></div>
<div ng-show="currentAlbum" class="albumart" cover="[[ currentAlbum.cover ]]" albumart="[[ currentAlbum.name ]]" title="[[ currentAlbum.name ]]" ></div>

<div class="song-info">
<span class="title" title="[[ currentTrack.title ]]">[[ currentTrack.title ]]</span><br />
Expand Down
22 changes: 15 additions & 7 deletions utility/scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ public function rescan() {
foreach ($music as $file) {
$this->update($file['path']);
}
// find album covers
$this->albumBusinessLayer->findCovers();

// reset execution time limit
set_time_limit($executionTime);
}
Expand All @@ -214,12 +217,17 @@ public function rescan() {
* Removes orphaned data from the database
*/
public function cleanUp() {
$sql =
'DELETE FROM *PREFIX*music_tracks WHERE file_id NOT IN (SELECT fileid FROM *PREFIX*filecache);'.
'DELETE FROM *PREFIX*music_albums WHERE id NOT IN (SELECT album_id FROM *PREFIX*music_tracks GROUP BY album_id);'.
'DELETE FROM *PREFIX*music_album_artists WHERE album_id NOT IN (SELECT id FROM *PREFIX*music_albums GROUP BY id);'.
'DELETE FROM *PREFIX*music_artists WHERE id NOT IN (SELECT artist_id FROM *PREFIX*music_album_artists GROUP BY artist_id);';
$query = $this->api->prepareQuery($sql);
$query->execute(array());
$sqls = array(
'UPDATE `*PREFIX*music_albums` SET `cover_file_id` = NULL WHERE `cover_file_id` IS NOT NULL AND `cover_file_id` NOT IN (SELECT `fileid` FROM `*PREFIX*filecache`);',
'DELETE FROM `*PREFIX*music_tracks` WHERE `file_id` NOT IN (SELECT `fileid` FROM `*PREFIX*filecache`);',
'DELETE FROM `*PREFIX*music_albums` WHERE `id` NOT IN (SELECT `album_id` FROM `*PREFIX*music_tracks` GROUP BY `album_id`);',
'DELETE FROM `*PREFIX*music_album_artists` WHERE `album_id` NOT IN (SELECT `id` FROM `*PREFIX*music_albums` GROUP BY `id`);',
'DELETE FROM `*PREFIX*music_artists` WHERE `id` NOT IN (SELECT `artist_id` FROM `*PREFIX*music_album_artists` GROUP BY `artist_id`);'
);

foreach ($sqls as $sql) {
$query = $this->api->prepareQuery($sql);
$query->execute();
}
}
}

0 comments on commit d520f74

Please sign in to comment.