astrXbian/www/boris/youtube.php

367 lines
9.4 KiB
PHP

<?php
require_once('conf.php');
require_once('functions.php');
$i = 0;
$div = 9;
$r = rand(0, ($div - 1));
$j = 0;
$maxElt = 16;
// require('php-ipfs-api/vendor/autoload.php');
// use Cloutier\PhpIpfsApi\IPFS;
// $ipfs = new IPFS("astroport", "8181", IPFS_API_PORT);
// echo 'IPFS id : ' . $ipfs->id() . '<br />';
$uriParams = [];
$videosList = array();
$videosListURIs = array();
$search = isset($_GET['search']) ? urldecode($_GET['search']) : "";
exec("/bin/bash -c './get_astrxbian_index.sh \"*\" \"". $search . "\"'", $videos);
exec("/bin/bash -c './get_PIN.sh'", $pinnedVideos);
// $videos = array_unique($videos);
// exec("/bin/bash -c './get_youtube_videos.sh'", $videos);
// echo file_get_contents("http://youtube2.com/ipns/12D3KooWHLLohhFqwTs3Ccego51w1Q2WUQ8JmhSMWtsZnQpMigHY/.12D3KooWHLLohhFqwTs3Ccego51w1Q2WUQ8JmhSMWtsZnQpMigHY/FASTRXBIAN");
// echo shell_exec('whoami'); // Pour savoir quel utilisateur système exécute les scripts PHP
// echo '<pre>'; var_dump($videos); echo '</pre>'; exit;
$tagsMenu = array();
$narrowingTags = array();
$show = isset($_GET['show']) ? $_GET['show'] : 'pinned';
if (isset($_GET['tags']) and !empty($_GET['tags'])) {
$tagFilter = explode('|', $_GET['tags']);
} else {
$tagFilter = array();
}
foreach ($videos as $v) {
if (empty($v)) {
continue;
}
list($contentType, $videoID, $year, $filename, $saison, $tagsStr, $ipnsHash, $definition, $videoURI) = explode(";", $v);
if (in_array($videoURI, $videosListURIs)) {
continue;
}
list($videoSource, $videoID) = handleVideoID($videoID);
$ipfsHash = preg_replace('!^/ipfs/([^/]+)/.*$!isU', '$1', $videoURI);
$mimeType = guessTypeFromFilename($videoURI);
$videoTags = getTagsListFromTagStr($tagsStr);
if (canReadVideoFormat($mimeType)) {
$tagsMenu = array_merge($tagsMenu, $videoTags);
}
$keepVideo = true;
$keepVideo = ($keepVideo and canReadVideoFormat($mimeType));
$keepVideo = ($keepVideo and (in_array($ipfsHash, $pinnedVideos) or ($show != 'pinned')));
$keepVideo = ($keepVideo and (!in_array($ipfsHash, $pinnedVideos) or ($show != 'notpinned')));
$keepVideo = ($keepVideo and (empty($tagFilter) or (array_intersect($tagFilter, $videoTags) == $tagFilter)));
if ($keepVideo) {
$narrowingTags = array_merge($narrowingTags, $videoTags);
/*
++$i;
if ($i % $div != $r) {
continue;
}
++$j;
if ($j > $maxElt) {
break;
}
*/
$duration = NULL;
$thumbURL = '';
$videoTitle = NULL;
if (($contentType == 'youtube') and ($videoSource == 'www.youtube.com')) {
$thumbURL = sprintf(YOUTUBE_THUMB, $videoID);
// $thumbURL = '';
// $json = getVideoJson($ipnsHash);
if (!empty($json)) {
// echo '<pre>'; var_dump($json); echo '</pre>';
$videoTitle = $json->title;
$duration = $json->duration;
}
} elseif (($contentType == 'youtube') and ($videoSource == '9gag.com')) {
$thumbURL = 'styles/'. THEME .'/9gag_logo.png';
} else {
$thumbURL = 'styles/'. THEME .'/font-awesome/film.white.90x90.png';
}
$videosListURIs[] = $videoURI;
$videosList[] = [
'duration' => $duration,
'thumbURL' => $thumbURL,
'category' => $contentType,
'mime' => $mimeType,
'tags' => $videoTags,
'ipnsHash' => $ipnsHash,
'uri' => $videoURI,
'title' => $videoTitle,
'filename' => $filename,
'videoId' => $videoID,
'videoSource' => $videoSource
];
}
}
$tagsMenu = array_unique($tagsMenu);
$narrowingTags = empty($narrowingTags) ? $tagFilter : array_unique($narrowingTags);
$home = true;
include('inc/header.php');
echo '
<aside id="menu">
<div>';
$tagFilterQuery = implode('|', $tagFilter);
$uriParams = [
'pinned' => [
'tags' => $tagFilterQuery,
'show' => 'pinned',
'search' => $search
],
'notpinned' => [
'tags' => $tagFilterQuery,
'show' => 'notpinned',
'search' => $search
],
'both' => [
'tags' => $tagFilterQuery,
'show' => 'both',
'search' => $search
]
];
$classes = [
'pinned' => ($show == 'pinned' ? ' selected' : ''),
'both' => ($show == 'both' ? ' selected' : ''),
'notpinned' => ($show == 'notpinned' ? ' selected' : ''),
];
echo '
<nav id="pinFilter">
<ul>
<li id="filter_pinned" class="'. $classes['pinned'] . '">
<a href="'. buildRequestedURI('/youtube.php', $uriParams['pinned'], true) .'">
<span>Épinglé localement</span>
</a>
</li>
<li id="filter_both" class="'. $classes['both'] . '">
<a href="'. buildRequestedURI('/youtube.php', $uriParams['both'], true) .'">
<span>Épinglé ou non</span>
</a>
</li>
<li id="filter_notpinned" class="'. $classes['notpinned'] . '">
<a href="'. buildRequestedURI('/youtube.php', $uriParams['notpinned'], true) .'">
<span>Non épinglé</span>
</a>
</li>
</ul>
</nav>
';
// if (!empty($tagFilter)) {
echo '
<nav id="tagfilter">
<h3>Filtrer davantage</h3>
<ul id="narrowingTags">';
// list($narrowingTags, $stationsTags) = separateTags($narrowingTags, $stations);
foreach ($narrowingTags as $tag) {
$tagArray = array($tag);
if (!in_array($tag, $tagFilter)) {
$selectedTag = false;
$tagQueryArray = array_merge($tagFilter, $tagArray);
} else {
$selectedTag = true;
$tagQueryArray = array_diff($tagFilter, $tagArray);
}
$classes = $selectedTag ? ' selected' : ' selectable';
$classes .= isStation($tag) ? ' station' : '';
$uriParams = [
'tags' => (empty($tagQueryArray) ? '' : implode('|', $tagQueryArray)),
'show' => $show,
'search' => $search
];
echo '
<li class="'. $classes . '">
<a href="'. buildRequestedURI('/youtube.php', $uriParams, true) .'">
' . $tag .'
</a>
</li>';
}
echo '
</ul>
</nav>';
// }
/*
echo '
<nav id="browse">
<h3>Parcourir</h3>
<ul id="tagsList">';
foreach ($tagsMenu as $tag) {
$uriParams = [
'tags' => $tag,
'show' => $show
];
$classes = isStation($tag) ? ' station' : '';
echo '
<li class="'. $classes . '">
<a href="'. buildRequestedURI('/youtube.php', $uriParams, true) .'">
' . $tag .'
</a>
</li>';
}
echo '
</ul>
</nav>';
*/
echo '
</div>
</aside>';
// echo '<pre>'; var_dump($videosList); echo '</pre>';
echo '
<ul id="videosList">';
foreach ($videosList as $video) {
echo '<li>';
$displayTitle = isset($video['title']) ? $video['title'] : $video['filename'];
$href = 'youtube_watch.php?uri='. $video['uri'] . '&amp;name='. urlencode($displayTitle) .'&mime='. $video['mime'];
echo '
<p class="thumbnail">
<a href="/ipns/'. $video['ipnsHash'] .'">
<img src="'. $video['thumbURL'] . '" alt="'. $displayTitle . '" />
</a>
</p>
';
if (isset($video['duration'])) {
echo '
<p class="duration">
'. formatDuration($video['duration']) . '
</p>';
}
echo '
<p class="video-title">
<a href="'. $href .'">
' . $displayTitle . '
</a>
</p>
<ul class="tags">';
foreach ($video['tags'] as $tag) {
$tagArray = array($tag);
if (!in_array($tag, $tagFilter)) {
$selectedTag = false;
$tagQueryArray = array_merge($tagFilter, $tagArray);
} else {
$selectedTag = true;
$tagQueryArray = array_diff($tagFilter, $tagArray);
}
$tagQueryArray = $tagArray;
$classes = $selectedTag ? ' selected' : 'selectable';
if (!empty($tagQueryArray)) {
$uriParams['tags'] = implode('|', $tagQueryArray);
}
$uriParams['show'] = $show;
echo '
<li class="'. $classes . '">
<a href="'. buildRequestedURI('/youtube.php', $uriParams, true) .'">
' . $tag .'
</a>
</li>';
}
echo '
</ul>';
echo '</li>';
}
echo '</ul>';
include('inc/footer.php');