Skip to content

Commit

Permalink
Added album format info on cover for albums from Tidal and HRA.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturSierzant committed Aug 25, 2020
1 parent ac26f13 commit ab9b248
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 26 deletions.
3 changes: 2 additions & 1 deletion about.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ function about() {
<td></td>
<td>
<ul style="padding-left: 1em;">
<li> added support for HighResAudio</li>
<li> added support for HighResAudio (thanks to <a target="_blank" href="https://github.com/marcbth">marcbth</a>)</li>
<li> added badge with audio format info on album cover (thanks to <a target="_blank" href="https://github.com/paradix">paradix</a>)</li>
<li> fixed bugs</li>
</ul>
<br>
Expand Down
6 changes: 5 additions & 1 deletion ajax-last-played.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@
$albums['album_id'] = $a_id;
$tidal_cover = '';
if (isTidal($a_id)){
$query1 = mysqli_query($db, "SELECT album, cover, artist_alphabetic FROM tidal_album
$query1 = mysqli_query($db, "SELECT album, cover, artist_alphabetic, audio_quality FROM tidal_album
WHERE album_id='" . getTidalId($a_id) . "' LIMIT 1");
$a = mysqli_fetch_assoc ( $query1 );
$albums['album'] = $a['album'];
$tidal_cover = $a['cover'];
$albums['artist_alphabetic'] = $a['artist_alphabetic'];
$albums['audio_quality'] = $a['audio_quality'];
}
elseif (isHra($a_id)){
if (!$hra_session) {
Expand All @@ -68,6 +69,9 @@
$albums['album'] = $results['data']['results']['title'];
$albums['cover'] = 'https://' . $results['data']['results']['cover']['master']['file_url'];
$albums['artist_alphabetic'] = $results['data']['results']['artist'];
if ($cfg['show_album_format']) {
$albums['audio_quality'] = $results['data']['results']['tracks'][0]['format'];
}
}
else {
$albums = null;
Expand Down
3 changes: 3 additions & 0 deletions image.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ function image($image_id, $quality, $track_id) {
header('Cache-Control: max-age=31536000');
if ($quality == 'hq') {
//$data = file_get_contents("http://images.osl.wimpmusic.com/im/im?w=1000&h=1000&albumid=" . $album_id);

/* $stream = fopen($t->albumCoverToURL($pic,'hq'), 'r');
$data = stream_get_contents($t->albumCoverToURL($pic,'hq')); */
$data = file_get_contents($t->albumCoverToURL($pic,'hq'));
}
else {
Expand Down
20 changes: 11 additions & 9 deletions include/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@
$cfg['hra_lang'] = "en";




// +------------------------------------------------------------------------+
// | Album format badge settings |
// +------------------------------------------------------------------------+
// | Show album format badge on album cover |
// +------------------------------------------------------------------------+

$cfg['show_album_format'] = false;


// +------------------- END OF NEW IN O!MPD 1.07 ---------------------------+


Expand Down Expand Up @@ -667,15 +678,6 @@



// +------------------------------------------------------------------------+
// | Album format badge settings |
// +------------------------------------------------------------------------+
// | Show album format badge on album cover |
// +------------------------------------------------------------------------+

$cfg['show_album_format'] = false;



// +------------------------------------------------------------------------+
// | Binary directory |
Expand Down
2 changes: 1 addition & 1 deletion include/initialize.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
define('NJB_START_TIME', microtime(true));

define('NJB_VERSION', '1.06');
define('NJB_DATABASE_VERSION', 48);
define('NJB_DATABASE_VERSION', 49);
define('NJB_IMAGE_SIZE', 300);
define('NJB_IMAGE_QUALITY', 85);
define('NJB_WINDOWS', strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
Expand Down
79 changes: 70 additions & 9 deletions include/library.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ function draw_tile($size,$album,$multidisc = '', $retType = "echo",$tidal_cover
$album_info = $rel_file = mysqli_fetch_assoc($query);
$res .= ' <div class="tile_format">' . html(calculateAlbumFormat($album_info)) . '</div>';
}
elseif ($cfg['show_album_format'] == true && isTidal($album['album_id'])) {
if ($aq = calculateAlbumFormat($album)) {
$res .= ' <div class="tile_format">' . html($aq) . '</div>';
}
}
elseif ($cfg['show_album_format'] == true && isHra($album['album_id'])) {
if ($aq = calculateAlbumFormat($album)) {
$res .= ' <div class="tile_format">' . html($aq) . '</div>';
}
}
//$res .= ' <div id="tile_title" class="tile_info">';
$res .= ' <div class="tile_info" style="cursor: initial;">';
$res .= ' <div class="tile_title">' . html($album['album']) . '</div>';
Expand Down Expand Up @@ -543,6 +553,7 @@ function showAlbumsFromTidal($artist, $size, $ajax = true, $tidalArtistId) {
if ($results['items'] || $resultsEPs['items']) {
$sql = "DELETE FROM tidal_album WHERE artist_id = '" . mysqli_real_escape_string($db,$tidalArtistId) . "'";
mysqli_query($db, $sql);

for($i=0;$i<2;$i++) {
if ($i == 0) {
$albums = $results['items'];
Expand All @@ -568,16 +579,18 @@ function showAlbumsFromTidal($artist, $size, $ajax = true, $tidalArtistId) {
}
if ($artists == '') $artists = $album["artist"]["name"];


$sql = "REPLACE INTO tidal_album
(album_id, artist, artist_alphabetic, artist_id, album, album_date, genre_id, discs, seconds, last_update_time, cover, type)
(album_id, artist, artist_alphabetic, artist_id, album, album_date, genre_id, discs, seconds, last_update_time, cover, type, audio_quality)
VALUES (
'" . $album["id"] . "', '" . mysqli_real_escape_string($db,$artists) . "', '" . mysqli_real_escape_string($db,$artists) . "', '" . $album["artist"]["id"] . "', '" . mysqli_real_escape_string($db,$album["title"]) . "', '" . $album["releaseDate"] . "', '', 1, '" . $album["duration"] . "','" . time() . "', '" .$album['cover'] . "','" . $album['type'] . "')";
'" . $album["id"] . "', '" . mysqli_real_escape_string($db,$artists) . "', '" . mysqli_real_escape_string($db,$artists) . "', '" . $album["artist"]["id"] . "', '" . mysqli_real_escape_string($db,$album["title"]) . "', '" . $album["releaseDate"] . "', '', 1, '" . $album["duration"] . "','" . time() . "', '" . $album["cover"] . "','" . $album["type"] . "','" . $album["audioQuality"] . "')";

mysqli_query($db, $sql);

$tidalAlbum["album_id"] = 'tidal_' . $album["id"];
$tidalAlbum["album"] = $album["title"];
$tidalAlbum["artist_alphabetic"] = $artists;
$tidalAlbum["audio_quality"] = $album["audioQuality"];
draw_tile($size, $tidalAlbum);
}
}
Expand Down Expand Up @@ -638,12 +651,12 @@ function showAlbumsFromTidal($artist, $size, $ajax = true, $tidalArtistId) {
for ($j=0;$j<2;$j++){
if ($j==0) {
$filter_query1 = 'WHERE type="album" AND ' . $filter_query;
$sql = "SELECT album_id, album, artist, album_date FROM tidal_album " . $filter_query1;
$sql = "SELECT album_id, album, artist, album_date, audio_quality FROM tidal_album " . $filter_query1;
$query = mysqli_query($db,$sql);
}
else {
$filter_query1 = 'WHERE type != "album" AND ' . $filter_query;
$sql = "SELECT album_id, album, artist, album_date FROM tidal_album " . $filter_query1;
$sql = "SELECT album_id, album, artist, album_date, audio_quality FROM tidal_album " . $filter_query1;
$query = mysqli_query($db,$sql);
if (mysqli_num_rows($query) > 0) {
echo ('<h1>EPs and Singles</h1>');
Expand All @@ -655,6 +668,7 @@ function showAlbumsFromTidal($artist, $size, $ajax = true, $tidalArtistId) {
$tidalAlbum["album_id"] = 'tidal_' . $album["album_id"];
$tidalAlbum["album"] = $album["album"];
$tidalAlbum["artist_alphabetic"] = $album["artist"];
$tidalAlbum["audio_quality"] = $album["audio_quality"];
draw_tile($size, $tidalAlbum);
}
}
Expand Down Expand Up @@ -703,9 +717,9 @@ function getAlbumFromTidal($album_id) {
if ($artists == '') $artists = $results["artist"]["name"];

$sql = "REPLACE INTO tidal_album
(album_id, artist, artist_alphabetic, artist_id, album, album_date, genre_id, discs, seconds, last_update_time, cover, type)
(album_id, artist, artist_alphabetic, artist_id, album, album_date, genre_id, discs, seconds, last_update_time, cover, type, audio_quality)
VALUES (
'" . $results["id"] . "', '" . mysqli_real_escape_string($db,$artists) . "', '" . mysqli_real_escape_string($db,$artists) . "', '" . $results["artist"]["id"] . "', '" . mysqli_real_escape_string($db,$results["title"]) . "', '" . $results["releaseDate"] . "', '', 1, '" . $results["duration"] . "','0','" . $results["cover"] . "','" . $results['type'] . "')";
'" . $results["id"] . "', '" . mysqli_real_escape_string($db,$artists) . "', '" . mysqli_real_escape_string($db,$artists) . "', '" . $results["artist"]["id"] . "', '" . mysqli_real_escape_string($db,$results["title"]) . "', '" . $results["releaseDate"] . "', '', 1, '" . $results["duration"] . "','0','" . $results["cover"] . "','" . $results['type'] . "','" . $results['audioQuality'] . "')";

mysqli_query($db, $sql);
$data['results'] = 1;
Expand Down Expand Up @@ -963,6 +977,7 @@ function showAllFromTidal($searchStr, $size) {
$album['album_id'] = 'tidal_' . $art['id'];
$album['artist_alphabetic'] = $art['artists'][0]['name'];
$album['album'] = $art['title'];
$album['audio_quality'] = $art['audioQuality'];
$albumsList .= draw_tile($size, $album, '', 'string',$art['cover']);
}
$albumsList .= '</table>';
Expand Down Expand Up @@ -1202,6 +1217,7 @@ function showArtistsFromHRA($searchStr, $size) {
$data = array();

$h = new HraAPI;
if (NJB_WINDOWS) $h->fixSSLcertificate();
$results = $h->searchArtists($value);
if (!$results['data']) {
$data['artists_results'] = 0;
Expand Down Expand Up @@ -1230,6 +1246,16 @@ function showAlbumsFromHRA($searchStr, $size) {
$data = array();

$h = new HraAPI;
$h->username = $cfg["hra_username"];
$h->password = $cfg["hra_password"];
if (NJB_WINDOWS) $h->fixSSLcertificate();
$conn = $h->connect();
if (!$conn){
$data['return'] = $conn["return"];
$data['response'] = $conn["error"];
echo safe_json_encode($data);
return;
}
$results = $h->searchAlbums($value);
if (!$results['data']) {
$data['albums_results'] = 0;
Expand All @@ -1243,6 +1269,10 @@ function showAlbumsFromHRA($searchStr, $size) {
$album['artist_alphabetic'] = $art['artist'];
$album['album'] = $art['title'];
$album['cover'] = $art['cover'];
if ($cfg['show_album_format']) {
$aq = $h->getAlbum($art['albumId']);
$album['audio_quality'] = $aq['data']['results']['tracks'][0]['format'];
}
$albumsList .= draw_tile($size, $album, '', 'string');
}
$albumsList .= '</table>';
Expand All @@ -1264,6 +1294,17 @@ function showArtistAlbumsFromHRA($searchStr, $size) {
$data = array();

$h = new HraAPI;
$h->username = $cfg["hra_username"];
$h->password = $cfg["hra_password"];
if (NJB_WINDOWS) $h->fixSSLcertificate();
$conn = $h->connect();
if (!$conn){
$data['return'] = $conn["return"];
$data['response'] = $conn["error"];
echo safe_json_encode($data);
return;
}

$results = $h->getArtistAlbums($value);
if (!$results['data']) {
$data['albums_results'] = 0;
Expand All @@ -1276,6 +1317,10 @@ function showArtistAlbumsFromHRA($searchStr, $size) {
$album['artist_alphabetic'] = $art['artist'];
$album['album'] = $art['title'];
$album['cover'] = $art['cover'];
if ($cfg['show_album_format']) {
$aq = $h->getAlbum($art['albumId']);
$album['audio_quality'] = $aq['data']['results']['tracks'][0]['format'];
}
$albumsList .= draw_tile($size, $album, '', 'string');
}
$albumsList .= '</table>';
Expand All @@ -1297,7 +1342,7 @@ function getTracksFromHraAlbum($album_id, $order = '') {
$h = new HraAPI;
$h->username = $cfg["hra_username"];
$h->password = $cfg["hra_password"];
if (NJB_WINDOWS) $t->fixSSLcertificate();
if (NJB_WINDOWS) $h->fixSSLcertificate();
$conn = $h->connect();
if ($conn === true){
$tracks = $h->getAlbumTracks($album_id);
Expand Down Expand Up @@ -1357,7 +1402,7 @@ function getHRAMPDUrl($track_id){
$h = new HraAPI;
$h->username = $cfg["hra_username"];
$h->password = $cfg["hra_password"];
if (NJB_WINDOWS) $t->fixSSLcertificate();
if (NJB_WINDOWS) $h->fixSSLcertificate();
$conn = $h->connect();
if ($conn === true){
$results = $h->getTrack($track_id);
Expand Down Expand Up @@ -3064,7 +3109,23 @@ function isInFavorite($track_id, $favorite_id) {
// | Calculate album format |
// +------------------------------------------------------------------------+
function calculateAlbumFormat($album_information) {
if (strpos($album_information['audio_profile'],'Lossless') === false) {
if ($album_information['audio_quality']) {
if (isTidal($album_information['album_id'])) {
switch (strtolower($album_information['audio_quality'])){
case "high":
case "lossless":
return "CD";
case "hi_res":
return "Master";
default:
return $album_information['audio_quality'];
}
}
elseif (isHra($album_information['album_id'])) {
return "24/" . round($album_information['audio_quality'],0);
}
}
elseif (strpos($album_information['audio_profile'],'Lossless') === false) {
return $album_information['audio_dataformat'];
}
elseif (stripos($album_information['audio_encoder'],'mqa') !== false) {
Expand Down
9 changes: 7 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2176,12 +2176,13 @@ function viewRecentlyPlayed() {
$albums['album_id'] = $a_id;
$tidal_cover = '';
if (isTidal($a_id)){
$query1 = mysqli_query($db, "SELECT album, cover, artist_alphabetic FROM tidal_album
$query1 = mysqli_query($db, "SELECT album, cover, artist_alphabetic, audio_quality FROM tidal_album
WHERE album_id='" . getTidalId($a_id) . "' LIMIT 1");
$a = mysqli_fetch_assoc ( $query1 );
$albums['album'] = $a['album'];
$tidal_cover = $a['cover'];
$albums['artist_alphabetic'] = $a['artist_alphabetic'];
$albums['audio_quality'] = $a['audio_quality'];
}
elseif (isHra($a_id)){
if (!$hra_session) {
Expand All @@ -2198,6 +2199,9 @@ function viewRecentlyPlayed() {
$albums['album'] = $results['data']['results']['title'];
$albums['cover'] = 'https://' . $results['data']['results']['cover']['master']['file_url'];
$albums['artist_alphabetic'] = $results['data']['results']['artist'];
if ($cfg['show_album_format']) {
$albums['audio_quality'] = $results['data']['results']['tracks'][0]['format'];
}
}
else {
$albums = null;
Expand All @@ -2222,7 +2226,8 @@ function viewRecentlyPlayed() {
'image_id' => $albums['image_id'],
'album' => $albums['album'],
'artist_alphabetic' => $albums['artist_alphabetic'],
'cover' => $albums['cover']
'cover' => $albums['cover'],
'audio_quality' => $albums['audio_quality']
);
draw_tile($size,$album_multidisc_1[$a_id],'allDiscs', 'echo', $tidal_cover);
}
Expand Down
4 changes: 2 additions & 2 deletions search.php
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ function tidal_albums(){
?>
<div>
<h1 onclick='toggleSearchResults("TIAl");' class="pointer" id="tidalAlbums"><i id="iconSearchResultsTIAl" class="fa fa-chevron-circle-down icon-anchor"></i> Albums</h1>
<div id="searchResultsTIAl">
<div id="searchResultsTIAl" class="albums_container">
<span id="albumsLoadingIndicator">
<i class="fa fa-cog fa-spin icon-small"></i> Loading albums list...
</span>
Expand Down Expand Up @@ -1456,7 +1456,7 @@ function hra_albums(){
?>
<div>
<h1 onclick='toggleSearchResults("HRAAl");' class="pointer" id="hraAlbums"><i id="iconSearchResultsHRAAl" class="fa fa-chevron-circle-down icon-anchor"></i> Albums</h1>
<div id="searchResultsHRAAl">
<div id="searchResultsHRAAl" class="albums_container">
<span id="hraAlbumsLoadingIndicator">
<i class="fa fa-cog fa-spin icon-small"></i> Loading albums list...
</span>
Expand Down
17 changes: 17 additions & 0 deletions sql/incremental_upgrade_49.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- --------------------------------------------------------
--
-- Zmiany w tabeli `tidal_album`
--

ALTER TABLE `tidal_album` ADD COLUMN `audio_quality` VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '';


-- --------------------------------------------------------

--
-- Database version
--

UPDATE `server` SET `value` = '' WHERE `name` = 'latest_version' LIMIT 1;
UPDATE `server` SET `value` = '0' WHERE `name` = 'latest_version_idle_time' LIMIT 1;
UPDATE `server` SET `value` = '49' WHERE `name` = 'database_version' LIMIT 1;
3 changes: 2 additions & 1 deletion sql/ompd_48.sql → sql/ompd_49.sql
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ CREATE TABLE IF NOT EXISTS `tidal_album` (
`last_update_time` int(10) unsigned NOT NULL DEFAULT '0',
`cover` varchar(255) NOT NULL DEFAULT '',
`type` tinytext NOT NULL,
`audio_quality` VARCHAR(20) NOT NULL DEFAULT '',
UNIQUE KEY `album_id` (`album_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Expand Down Expand Up @@ -711,7 +712,7 @@ INSERT INTO `user` VALUES ('anonymous', 'adf8efe68157cf37503f86d602bec6d593750c3
-- Default server
--

INSERT INTO `server` VALUES ('database_version', '48');
INSERT INTO `server` VALUES ('database_version', '49');
INSERT INTO `server` VALUES ('escape_char_hash', 'd41d8cd98f00b204e9800998ecf8427e');
INSERT INTO `server` VALUES ('getid3_hash', 'd41d8cd98f00b204e9800998ecf8427e');
INSERT INTO `server` VALUES ('image_quality', '0');
Expand Down

0 comments on commit ab9b248

Please sign in to comment.