Skip to content

Commit

Permalink
Fixed YT search.
Browse files Browse the repository at this point in the history
Fixed displaying Tidal albums in Recently played albums - day by day.
Fixed error when clicking Prev or Next when playback stopped.
Fixed displaying covers for album added before 'cover' field was added to 'tidal_album' table.
  • Loading branch information
ArturSierzant committed Jun 18, 2020
1 parent 36c4d63 commit 4433cdd
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 33 deletions.
39 changes: 26 additions & 13 deletions ajax-yt-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,38 @@
$results = array();
$search = $_GET['searchStr'];
$search = str_replace(" ", "+", $search);
$html = file_get_html("https://www.youtube.com/results?search_query=" . $search);
$html = new simple_html_dom();
$html -> load_file("https://www.youtube.com/results?search_query=" . $search);
//echo ($html);
//exit();
$i = 0;
$data['return'] = 0;

foreach($html->find('ol.item-section') as $ol){
foreach($ol->find('li') as $li) {
foreach($li->find('div.yt-lockup') as $d){
foreach($d->find('span.video-time') as $vt){
if($vt->innertext){
foreach($d->find('div.yt-lockup-content h3 a') as $a){
$results['items'][$i]['id'] = getYouTubeId($a->href);
$results['items'][$i]['title'] = $a->innertext;
$results['items'][$i]['url'] = $a->href;
$results['items'][$i]['time'] = $vt->innertext;
$i++;
for ($j=1;$j<=5;$j++) {
foreach($html->find('ol.item-section') as $ol){
foreach($ol->find('li') as $li) {
foreach($li->find('div.yt-lockup') as $d){
foreach($d->find('span.video-time') as $vt){
if($vt->innertext){
foreach($d->find('div.yt-lockup-content h3 a') as $a){
$results['items'][$i]['id'] = getYouTubeId($a->href);
$results['items'][$i]['title'] = $a->innertext;
$results['items'][$i]['url'] = $a->href;
$results['items'][$i]['time'] = $vt->innertext;
$i++;
}
}
}
}
}
}
}
if ($i==0) {
//try to load YT page up to 5 times because sometimes it returned 0 results
$j++;
$html -> load_file("https://www.youtube.com/results?search_query=" . $search);
}
else {
break;
}
}

Expand Down
13 changes: 12 additions & 1 deletion include/library.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,19 @@ function draw_tile($size,$album,$multidisc = '', $retType = "echo",$tidal_cover
$pic = $rows['cover'];
}

$cover = $t->albumCoverToURL($pic,'lq');
//album added before 'cover' field was added to 'tidal_album' table
if (!$pic) {
getAlbumFromTidal($album_id);
$picQuery = mysqli_query($db,"SELECT cover FROM tidal_album
WHERE album_id = '" . $album_id . "'");
$rows = mysqli_fetch_assoc($picQuery);
$pic = $rows['cover'];
}

$cover = $t->albumCoverToURL($pic,'lq');
if (!$cover) {
$cover = 'image/no_image.jpg';
}
$res .= '<img onclick=\'location.href="index.php?action=view3&amp;album_id=' . $album['album_id'] . '"\' src="' . $cover . '" alt="" width="100%" height="100%">';
}
else {
Expand Down
51 changes: 34 additions & 17 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2123,18 +2123,19 @@ function viewRecentlyPlayed() {

if ($type == 'day') {
if ($cfg['use_tidal']) {
$query_rp = mysqli_query($db, "SELECT * FROM
((SELECT a.album_id, a.image_id, a.album, a.artist_alphabetic, counter.time as played_time
FROM counter JOIN (SELECT album_id, image_id, album, artist_alphabetic FROM album) as a on a.album_id = counter.album_id
WHERE counter.album_id NOT LIKE 'tidal_%')
UNION
(SELECT t.album_id, t.album_id as image_id, t.album, t.artist_alphabetic, counter.time as played_time
FROM counter JOIN (SELECT concat('tidal_',album_id) as album_id, album, artist_alphabetic FROM tidal_album) as t on t.album_id = counter.album_id
WHERE counter.album_id LIKE 'tidal_%')
) al
ORDER BY al.played_time DESC
");
} else {
$query_rp = mysqli_query($db, "SELECT * FROM
((SELECT a.album_id, a.image_id, a.album, a.artist_alphabetic, counter.time as played_time
FROM counter JOIN (SELECT album_id, image_id, album, artist_alphabetic FROM album) as a on a.album_id = counter.album_id
WHERE counter.album_id NOT LIKE 'tidal_%')
UNION
(SELECT t.album_id, t.album_id as image_id, t.album, t.artist_alphabetic, counter.time as played_time
FROM counter JOIN (SELECT concat('tidal_',album_id) as album_id, album, artist_alphabetic FROM tidal_album) as t on t.album_id = counter.album_id
WHERE counter.album_id LIKE 'tidal_%')
) al
ORDER BY al.played_time DESC
");
}
else {
$query_rp = mysqli_query($db, '
SELECT a.album_id, a.image_id, a.album, a.artist_alphabetic, counter.time as played_time
FROM counter JOIN (SELECT album_id, image_id, album, artist_alphabetic FROM album) as a on a.album_id = counter.album_id
Expand Down Expand Up @@ -2293,11 +2294,27 @@ function viewPlayedAtDay() {
$page = (get('page') ? get('page') : 1);
$max_item_per_page = $cfg['max_items_per_page'];


$query_rp = mysqli_query($db, '
SELECT a.album_id, a.image_id, a.album, a.artist_alphabetic, counter.time as played_time
FROM counter JOIN (SELECT album_id, image_id, album, artist_alphabetic FROM album) as a on a.album_id = counter.album_id WHERE counter.time > ' . $beginOfDay . ' AND counter.time < ' . $endOfDay . ' ORDER BY played_time DESC
' );
if ($cfg['use_tidal']) {
$q = '
SELECT * FROM
(
(SELECT a.album_id, a.image_id, a.album, a.artist_alphabetic, counter.time as played_time
FROM counter JOIN (SELECT album_id, image_id, album, artist_alphabetic FROM album) as a on a.album_id = counter.album_id WHERE counter.time > ' . $beginOfDay . ' AND counter.time < ' . $endOfDay . ')
UNION
(SELECT CONCAT("tidal_", b.album_id) as album_id, b.album_id as image_id, b.album, b.artist_alphabetic, counter.time as played_time
FROM counter JOIN (SELECT album_id, cover, album, artist_alphabetic FROM tidal_album) as b on CONCAT("tidal_", b.album_id) = counter.album_id WHERE counter.time > ' . $beginOfDay . ' AND counter.time < ' . $endOfDay . ')
) as c
ORDER BY c.played_time DESC
';
$query_rp = mysqli_query($db, $q );
//echo $q;
}
else {
$query_rp = mysqli_query($db, '
SELECT a.album_id, a.image_id, a.album, a.artist_alphabetic, counter.time as played_time
FROM counter JOIN (SELECT album_id, image_id, album, artist_alphabetic FROM album) as a on a.album_id = counter.album_id WHERE counter.time > ' . $beginOfDay . ' AND counter.time < ' . $endOfDay . ' ORDER BY played_time DESC
' );
}

$album_multidisc = albumMultidisc($query_rp, 'rp');
?>
Expand Down
10 changes: 8 additions & 2 deletions play.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ function prev_() {
require_once('include/play.inc.php');

$data = array();

$status = mpd('status');
if ($status['state'] == 'stop') {
mpd('play');
}
mpd('previous');
if (get('menu') == 'playlist') {
$status = mpd('status');
Expand Down Expand Up @@ -283,7 +286,10 @@ function next_() {
require_once('include/play.inc.php');

$data = array();

$status = mpd('status');
if ($status['state'] == 'stop') {
mpd('play');
}
mpd('next');
if (get('menu') == 'playlist') {
$status = mpd('status');
Expand Down
8 changes: 8 additions & 0 deletions tidalapi/tidal_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ function getStreamURL($track_id) {
return $this->request();
}

/* function getUserHomePage() {
curl_setopt($this->curl, CURLOPT_URL, self::API_URL . "/pages/home?locale=en_US&countryCode=" . $this->countryCode . "&deviceType=BROWSER");
return $this->request();
} */

function getUserPlaylists() {
curl_setopt($this->curl, CURLOPT_URL, self::API_URL . "users/" . $this->userId . "/playlists?sessionId=" . $this->sessionId . "&countryCode=" . $this->countryCode . "&limit=" . $limit);
return $this->request();
Expand All @@ -191,6 +196,9 @@ static function artistPictureWToURL($pic) {
}

static function albumCoverToURL($pic,$quality = 'hq') {
if (!$pic) {
return false;
}
$pic = str_replace("-","/",$pic);
if ($quality == 'hq') {
$pic = self::RESOURCES_URL . $pic . '/1280x1280.jpg';
Expand Down

0 comments on commit 4433cdd

Please sign in to comment.