ALL THE NEW CODES

This commit is contained in:
Nicolas A. Tonne
2014-09-01 14:04:00 +02:00
parent 8d6e08faa5
commit 6d3f725a58
21 changed files with 2784 additions and 340 deletions

123
change.php Normal file
View File

@@ -0,0 +1,123 @@
<?php
$guid=substr(base64_encode(crc32($_SERVER['HTTP_USER_AGENT'].$_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_ACCEPT_LANGUAGE'])), 0, 8);
if(isset($_REQUEST['test'])){
echo($guid);
exit;
}
//save or del
$list = explode("/", htmlspecialchars(strtolower($_SERVER["REQUEST_URI"])));
if($list[1]==""||!isset($list[1])||count($list)<=1)$list="videos";
else $list=$list[1];
$list="lists/".$list.".json";
$f = @fopen($list,"x");
if($f){ fwrite($f,"[[],[".time()."],[],[],[],[]]"); fclose($f); }
$file = file_get_contents($list);
$data = json_decode($file);
$save = false;
if(isset($_REQUEST['thisUrl'])){
$string = $_REQUEST['thisUrl'];
$action = isset($_REQUEST['act']);
if($data[0][0] == $string)
{
if($action=="save"){ //next song
$save = true;
nextSong();
}
else if($action=="delete"){
array_shift($data[0]);
array_shift($data[3]);
array_shift($data[2]);
}
file_put_contents($list, json_encode($data));
}
if($action == "save" && !$save) //count views
{
$data[4][0] = $data[4][0] + 1;
file_put_contents($list, json_encode($data));
}
echo $data[0][0];
}
else if(isset($_GET['v'])){ //add
$video = htmlspecialchars($_GET['v']);
$name = htmlspecialchars($_GET['n']);
if(!in_array($video, $data[0]))
{
//array_push($data[0], $video);
$i = array_search(0, $data[2]);
if($i == 0)$i=1;
else if($i == false)$i=count($data[2]);
array_splice($data[3], $i, 0, array($name));
array_splice($data[2], $i, 0, array(1));
array_splice($data[0], $i, 0, array($video));
file_put_contents($list, json_encode($data));
print("added");
}
}
else if(isset($_GET['vote'])){ //add vote
$vote=$_GET['vote'];
$id=$_GET['id'];
$i = array_search($id, $data[0]);
if($vote == 'neg'){$voteAdd = -1;}
else if($vote == 'pos'){$voteAdd = 1;}
$name = $data[3][$i];
$votes = $data[2][$i] + $voteAdd;
if($i == true && $votes >= 0){
//print_r($i);
// echo "IIII: ",$i;
unset($data[3][$i]);
unset($data[0][$i]);
unset($data[2][$i]);
$underVote = array_search($votes-1, $data[2]);
if($underVote == 0)$underVote=1;
else if($underVote == false)$underVote=count($data[2]);
array_splice($data[3], $underVote, 0, array($name));
array_splice($data[2], $underVote, 0, array($votes));
array_splice($data[0], $underVote, 0, array($id));
file_put_contents($list, json_encode($data));
echo "Vote registrated. I hope";
}
}
else if(isset($_GET['skip'])){ //skip song request
$viewers=$data[4][0];
$skips=count($data[5]);
if(!in_array($guid, $data[5])){
array_push($data[5], $guid);
$skips+=1;
$data[5][0]=$skips;
if($skips>=$viewers/2){
nextSong();
echo("skipped!");
}
file_put_contents($list, json_encode($data));
}
echo($skips."/".$viewers);
}
else{ print($file); }
function nextSong(){
global $data;
array_push($data[0], $data[0][0]);
array_shift($data[0]);
array_push($data[2], 0); //reset votes
array_shift($data[2]);
array_push($data[3], $data[3][0]);
array_shift($data[3]);
array_shift($data[4]);
array_push($data[4], 1);
$data[5]=array();
$data[1][0] = time();
}
?>

3
channel.php Normal file
View File

@@ -0,0 +1,3 @@
<?php
echo file_exists()
?>

View File

@@ -1,20 +0,0 @@
<?php
if(isset($_POST['thisUrl']))
{
$string = $_POST['thisUrl'];
$file = file_get_contents('videos.json');
$data = json_decode($file);
unset($file);//prevent memory leaks for large json.
//insert data here
if($data[0] == $string)
{
array_shift($data);
}
file_put_contents("videos.json", json_encode($data));
unset($data);
}else
{
echo "You're a bad boy";
}
?>

BIN
favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

169
index.php
View File

@@ -1,136 +1,47 @@
<?php
/*$host = 'http://'.$_SERVER['HTTP_HOST'].'/+';
$short = $_SERVER['QUERY_STRING'];*/
$video = htmlspecialchars($_GET['v']);
$name = htmlspecialchars($_GET['n']);
$list = json_decode(file_get_contents('videos.json'));
if(isset($_GET['v'])){
$file = file_get_contents('videos.json');
$data = json_decode($file);
unset($file);//prevent memory leaks for large json.
}
?>
<html>
<head>
<head>
<title>Zöff</title>
<link rel="stylesheet" type="text/css" href="style.css" title="Default" />
<meta name="author" content="Nicolas 'Nixo' Almagro Tonne &amp; Kasper 'KasperRT' Rynning-Tønnesen">
<link rel="stylesheet" type="text/css" href="/style.css" title="Default" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<link rel="icon" type="image/png" href="/static/favicon.png"/>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300' rel='stylesheet' type='text/css'>
</head>
<body>
<div class="top vcent centered">
<div id="change" class="small">
<div class="big">Zöff</div>
Zöff
<form name="ufo" action="" class="daform" id="base" method="get" onsubmit="return submitform();">
<input id="longurl" name="v" type="text" class="innbox" />
</form>
<div id="change" class="small"><?php
if(isset($_GET['chan'])) header('Location: '.$_GET['chan']);
$list = explode("/", htmlspecialchars(strtolower($_SERVER["REQUEST_URI"])));
if($list[1]==""||!isset($list[1])||count($list)<=1){$list="";include('nochan.php');die();}
else $list=$list[1];?>
<a id="toptitle" href="/">Zöff</a>
<div id="chan" class="chan" title="Show big URL" onclick="show()"><?php echo(ucfirst($list));?></div>
<input id="search" name="v" type="text" class="search_input innbox" spellcheck="false" placeholder="Search" onsubmit="null;" autocomplete="off"/>
<div id="results"></div>
<div class="main">
<div id="player" class="ytplayer"></div>
<div class="playlist" >
<div id="buttons" class="result">
<img src="/static/skip.png" class="skip" alt="Skip" title="Skip" onclick="skip();">
</div>
<script type="text/javascript" src="swfobject.js"></script>
<div id="playlist">
<div id="wrapper">
</div>
</div>
</div>
</div>
</div>
<div class="footer small centered top anim">&copy; 2014 <a class="anim" href="//nixo.no">Nixo</a> &amp; <a class="anim" href="//kasperrt.no">KasperRT</a> </div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="ytapiplayer">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>
<script>
/**
TODO:
-legge til timer når man trykker pause for at når man "unpauser", går den dit den ville vært, hvis videoen ville blitt ferdig, load en ny video men ha den på pause
-legge til tid når en video ble påbegynt, for at hvis folk joiner midt i en video, hopper den dit
*/
/**
Fetcher sangen som spilles fra JSON filen
*/
var response = $.ajax({ type: "GET",
url: "videos.json",
async: false
}).responseText;
var url = $.parseJSON(response);
response = url[0][0];
/**
Legger sangen inn i <div>en, via swfobject
*/
var params = { allowScriptAccess: "always"};
var atts = { id: "myytplayer" };
swfobject.embedSWF("http://www.youtube.com/v/"+response+"?enablejsapi=1&playerapiid=ytplayer&version=3&controls=1&iv_load_policy=3",
"ytapiplayer", "825", "462", "8", null, null, params, atts);
/**
eventlistener for når playeren endres
*/
function onytplayerStateChange(newState) {
if(newState == 0)
{
$.ajax({
type: "POST",
url: "save.php",
data: "thisUrl="+response,
success: function() {
console.log("saved");
console.log(response);
}
});
setTimeout(function(){
response = $.ajax({ type: "GET",
url: "videos.json",
async: false
}).responseText;
var url = $.parseJSON(response);
response = url[0][0];
console.log(response);
ytplayer.loadVideoById(response);
},500);
}
}
function errorHandler(newState)
{
$.ajax({
type: "POST",
url: "delete.php",
data: "thisUrl="+response,
success: function() {
console.log("deleted");
}
});
setTimeout(function(){
response = $.ajax({ type: "GET",
url: "videos.json",
async: false
}).responseText;
var url = $.parseJSON(response);
response = url[0];
ytplayer.loadVideoById(response);
},100);
}
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
//ytplayer.addEventListener("onError", "errorHandler");
ytplayer.seekTo(ytplayer.getDuration()-10);
ytplayer.setVolume(100);
ytplayer.playVideo();
}
</script>
<br>
<?php print_r($list); ?>
</div>
</body>
<script type="text/javascript" src="/swfobject.js"></script>
<script type="text/javascript" src="/iscroll.js"></script>
<script type="text/javascript" src="/list.js"></script>
<script type="text/javascript" src="/youtube.js"></script>
<script type="text/javascript" src="/search.js"></script>
<script type="text/javascript" src="/visualize.js"></script>
</body>
</html>

2006
iscroll.js Normal file

File diff suppressed because it is too large Load Diff

111
list.js Normal file
View File

@@ -0,0 +1,111 @@
var list;
var toSend = "";
var sendURL;
var myScroll;
var scroller = false;
var showToggle =true;
var chan = $("#chan").html();
function updateList()
{
console.log("updating list");
list = $.ajax({ type: "GET",
url: "change.php",
async: false
}).responseText;
list = $.parseJSON(list);
list[0].shift();
list[3].shift();
list[2].shift();
setTimeout(function()
{
$("#wrapper").empty();
$.each(list[0], function(j, listeID){
var video_title=list[3][j].replace(/\\\'/, "'");
var video_id = list[0][j];
var video_thumb = "http://i.ytimg.com/vi/"+video_id+"/default.jpg";
var odd = ""; if(j%2==0)odd=" oddlist";
var finalhtml="<div id='result' class='result lresult"+odd+"'>"+
"<img src='"+video_thumb+"' class='thumb lthumb'>"+
"<div class='ltitle'>"+video_title+"</div>"+
"<div class='votes'>"+list[2][j]+"<a onclick=\"vote('"+video_id+"','pos');\" id='plus'>+</a><a onclick=\"vote('"+video_id+"','neg');\" id='minus'>-</a></div>"+
"</div>";
$("#wrapper").append(finalhtml);
});
if($("#playlist").height() > $("#player").height())
{
if(!window.mobilecheck()){ $("#playlist").css({height: $("#player").height() - $("#buttons").height()-4});}
if(scroller == false)
{
myScroll = new IScroll('#playlist', {
mouseWheel: true,
scrollbars: false,
scrollY: true,
interactiveScrollbars: false
});
scroller = true;
}else
{
myScroll.refresh();
}
}
if(window.mobilecheck())
{
document.getElementById("player").style.display="none";
ytplayer.pauseVideo();
}
}, 2500);
}
function vote(id, vote){
console.log($.ajax({
type: "GET",
url: "change.php",
async: false,
data: "vote="+vote+"&id="+id,
success: function() {
console.log("voted "+vote+" on "+id);
if(vote=="pos"){ $("#playlist").addClass("success");}
else{ $("#playlist").addClass("error");}
},
}).responseText);
setTimeout(function(){
$("#playlist").removeClass("success");
$("#playlist").removeClass("error");
},1500);
}
function skip(){
console.log($.ajax({
type: "GET",
url: "change.php",
async: false,
data: "skip",
success: function() {
console.log("voted to skip song");
$("#buttons").addClass("success");
},
}).responseText);
setTimeout(function(){
$("#playlist").removeClass("success");
},1500);
}
function show(){
if(showToggle){
showToggle=false;
$("#toptitle").empty();
$("#chan").addClass("bigChan");
$("#chan").html("zoff.no/"+chan);
}else{
showToggle=true;
$("#toptitle").html("Zöff");
$("#chan").removeClass("bigChan");
$("#chan").html(chan);
}
}

0
lists/index.php Normal file
View File

40
nochan.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
if(isset($_GET['chan']))
{
header('Location: '.$_GET['chan']);
}
$dir = scandir('./lists');
$channels = array();
foreach($dir as $files)
{
//echo $files;
if(strpos($files, '.json') !== FALSE)
{
//echo "found some"
array_push($channels, ucfirst(str_replace(".json", "", $files)));
//$channels = $channels . str_replace(".json", "", $files) . " ";
}
}
?>
Zöff
<form name="ufo" action="" class="daform nomargin" id="base" method="get" onsubmit="null;" autocomplete="off">
<input id="search" name="chan" type="text" class="search_input innbox" spellcheck="false" placeholder="Type Channel Name" autofocus/>
</form>
</div>
<div id="channels">Channels: <br>
<?php
foreach($channels as $channel)
{
echo "<a class='channels' href='/".$channel."'>".$channel."</a>";
}
?>
</div></div>
<div class="footer small centered top anim">&copy; 2014 <a class="anim" href="//nixo.no">Nixo</a> &amp; <a class="anim" href="//kasperrt.no">KasperRT</a> </div>
</body>
</html>

View File

@@ -1,23 +0,0 @@
<?php
if(isset($_POST['thisUrl']))
{
$string = $_POST['thisUrl'];
$file = file_get_contents('videos.json');
$data = json_decode($file);
unset($file);//prevent memory leaks for large json.
//insert data here
if($data[0] == $string)
{
array_push($data, $string);
array_shift($data);
}
file_put_contents("videos.json", json_encode($data));
echo $data;
unset($data);
}else
{
echo "You're a bad boy";
}
die();
?>

View File

@@ -1,154 +0,0 @@
{
"auto_complete":
{
"selected_items":
[
]
},
"buffers":
[
],
"build_system": "",
"command_palette":
{
"height": 0.0,
"selected_items":
[
],
"width": 0.0
},
"console":
{
"height": 0.0,
"history":
[
]
},
"distraction_free":
{
"menu_visible": true,
"show_minimap": false,
"show_open_files": false,
"show_tabs": false,
"side_bar_visible": false,
"status_bar_visible": false
},
"file_history":
[
],
"find":
{
"height": 0.0
},
"find_in_files":
{
"height": 0.0,
"where_history":
[
]
},
"find_state":
{
"case_sensitive": false,
"find_history":
[
],
"highlight": true,
"in_selection": false,
"preserve_case": false,
"regex": false,
"replace_history":
[
],
"reverse": false,
"show_context": true,
"use_buffer2": true,
"whole_word": false,
"wrap": true
},
"groups":
[
{
"sheets":
[
]
}
],
"incremental_find":
{
"height": 0.0
},
"input":
{
"height": 0.0
},
"layout":
{
"cells":
[
[
0,
0,
1,
1
]
],
"cols":
[
0.0,
1.0
],
"rows":
[
0.0,
1.0
]
},
"menu_visible": true,
"output.find_results":
{
"height": 0.0
},
"project": "save.sublime-project",
"replace":
{
"height": 0.0
},
"save_all_on_build": true,
"select_file":
{
"height": 0.0,
"selected_items":
[
],
"width": 0.0
},
"select_project":
{
"height": 0.0,
"selected_items":
[
],
"width": 0.0
},
"select_symbol":
{
"height": 0.0,
"selected_items":
[
],
"width": 0.0
},
"settings":
{
},
"show_minimap": true,
"show_open_files": false,
"show_tabs": true,
"side_bar_visible": true,
"side_bar_width": 150.0,
"status_bar_visible": true,
"template_settings":
{
}
}

95
search.js Normal file
View File

@@ -0,0 +1,95 @@
$(document).ready(function()
{
$("#search").focus();
$('#base').bind("keyup keypress", function(e) {
var code = e.keyCode || e.which;
if (code == 13) {
e.preventDefault();
return false;
}
});
var old_input="";
$(".search_input").focus();
setTimeout(function(){
$(".search_input").keyup(function()
{
var search_input = $(this).val();
if(search_input != old_input){
old_input=search_input;
$("#results").html('');
if(search_input != ""){
var keyword= encodeURIComponent(search_input);
var yt_url='http://gdata.youtube.com/feeds/api/videos?q='+keyword+'&format=5&max-results=25&v=2&alt=jsonc';
$.ajax({
type: "GET",
url: yt_url,
dataType:"jsonp",
success: function(response)
{
if(response.data.items)
{
$.each(response.data.items, function(i,data)
{
if(data.duration > 720){return;}
var video_title=encodeURIComponent(data.title).replace(/'/g, "\\\'");
var views=data.viewCount;
var video_thumb = "http://i.ytimg.com/vi/"+data.id+"/default.jpg";
var length = Math.floor(data.duration/60)+":"+(data.duration-Math.floor(data.duration / 60)*60);
var finalhtml="<div id='result' class='result' onclick=\"submit('"+data.id+"','"+video_title+"');\">"+
"<img src='"+video_thumb+"' class='thumb'>"+
"<div id='title'>"+data.title+""+
"<span class='result_info'>"+data.uploader+" • "+views+" views • "+length+"</span></div></div>";
$("#results").append(finalhtml);
});
}
else
{
$("#video").html("<div id='no'>No Video</div>");
}
}
});
}
}
});
}, 300);
});
function submit(id,title){
console.log($.ajax({
type: "GET",
url: "change.php",
async: false,
data: "v="+id+"&n="+title,
success: function() {
console.log("added "+id);
document.getElementById("search").value = "";
$("#search").addClass("success");
$("#results").html('');
},
error: function(){
console.log("error in adding");
document.getElementById("search").value = "";
$("#search").addClass("error");
$("#results").html('');
}
}).responseText);
$("#search").focus();
setTimeout(function(){
$("#search").removeClass("success");
$("#search").removeClass("error");
},1500);
}
// if(reply=="added"){$("#search").removeClass('success'); $("#search").addClass('success');}

BIN
static/Logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
static/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
static/skip.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -1,15 +1,62 @@
body{background:#444; overflow: hidden;}
.top, .top a {
font-family: 'Open Sans', sans-serif; font-weight: 600; text-align: center;
body{background:#FFF; margin:0;}
.top{
font-family: 'Open Sans', sans-serif; font-weight: 300; text-align: center;
animation: fadein .5s; -moz-animation: fadein .5s; -webkit-animation: fadein .5s; -o-animation: fadein .5s;
}
.top div{color:#ed207f;}
.vcent{position: relative; top: 50%; transform: translateY(-50%);}
.face{line-height: 1; font-size: 29vw; word-spacing: 60px; margin-top: -7%;}
.innbox, .innbox a{width:80%; height: 50px; font-family: 'Open Sans', sans-serif; font-size: 25px; color:#f15; text-align: center;}
.small, .small a{font-size: 5vw; color:#E2E2E2; display:block !important; text-decoration: none;}
.small a:hover{color:#ed207f;}
.daform{margin-bottom: 20px;}
.big{font-size:180vh; position:absolute; top:-100%; color:#000 !important; z-index:-1;}
.top, .top a{color:#ed207f; text-decoration: none;}
.vcent{position: relative; top: 50%; -webkit-transform: translateY(-50%);}
.channels{padding:10px;}
.innbox, .innbox a{
width:90%; height: 50px; border-radius:7px; border:none; font-family: 'Open Sans', sans-serif; font-size: 25px; margin-bottom: 20px;
color:#f15; text-align: center;-webkit-transition:background 1s;-moz-transition:background 1s;-o-transition:background 1s; transition:background 1s;
}
.success{animation: fadecol 1.5s; -moz-animation: fadecol 1.5s; -webkit-animation: fadecol 1.5s; -o-animation: fadecol 1.5s;}
.error{animation: fadewrong 1.5s; -moz-animation: fadewrong 1.5s; -webkit-animation: fadewrong 1.5s; -o-animation: fadewrong 1.5s;}
.small{font-size: 5vw; color:#E2E2E2; display:block !important; text-decoration: none; }
/*.small:hover{color: #CCC;}*/
.big{font-size:180vh; position:absolute; top:-50%; color:#330A00 !important; z-index:-1; width: 100%; overflow: hidden; display: none;}
.footer a{color:#696969; text-decoration: none;}.footer a:hover {color:#ed207f;}
.footer{font-size: 15px; position:absolute; width:99%;color:#c0c0c0 !important; margin-top: 0; word-spacing: 2px;}
.nomargin{padding: 0;margin:0;}
.anim{transition: all .20s ease-in-out; -moz-transition: all .20s ease-in-out; -webkit-transition: all .20s ease-in-out;}
.chan{color:#CCC; cursor:pointer; display: inline;}
.bigchan{color: #ed207f; font-size: 10vw; padding-top: 25%;}
#buttons{cursor: default; text-align: right;}
.skip{cursor: pointer; height: 25px; padding:8px 21px 0 0;}
#results{position:absolute; background-color: white; font-size: 14px; width:90%; margin-left: 5%; margin-top:-5px; z-index: 1; }
.result{border: 1px solid #EEE; border-bottom:none; padding: 3px 0 3px 10%; text-align: left; height: 40px; cursor: pointer;}
.result:hover{background-color: #DDD;}
#title{ padding-left: 20%; padding-top:10px; max-width: 76%; color:#ed207f;}
.result_info{color:#888; font-size: 12px; float:right;}
.thumb{height: 40px; width:80px; float: left;}
.main{width:90%; margin: 0 auto 0 auto;}
.playlist{background-color: #DADADA; width:20%; margin-left: 0px; display: inline-block; font-size: 14px; border-radius: 3px; vertical-align: top; overflow: hidden; height: calc(87% - 183px); border-bottom:solid #c9c9c9 4px;}
.lresult{padding:0; height: 60px; border-top: none; cursor: default; background-color: #DADADA;}
.lthumb{height: 60px; margin-right: 10px; display: inline;}
.ltitle{ color:#ed207f; overflow: hidden; height: 60px; }
.oddlist{background-color: #EEE;}
.votes{float: right; position: relative; margin-top: -1.4em; padding:0 3 0 4; background-color: #333; border-radius: 3px;}
#plus, #minus {text-decoration: none; color:white; margin-left: 2px; padding-left: 3px; padding-right: 3px; }
#plus:hover,#minus:hover{background-color: #111;}
#player{height: 68%; height: calc(87% - 183px); width: 78%; border-radius: 3px; border-bottom:solid #c9c9c9 4px;}
#playlist{}
@media (max-width: 1000px) {
#player{width: 100%; height:45%; margin-bottom: 20px;}
.playlist{width: 100%;}
.lresult{font-size: 40px; height: 90px; font-size: 50px;}
.votes{font-size: 42px; padding-right: 8px; height: 89px; line-height: 89px; padding-left: 20px; border-radius: 15px;}
.lthumb{height: 90px;}
#plus,#minus{padding-left: 24px; margin-left: 0; padding-right: 24px;}
#plus{border-right:solid 3px rgb(172, 172, 172);}
}
@-webkit-keyframes fadein{from {opacity:0;}to{opacity:1;}}@keyframes fadein{from{opacity:0;}to{opacity:1;}}@-moz-keyframes fadein{from{opacity:0;}to{opacity:1;}}@-o-keyframes fadein{from{opacity:0;}to{opacity:1;}}
@-webkit-keyframes fadecol{from {background-color:#00FF00;}to{background-color: #FFF;}}@keyframes fadecol{background-color: #00FF00;}to{background-color: #FFF;}}@-moz-keyframes fadecol{from{background-color: #00FF00;}to{background-color: #FFF;}}@-o-keyframes fadecol{background-color: #00FF00;}to{background-color: #FFF;}}
@-webkit-keyframes fadewrong{from {background-color:#FF0000;}to{background-color: #FFF;}}@keyframes fadewrong{background-color: #FF0000;}to{background-color: #FFF;}}@-moz-keyframes fadewrong{from{background-color: #FF0000;}to{background-color: #FFF;}}@-o-keyframes fadewrong{background-color: #FF0000;}to{background-color: #FFF;}}

13
timedifference.php Normal file
View File

@@ -0,0 +1,13 @@
<?php
$list = explode("/", htmlspecialchars(strtolower($_SERVER["REQUEST_URI"])));
if($list[1]==""||!isset($list[1])||count($list)<=1)$list="videos";
else $list=$list[1];
$list="lists/".$list.".json";
$data = json_decode(file_get_contents($list));
$diff = (time() - $data[1][0]);
$returnArray = array($diff, $data[0][0], time(), $data[1][0], $data[3][0], $data[4][0]);
$returnArray = json_encode($returnArray);
echo $returnArray;
?>

View File

@@ -1 +0,0 @@
["E37prdzWME4", "vYkwNZJJc4s", "Oi2jIyeTI3g"]

8
videos.php Normal file
View File

@@ -0,0 +1,8 @@
<?php
$list = htmlspecialchars($_REQUEST['list']);
if(!isset($_REQUEST['list']))$list="videos";
$filename = "lists/".$list.'.json';
if(!file_exists($filename)){ $f=fopen($filename, "a+"); fwrite($f,"[]"); fclose($f);}
$file = file_get_contents($filename);
print($file);
?>

5
visualize.js Normal file
View File

@@ -0,0 +1,5 @@
/*$(document).ready(function()
{
context = new AudioContext();
src = context.createMediaElementSource($('#player video'));
}*/

280
youtube.js Normal file
View File

@@ -0,0 +1,280 @@
/*
This is the youtube player sync and control file.
Fetcher sangen som spilles fra JSON filen
*/
var timeDifference;
var wasPaused;
var beginning;
var diffVideo;
var serverTime;
var url;
var response;
var url
var tag
var firstScriptTag;
var ytplayer;
var syncInterval;
var title;
var interval;
var viewers;
var changed = false;
$(document).ready(function()
{
window.mobilecheck = function() {
var check = false;
(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))check = true})(navigator.userAgent||navigator.vendor||window.opera);
return check; }
updateList();
timeDifference;
wasPaused = false;
beginning = true;
diffVideo = false;
interval = false;
response = $.ajax({ type: "GET",
url: "change.php",
async: false
}).responseText;
url = $.parseJSON(response);
$.ajax({
type: 'get',
url: 'timedifference.php',
data: "abcde",
async: false,
success: function(data) {
timeDifference = $.parseJSON(data);
}
});
console.log("timediff:"+timeDifference[0]);
response = url[0][0];
tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
syncInterval = setInterval(getTime, 5000);
listInterval = setInterval(updateList, 10000);
if(window.mobilecheck()){document.getElementById("search").blur();}
});
function onYouTubeIframeAPIReady() {
ytplayer = new YT.Player('player', {
height: window.height*0.75,
width: window.width*0.6,
videoId: response,
playerVars: { controls: "1" , iv_load_policy: "3", theme:"light", rel:"0", color:"white" },
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange,
'onError': errorHandler
}
});
}
/**
Legger sangen inn i <div>en, via swfobject
var params = { allowScriptAccess: "always"};
var atts = { id: "myytplayer" };
swfobject.embedSWF("http://www.youtube.com/v/"+response+"?enablejsapi=1&playerapiid=ytplayer&version=3&controls=1&iv_load_policy=3",
"ytapiplayer", "825", "462", "8", null, null, params, atts);
eventlistener for når playeren endres
*/
function onPlayerStateChange(newState) {
console.log("new state: "+newState.data);
console.log("beginning: "+beginning);
//ytplayer.seekTo(15);
if((newState.data == 0 && checkEnd()) || (newState.data == 1 && checkEnd()))
{
console.log("nummer 1");
startNextSong();
ytplayer.pauseVideo();
}else if(newState.data == 1 && (wasPaused && !beginning))
{
console.log("unpaused");
beginning = false;
wasPaused = false;
getTime();
}else if(newState.data == 2)
{
clearInterval(syncInterval);
interval = true;
wasPaused = true;
beginning = false;
}
}
function checkEnd()
{
console.log("sjekker om brukeren spolte");
$.ajax({
type: 'get',
url: 'timedifference.php',
data: "abcde",
async: false,
success: function(data) {
timeDifference = $.parseJSON(data);
}
});
if(parseInt(timeDifference[0]) > ytplayer.getDuration())
{
return true;
}
return false;
}
function startNextSong()
{
clearInterval(syncInterval);
//console.log(getTime());
if(checkEnd() && !changed)
{
setTimeout(function(){
response = $.ajax({
type: "POST",
url: "change.php",
async: false,
data: "thisUrl="+response+"&act=save",
success: function() {
console.log("saved song-switch - "+response);
}
}).responseText;
console.log("next video: "+response);
getTitle(response);
ytplayer.loadVideoById(response);
beginning = true;
syncInterval = setInterval(getTime, 5000);
},2500);
updateList();
changed = true
setTimeout(function() {
changed = false;
}, 2500);
}
}
function getTime()
{
if(!wasPaused)
{
console.log("sjekker om brukeren spolte");
$.ajax({
type: 'get',
url: 'timedifference.php',
data: "abcde",
async: false,
success: function(data) {
timeDifference = $.parseJSON(data);
}
});
console.log("current song: "+response);
console.log("song in database: "+timeDifference[1]);
if(parseInt(timeDifference[2]) + 1> ytplayer.getCurrentTime() + parseInt(timeDifference[3]) && ytplayer.getPlayerState() == 0)
{
return true;
}else if(ytplayer.getCurrentTime() + parseInt(timeDifference[3]) > parseInt(timeDifference[2]) + 5 || (ytplayer.getCurrentTime() + parseInt(timeDifference[3]) < parseInt(timeDifference[2]) - 5 && ytplayer.getPlayerState() != 0 && ytplayer.getPlayerState() != 3))
{
if(parseInt(timeDifference[0]) > ytplayer.getDuration())
{
console.log("burde ikke søke, men hoppe til neste sang");
}
ytplayer.seekTo(timeDifference[0]);
ytplayer.pauseVideo();
ytplayer.playVideo();
getTitle();
return false;
}
//if(interval){syncInterval = setInterval(getTime, 5000);interval = false;}
if(response != timeDifference[1])
{
clearInterval(syncInterval);
console.log("forskjellige videoer!!");
ytplayer.pauseVideo();
ytplayer.loadVideoById(timeDifference[1]);
setTimeout(function(){
//console.log(response);
diffVideo = true;
beginning = true;
$.ajax({
type: "POST",
url: "change.php",
async: false,
data: "thisUrl=123abcprompeprompe&act=save",
success: function(data)
{
response = timeDifference[1];
getTitle();
}
});
syncInterval = setInterval(getTime, 5000);
},2500);
}
}
}
function getTitle()
{
$.ajax({ type: "GET",
url: "timedifference.php",
async: false,
success: function(data) {
viewers = $.parseJSON(data);
var outPutWord = viewers[5] > 1 ? "viewers" : "viewer";
var title= viewers[4].replace(/\\\'/, "'");
document.title = viewers[4] + " • Zöff";
document.getElementsByName('v')[0].placeholder = viewers[4] + " • " + viewers[5] + " " + outPutWord;
}
});
}
function errorHandler(newState)
{
setTimeout(function(){
response = $.ajax({
type: "POST",
url: "change.php",
async: false,
data: "thisUrl="+response+"&act=delete",
success: function() {
console.log("error! deleted video");
}
}).responseText;
ytplayer.loadVideoById(response);
},2500);
/*
setTimeout(function(){
response = $.ajax({ type: "GET",
url: "change.php",
async: false
}).responseText;
var url = $.parseJSON(response);
response = url[0][0];
ytplayer.loadVideoById(response);
},2500);*/
}
function onPlayerReady(event) {
//ytplayer = document.getElementById("myytplayer");
// ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
//ytplayer.addEventListener("onError", "errorHandler");
getTime();
ytplayer.playVideo();
getTitle();
}