Skip to content

Instantly share code, notes, and snippets.

@malikkurosaki
Created March 11, 2018 03:08
Show Gist options
  • Save malikkurosaki/f4ebff1356b990279d6a8d7eda4889bc to your computer and use it in GitHub Desktop.
Save malikkurosaki/f4ebff1356b990279d6a8d7eda4889bc to your computer and use it in GitHub Desktop.
interface youtube search for creative common , type video max result and key search
<?php
session_start();
/*
name : lazy yutube
author : malik kurosaki
licency : public opensource
description : aplikasi ini saya buat karena saya pemalas dan menunggu para pemalas pemalas yang lain untuk membuat aplikasi lainnya
untuk menunjang dan mempermudah bagi kegiatan pemalas pemalas lainnya
silahkan join jika memang anda seorang pemalas
contact : wa 081338929722
*/
?>
<!doctype html>
<html>
<head>
<title>YouTube Search</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<style>
html,body{
max-width: 720px;
margin: 0px auto;
}
#pop{
max-width: 500px;
position: absolute;
margin: 5% auto;
right: 0;
left: 0;
display: none;
}
#result{
height: 150px;
margin: 0px auto;
overflow: hidden;
}
#progres{
position: fixed;
top: 5px;
display: none;
}
#upl{
position: fixed;
top: 5px;
display: none;
}
</style>
</head>
<body class="" >
<div class="w3-container w3-center w3-teal w3-round w3-card w3-border 3-border-white">
<h1>Lazy Youtuber</h1>
<p>
<?php if(isset($_SESSION['halo'])){
echo $_SESSION['halo'];
echo " <a href='logout.php'>logout</a>";
}else{
include_once "auth.php";
} ?>
</p>
</div>
<div id='progres' class="w3-blue w3-padding w3-container"></div>
<div id="upl" class="w3-red"></div>
<div id="pop" class="w3-round w3-card w3-padding w3-light-grey">
<div class="w3-container">
<div class="w3-center w3-conteiner">UPLOAD</div>
<img class="w3-image w3-border w3-border-white w3-round w3-card" id="content" >
</div>
<div class="w3-raw-cell w3-padding w3-center">
<div class="w3-cell">
<input id="tg1" class="w3-input w3-round" type="text" name="tg1" placeholder="insert tag 1 here">
</div>
<div class="w3-cell">
<input id="tg2" class="w3-input w3-round" type="text" name="tg2" placeholder="insert tag 2 here">
</div>
</div>
<div class="w3-container"><input id="dcs" class="w3-input" type="text" placeholder="type description here"> </div>
<div class="w3-container">
<div class="w3-half w3-padding">
<div id="no" class="w3-round w3-red w3-padding">no</div>
</div>
<div class="w3-half w3-padding">
<div id="yes" class="w3-round w3-green w3-padding">yes</div>
</div>
</div>
</div>
<form method="GET" class="w3-container w3-margin-bottom" id="cc">
<div class="w3-container w3-raw-cell w3-light-grey w3-round">
<div class="w3-cell">max result<input class=" w3-round w3-btn w3-light-grey" type="number" id="maxResults" name="maxResults" min="1" max="50" step="1" value="9">
</div>
<div class="w3-cell">duration
<select class="w3-btn w3-round w3-light-grey" name="f" form="cc">
<option value="short">short</option>
<option value="medium">medium</option>
</select>
</div>
</div>
<div class="w3-raw-cell w3-margin-top">
<div class="w3-threequarter"><input class='w3-round w3-input w3-button w3-light-grey margin-bottom' type="search" id="q" name="q" placeholder="please search cc video to choise"></div>
<div class="w3-quarter "><div class=""><input form="cc" class="w3-button w3-round w3-red w3-right" type="submit" value="Search"></div></div>
</div>
</form>
<?php
if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
throw new \Exception('please run "composer require google/apiclient:~2.0" in "' . __DIR__ .'"');
}
require_once __DIR__ . '/vendor/autoload.php';
if (isset($_GET['q']) && isset($_GET['maxResults'])) {
$DEVELOPER_KEY = 'AIzaSyCybYeFxMI1pqKvMBFlz5qquPgnmL0mcBY';
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
// Define an object that will be used to make all API requests.
$youtube = new Google_Service_YouTube($client);
$htmlBody = '';
try {
// Call the search.list method to retrieve results matching the specified
// query term.
$searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => $_GET['q'],
'maxResults' => $_GET['maxResults'],
'videoLicense' => 'creativeCommon',
'type' => 'video','videoDuration' => $_GET['f']
));
$names = '';
$videos = '';
foreach ($searchResponse['items'] as $searchResult) {
if($searchResult['id']['kind']) {
$names .= $searchResult['snippet']['title'];
$videos .= "<div id='result' class='w3-col s4 w3-padding w3-round w3-light-grey'><div class=' '><img id='".$searchResult['id']['videoId']."' src='https://img.youtube.com/vi/".$searchResult['id']['videoId']."/default.jpg' alt='".$searchResult['snippet']['title']."' class='w3-round' ><div class='w3-tiny '>".$searchResult['snippet']['title']."</div></div></div>";
}
}
$htmlBody .= <<<END
<div>$videos</div>
END;
} catch (Google_Service_Exception $e) {
$htmlBody .= sprintf('<p>A service error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
} catch (Google_Exception $e) {
$htmlBody .= sprintf('<p>An client error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
}
}
?>
<div class="w3-container w3-margin-bottom w3-card">
<?=$htmlBody?>
</div>
<footer class="w3-blue-grey w3-container">
<div class="w3-raw-cell">
<div class="w3-cell w3-padding">
<h3>disclaimer</h3>
<p class="w3-tiny">aplikasi ini dibuat untuk kamu yang benar benar malas</p>
</div>
<div class="w3-cell w3-padding">
<h3>about</h3>
<p class="w3-tiny">malik kurosaki</p>
</div>
<div class="w3-cell w3-padding">
<h3>contact</h3>
<p class="w3-tiny">wa: 081338929722</p>
</div>
</div>
</footer>
<script>
var gt = document.getElementsByTagName("IMG");
var pop = document.getElementById("pop");
var no = document.getElementById("no");
var yes = document.getElementById("yes");
var content = document.getElementById("content");
var progres = document.getElementById("progres");
var upl = document.getElementById("upl");
var p = 1;
for(i=0;i<gt.length;i++){
gt[i].onclick= function(e){
var tid = e.target.id;
var ttitle = e.target.alt;
var tg1 = document.getElementById("tg1");
var tg2 = document.getElementById("tg2");
var dcs = document.getElementById("dcs");
pop.style.display = "block";
content.src ='https://img.youtube.com/vi/'+ e.target.id +'/0.jpg';
no.onclick = function(){
pop.style.display = "none";
};
yes.onclick = function(){
pop.style.display = "none";
progres.style.display = "block";
var tdl = setInterval(prun,1000);
xdl = new XMLHttpRequest();
xdl.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
progres.style.display = "none";
clearInterval(tdl);
if(this.responseText.includes("time")){
alert("internet not stable or select another video");
}
if(this.responseText == 1){
//prepare to upload
upl.style.display = "block";
var tup = setInterval(urun,1000);
xup = new XMLHttpRequest();
xup.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
upl.style.display = "none";
clearInterval(tup);
if(this.responseText.includes("uploaded")){
alert("berhasil");
}
}
};
xup.open("GET","upload.php?u="+ ttitle +"&t1="+ tg1.value +"&t2="+ tg2.value +"&dcs="+ dcs.value,true);
xup.send();
}else{
alert("fiailed connect to server or internet no connection");
}
}
};
xdl.open("GET","download.php?dl="+ tid +"&t="+ ttitle,true);
xdl.send();
};
};
}
function prun(){
p++;
progres.style.width = p +"%";
progres.innerHTML = p +"%";
if(p >=100){
p = 1;
}
}
function urun(){
p++;
upl.style.width = p +"%";
upl.innerHTML = p +"% upload";
if(p >=100){
p = 1;
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment