Skip to content

Commit

Permalink
Fixed YouTube search results
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturSierzant committed Jul 3, 2020
1 parent 4433cdd commit c2d1c06
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 14 deletions.
2 changes: 1 addition & 1 deletion about.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function about() {
<tr class="line"><td colspan="5"></td></tr>
<tr class="<?php echo ($i++ & 1) ? 'even' : 'odd'; ?>">
<td>&nbsp;</td>
<td style="vertical-align: top;">v1.06 <br>2020.??.??</td>
<td style="vertical-align: top;">v1.06 <br>2020.07.??</td>
<td></td>
<td>
<ul style="padding-left: 1em;">
Expand Down
46 changes: 39 additions & 7 deletions ajax-yt-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
require_once('include/library.inc.php');
require_once('PHPsimpleHTMLDomParser/simple_html_dom.php');

//error_reporting(E_ALL ^ E_NOTICE);
//@ini_set('display_errors', 'On');

global $cfg, $db;

authenticate('access_media');
Expand All @@ -32,14 +35,15 @@
$search = $_GET['searchStr'];
$search = str_replace(" ", "+", $search);
$html = new simple_html_dom();
$html -> load_file("https://www.youtube.com/results?search_query=" . $search);
//echo ($html);
//exit();
//$html -> load_file("https://www.youtube.com/results?search_query=" . $search);
$urlSearch = "https://www.google.com/search?q=site:youtube.com+" . $search;
$html -> load_file($urlSearch);
$i = 0;
$data['return'] = 0;

for ($j=1;$j<=5;$j++) {
foreach($html->find('ol.item-section') as $ol){

for ($j=1;$j<=2;$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){
Expand All @@ -55,11 +59,39 @@
}
}
}
} */
foreach($html->find('div[id=main]') as $ol){
for ($k = 3; $k <= 15; $k++) {
//echo $ol;
if ($ol->children($k) !== null && $ol->children($k)->find('div',0) !== null && $ol->children($k)->find('div',0)->find('div',0) !== null) {
foreach($ol->children($k)->find('div',0)->find('div',0)->find('a') as $a) {
$watch = $a->find('div',1)->innertext;
if (strpos($watch,'watch') !== false) {
$url = urldecode(str_replace('/url?q=','',$a->href));
$query = parse_url($url, PHP_URL_QUERY);
parse_str($query, $output);
$results['items'][$i]['id'] = $output['v'];
$title = $a->find('h3',0)->plaintext;
$title = mb_convert_encoding($title,'UTF-8','UTF-8');
$title = str_replace(' - YouTube','',$title);
$results['items'][$i]['title'] = $title;
$results['items'][$i]['url'] = "/watch?v=" . $output['v'];

if ($ol->children($k)->find('div',0)->children(2) !== null) {
$t = $ol->children($k)->find('div',0)->children(2)->plaintext;
$t = preg_match('/\d{0,}\d{0,}:{0,}\d{0,}\d:\d\d/',$t,$matches);
$results['items'][$i]['time'] = $matches[0];
}
}
$i++;
}
}
}
}
if ($i==0) {
//try to load YT page up to 5 times because sometimes it returned 0 results
//try to load YT page up to 2 times because sometimes it returned 0 results
$j++;
$html -> load_file("https://www.youtube.com/results?search_query=" . $search);
$html -> load_file($urlSearch);
}
else {
break;
Expand Down
2 changes: 1 addition & 1 deletion include/initialize.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

define('NJB_START_TIME', microtime(true));

define('NJB_VERSION', '1.05');
define('NJB_VERSION', '1.06');
define('NJB_DATABASE_VERSION', 47);
define('NJB_IMAGE_SIZE', 300);
define('NJB_IMAGE_QUALITY', 85);
Expand Down
2 changes: 1 addition & 1 deletion skin/dark_red/template.header.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ function setMiniplayer(){


<span id="menuMiddleMedia">
<span id="list" onclick='toggleSubMiddle("Alpha");'>people <i id="iconmenuSubMiddleMediaAlpha" class="fa fa-chevron-circle-down"></i></span>
<span id="list" onclick='toggleSubMiddle("Alpha");'>artist <i id="iconmenuSubMiddleMediaAlpha" class="fa fa-chevron-circle-down"></i></span>

<?php echo $header['seperation']; ?>
<!-- <span id="genre" onclick='toggleSubMiddle("Genre");'>genre <i id="iconmenuSubMiddleMediaGenre" class="fa fa-chevron-circle-down"></i></span>
Expand Down
3 changes: 2 additions & 1 deletion skin/dark_wide/template.header.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
$tileSize = $tileSizeArr[0];
$containerWidth = $tileSizeArr[1];
var $useMaxWidth = true; //special case for skin dark-wide

var opts = {
lines: 13, // The number of lines to draw
length: 21, // The length of each line
Expand Down Expand Up @@ -716,7 +717,7 @@ function setMiniplayer(){


<span id="menuMiddleMedia">
<span id="list" onclick='toggleSubMiddle("Alpha");'>people <i id="iconmenuSubMiddleMediaAlpha" class="fa fa-chevron-circle-down"></i></span>
<span id="list" onclick='toggleSubMiddle("Alpha");'>artist <i id="iconmenuSubMiddleMediaAlpha" class="fa fa-chevron-circle-down"></i></span>

<?php echo $header['seperation']; ?>
<!-- <span id="genre" onclick='toggleSubMiddle("Genre");'>genre <i id="iconmenuSubMiddleMediaGenre" class="fa fa-chevron-circle-down"></i></span>
Expand Down
2 changes: 1 addition & 1 deletion skin/ompd_dark/template.header.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ function setMiniplayer(){


<span id="menuMiddleMedia">
<span id="list" onclick='toggleSubMiddle("Alpha");'>people <i id="iconmenuSubMiddleMediaAlpha" class="fa fa-chevron-circle-down"></i></span>
<span id="list" onclick='toggleSubMiddle("Alpha");'>artist <i id="iconmenuSubMiddleMediaAlpha" class="fa fa-chevron-circle-down"></i></span>

<?php echo $header['seperation']; ?>
<!-- <span id="genre" onclick='toggleSubMiddle("Genre");'>genre <i id="iconmenuSubMiddleMediaGenre" class="fa fa-chevron-circle-down"></i></span>
Expand Down
2 changes: 1 addition & 1 deletion skin/ompd_default/template.header.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ function setMiniplayer(){


<span id="menuMiddleMedia">
<span id="list" onclick='toggleSubMiddle("Alpha");'>people <i id="iconmenuSubMiddleMediaAlpha" class="fa fa-chevron-circle-down"></i></span>
<span id="list" onclick='toggleSubMiddle("Alpha");'>artist <i id="iconmenuSubMiddleMediaAlpha" class="fa fa-chevron-circle-down"></i></span>

<?php echo $header['seperation']; ?>
<!-- <span id="genre" onclick='toggleSubMiddle("Genre");'>genre <i id="iconmenuSubMiddleMediaGenre" class="fa fa-chevron-circle-down"></i></span>
Expand Down
2 changes: 1 addition & 1 deletion skin/ompd_the_first/template.header.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ function setMiniplayer(){


<span id="menuMiddleMedia">
<span id="list" onclick='toggleSubMiddle("Alpha");'>people <i id="iconmenuSubMiddleMediaAlpha" class="fa fa-chevron-circle-down"></i></span>
<span id="list" onclick='toggleSubMiddle("Alpha");'>artist <i id="iconmenuSubMiddleMediaAlpha" class="fa fa-chevron-circle-down"></i></span>

<?php echo $header['seperation']; ?>
<!-- <span id="genre" onclick='toggleSubMiddle("Genre");'>genre <i id="iconmenuSubMiddleMediaGenre" class="fa fa-chevron-circle-down"></i></span>
Expand Down

0 comments on commit c2d1c06

Please sign in to comment.