diff --git a/lists/tritoen.json b/lists/tritoen.json index 5bdbd37d..d7d41ba7 100755 --- a/lists/tritoen.json +++ b/lists/tritoen.json @@ -1 +1 @@ -{"nowPlaying":{"5ryIHUSiOQA":{"id":"5ryIHUSiOQA","title":"Truls - The Next (Matoma Remix)","votes":0,"added":1414011510,"guids":[]}},"songs":{"Sb3XfrCtjVU":{"id":"Sb3XfrCtjVU","title":"The Notorious BIG ft. Ja Rule - Old Thing Back (Matoma Remix)","votes":0,"added":1414011510,"guids":[]},"YEx-QeYvE8Q":{"id":"YEx-QeYvE8Q","title":"L\u00f6wenherz & Freed - Tagtraum","votes":0,"added":1414011522,"guids":[]},"HAIDqt2aUek":{"id":"HAIDqt2aUek","title":"Porter Robinson - Sad Machine (Lyric Video)","votes":0,"added":1414011523,"guids":[]},"uhYMVwn3pJw":{"id":"uhYMVwn3pJw","title":"Bob Sinclar - Cinderella (She Said Her Name) - Official Video","votes":0,"added":1414011530,"guids":[]},"rvPGHb14__4":{"id":"rvPGHb14__4","title":"John Mayer - Waiting On The World To Change (Scheinizzl Remix)","votes":0,"added":1414011531,"guids":[]},"xi8_BuYT9UI":{"id":"xi8_BuYT9UI","title":"Mattafix - Big City Life (LEEX Remix)","votes":0,"added":1414011533,"guids":[]},"V40EjCjP3VU":{"id":"V40EjCjP3VU","title":"Philter - The Seven Seas","votes":0,"added":1414011950,"guids":[]},"vMwFFENUOQk":{"id":"vMwFFENUOQk","title":"Mandeh - Sandbank","votes":0,"added":1414012185,"guids":[]},"lCtozJkvyV8":{"id":"lCtozJkvyV8","title":"Sterk\u00f8l ","votes":0,"added":1414012436,"guids":[]},"FQvak0ZpfBA":{"id":"FQvak0ZpfBA","title":"Philter - The Protagonist","votes":0,"added":1414012633,"guids":[]},"nnjxb5NvAIk":{"id":"nnjxb5NvAIk","title":"Philter - Pi","votes":0,"added":1414012827,"guids":[]},"cV9dsOJXt3g":{"id":"cV9dsOJXt3g","title":"Notorious BIG - Juicy (Sh\u00e8mce Remix)","votes":0,"added":1414013114,"guids":[]},"fkLEljSKY30":{"id":"fkLEljSKY30","title":"IZ - Somewhere Over The Rainbow ( Thomas Jack Remix )","votes":0,"added":1414013497,"guids":[]},"lSooYPG-5Rg":{"id":"lSooYPG-5Rg","title":"Porter Robinson - Sea of Voices (Audio)","votes":0,"added":1414013802,"guids":[]},"si81bIoZRJQ":{"id":"si81bIoZRJQ","title":"Porter Robinson - Divinity ft. Amy Millan","votes":0,"added":1414014174,"guids":[]},"CUJcEYOjXI8":{"id":"CUJcEYOjXI8","title":"Philter - Flutterby","votes":0,"added":1414014353,"guids":[]},"FHCYHldJi_g":{"id":"FHCYHldJi_g","title":"Duke Dumont - I Got U (Official video) ft. Jax Jones","votes":0,"added":1414014596,"guids":[]},"VHoT4N43jK8":{"id":"VHoT4N43jK8","title":"Stromae - Alors On Danse","votes":0,"added":1414014891,"guids":[]},"eg5sRQNEwtg":{"id":"eg5sRQNEwtg","title":"Philter - Love","votes":0,"added":1414015111,"guids":[]},"oiKj0Z_Xnjc":{"id":"oiKj0Z_Xnjc","title":"Stromae - Papaoutai","votes":0,"added":1414015348,"guids":[]},"ublchJYzhao":{"id":"ublchJYzhao","title":"Stromae - ta f\u00eate","votes":0,"added":1414015554,"guids":[]}},"conf":{"startTime":1414015554,"views":2,"skips":[],"delsongs":false}} \ No newline at end of file +{"nowPlaying":{"lCtozJkvyV8":{"id":"lCtozJkvyV8","title":"Sterk\u00f8l ","votes":0,"added":1414012436,"guids":[]}},"songs":{"FQvak0ZpfBA":{"id":"FQvak0ZpfBA","title":"Philter - The Protagonist","votes":0,"added":1414012633,"guids":[]},"nnjxb5NvAIk":{"id":"nnjxb5NvAIk","title":"Philter - Pi","votes":0,"added":1414012827,"guids":[]},"cV9dsOJXt3g":{"id":"cV9dsOJXt3g","title":"Notorious BIG - Juicy (Sh\u00e8mce Remix)","votes":0,"added":1414013114,"guids":[]},"fkLEljSKY30":{"id":"fkLEljSKY30","title":"IZ - Somewhere Over The Rainbow ( Thomas Jack Remix )","votes":0,"added":1414013497,"guids":[]},"lSooYPG-5Rg":{"id":"lSooYPG-5Rg","title":"Porter Robinson - Sea of Voices (Audio)","votes":0,"added":1414013802,"guids":[]},"si81bIoZRJQ":{"id":"si81bIoZRJQ","title":"Porter Robinson - Divinity ft. Amy Millan","votes":0,"added":1414014174,"guids":[]},"CUJcEYOjXI8":{"id":"CUJcEYOjXI8","title":"Philter - Flutterby","votes":0,"added":1414014353,"guids":[]},"FHCYHldJi_g":{"id":"FHCYHldJi_g","title":"Duke Dumont - I Got U (Official video) ft. Jax Jones","votes":0,"added":1414014596,"guids":[]},"VHoT4N43jK8":{"id":"VHoT4N43jK8","title":"Stromae - Alors On Danse","votes":0,"added":1414014891,"guids":[]},"eg5sRQNEwtg":{"id":"eg5sRQNEwtg","title":"Philter - Love","votes":0,"added":1414015111,"guids":[]},"oiKj0Z_Xnjc":{"id":"oiKj0Z_Xnjc","title":"Stromae - Papaoutai","votes":0,"added":1414015348,"guids":[]},"ublchJYzhao":{"id":"ublchJYzhao","title":"Stromae - ta f\u00eate","votes":0,"added":1414015554,"guids":[]},"5ryIHUSiOQA":{"id":"5ryIHUSiOQA","title":"Truls - The Next (Matoma Remix)","votes":0,"added":1414015747,"guids":[]},"Sb3XfrCtjVU":{"id":"Sb3XfrCtjVU","title":"The Notorious BIG ft. Ja Rule - Old Thing Back (Matoma Remix)","votes":0,"added":1414016072,"guids":[]},"YEx-QeYvE8Q":{"id":"YEx-QeYvE8Q","title":"L\u00f6wenherz & Freed - Tagtraum","votes":0,"added":1414016380,"guids":[]},"HAIDqt2aUek":{"id":"HAIDqt2aUek","title":"Porter Robinson - Sad Machine (Lyric Video)","votes":0,"added":1414016642,"guids":[]},"uhYMVwn3pJw":{"id":"uhYMVwn3pJw","title":"Bob Sinclar - Cinderella (She Said Her Name) - Official Video","votes":0,"added":1414016836,"guids":[]},"rvPGHb14__4":{"id":"rvPGHb14__4","title":"John Mayer - Waiting On The World To Change (Scheinizzl Remix)","votes":0,"added":1414017132,"guids":[]},"xi8_BuYT9UI":{"id":"xi8_BuYT9UI","title":"Mattafix - Big City Life (LEEX Remix)","votes":0,"added":1414017509,"guids":[]},"V40EjCjP3VU":{"id":"V40EjCjP3VU","title":"Philter - The Seven Seas","votes":0,"added":1414017748,"guids":[]},"vMwFFENUOQk":{"id":"vMwFFENUOQk","title":"Mandeh - Sandbank","votes":0,"added":1414017982,"guids":[]}},"conf":{"startTime":1414017982,"views":2,"skips":[],"delsongs":false}} \ No newline at end of file diff --git a/php/change.php b/php/change.php index d81a56f6..87145fca 100755 --- a/php/change.php +++ b/php/change.php @@ -1,59 +1,59 @@ array(), "songs" => array(), "conf" => array("startTime" => time(), "views" => 0, "skips" => array())); -$array = json_encode($array); -$f = @fopen($list,"x"); -if($f){ fwrite($f,$array); fclose($f); } -$file = file_get_contents($list); -$data = json_decode($file, TRUE); -$songs = $data["songs"]; +$array = json_encode($array); //encoding the array +$f = @fopen($list,"x"); //opening a file, ignoring warnings +if($f){ fwrite($f,$array); fclose($f); } //if the file doesn't exist, we create a new one, and adds the newly made array there +$file = file_get_contents($list); //gets the content of the file +$data = json_decode($file, TRUE); //decoding the file. The true is there for array comprehension in php or something. Don't remove! +$songs = $data["songs"]; //setting the now playing and the next song in the next couplecouple of lines $np = $data["nowPlaying"]; $np = array_values($np); $firstSong = array_values($songs); -$save = false; - +$save = false; //declares the save variable, see further down for why +//If test for either saving when the song is done, or an error has occured if(isset($_REQUEST['thisUrl'])){ - $string = $_REQUEST['thisUrl']; - $action = isset($_REQUEST['act']); - $firstToAdd = $firstSong[0]["id"]; - if($np[0]["id"] == $string) + $string = $_REQUEST['thisUrl']; //saving string as the id of the song + $action = isset($_REQUEST['act']); //checking the action of the request, either save or del + $firstToAdd = $firstSong[0]["id"]; //getting the id of the first in the queue + if($np[0]["id"] == $string) //if the string we're sending in matches the id of the song playing now, we proceed { - if($action=="save" || $action == "empty"){ //next song - $save = true; + if($action=="save" || $action == "empty"){ //action save or empty, either way goes further + $save = true; //small fix for the editing of viewers. Explain later in file. //array_shift($data["songs"]); //array_shift($data["nowPlaying"]); - if(!is_null($np[0]["id"]) && !is_null($firstToAdd)){ - array_shift($data["songs"]); + if(!is_null($np[0]["id"]) && !is_null($firstToAdd)){ //Checking both the next song and the song playing now is null, if so it just skips the flipping around with songs + array_shift($data["songs"]); //already shifts the array of songs, because we have the first in the queue saved $q = $data["conf"]; - $q = array_key_exists("removeplay", $q); - if(!$data["conf"]["removeplay"] || $q != 1) - { + $q = array_key_exists("removeplay", $q); + if(!$data["conf"]["removeplay"] || $q != 1) //checking if removeplay exists or if its false. If its true, the song we just played won't be added to the queue + { //here we just adds the song that was just played into the queue in the songs array, take note here we set added as the current time it was added. This is because of the multisort further down $data["songs"][$np[0]["id"]] = array("id" => $np[0]["id"], "title" => $np[0]["title"], "votes" => $np[0]["votes"], "added" => time(), "guids" => array()); } - array_shift($data["nowPlaying"]); + array_shift($data["nowPlaying"]); //shifting the nowPlaying array, and moving the first in line to the nowPlaying array $data["nowPlaying"][$firstSong[0]["id"]] = array("id" => $firstSong[0]["id"], "title" => $firstSong[0]["title"], "votes" => 0, "added" => $firstSong[0]["added"], "guids" => $firstSong[0]["guids"]); } //array_push($data["songs"], $add); - $data["conf"]["skips"] = array(); - $data["conf"]["startTime"] = time(); - $data["conf"]["views"] = 1; - foreach($data["songs"] as $k=>$v) { + $data["conf"]["skips"] = array(); //resets the skip count + $data["conf"]["startTime"] = time(); //resets the starttime of the song so it will be sorted accordingly + $data["conf"]["views"] = 1; //resets the views ??must be fixed.. + foreach($data["songs"] as $k=>$v) { //the next 5 lines of code is just for sorting the array with highest votes at the top, and the lowest time added at the top, so that the voting will be alot more fair $sort['votes'][$k] = $v['votes']; $sort['added'][$k] = $v['added']; } @@ -62,102 +62,99 @@ if(isset($_REQUEST['thisUrl'])){ /* else if($action=="delete"){ array_shift($firstSong[0]); }*/ - file_put_contents($list, json_encode($data)); - }else if(is_null($np[0]["id"])) + file_put_contents($list, json_encode($data)); //sending the encoded json array to the file + }else if(is_null($np[0]["id"])) //if nowPlaying is null, it just moves the first song in the queue up { array_shift($data["songs"]); - //$data["songs"][$np[0]["id"]] = array("id" => $np[0]["id"], "title" => $np[0]["title"], "votes" => $np[0]["votes"], "added" => time(), "guids" => array()); array_shift($data["nowPlaying"]); $data["nowPlaying"][$firstSong[0]["id"]] = array("id" => $firstSong[0]["id"], "title" => $firstSong[0]["title"], "votes" => 0, "added" => $firstSong[0]["added"], "guids" => $firstSong[0]["guids"]); } - if($action == "save" && !$save) //count views + if($action == "save" && !$save) //count views { $data["conf"]["views"] = $data["conf"]["views"] + 1; file_put_contents($list, json_encode($data)); } - $newPlaying = array_values($data["nowPlaying"]); - echo $newPlaying[0]["id"]; + $newPlaying = array_values($data["nowPlaying"]); //returning the new songs id to the javascript so it gets what song to start next + echo $newPlaying[0]["id"]; } -else if(isset($_GET['v'])){ //add +else if(isset($_GET['v'])){ //if it gets v, we start our add "function" $q = $data["conf"]; $q = array_key_exists("addsongs", $q); - if($q != 1 || $data["conf"]["addsongs"] == "false") + if($q != 1 || $data["conf"]["addsongs"] == "false") //checking wether it has been set so only admins can add songs. If its false, or the value doesn't exist, we continue { - $video = htmlspecialchars($_GET['v']); - $name = htmlspecialchars($_GET['n']); - if(!in_array($video, $data["songs"])) + $video = htmlspecialchars($_GET['v']); //id of the video + $name = htmlspecialchars($_GET['n']); //name of the video + if(!in_array($video, $data["songs"])) //checking if the video already is in the array of songs (should check the now playing to) { - if(count($data["nowPlaying"]) > 0) $place = "songs"; - else $place = "nowPlaying"; + if(count($data["nowPlaying"]) > 0) $place = "songs"; //checking if the nowPlaying array is empty, if it is, the "place" to add it is nowPlaying, if not it is songs + else $place = "nowPlaying"; //Adding to the array $data[$place][$video] = array("id" => $video, "title" => $name, "votes" => 0, "added" => time(), "guids" => array()); - $data[$place][$video]["votes"] = 1; - array_push($data[$place][$video]["guids"], $guid); - $sort = array(); + $data[$place][$video]["votes"] = 1; //Upping the votes, so it comes further up than the ones already played + array_push($data[$place][$video]["guids"], $guid); //adding the users GUID to the array so he can't vote infinite times if($place != "nowPlaying") { + $sort = array(); foreach($data["songs"] as $k=>$v) { - $sort['votes'][$k] = $v['votes']; + $sort['votes'][$k] = $v['votes']; //Again sorting, explained further up $sort['added'][$k] = $v['added']; } array_multisort($sort['votes'], SORT_DESC, $sort['added'], SORT_ASC, $data["songs"]); } file_put_contents($list, json_encode($data)); - print("added"); + print("added"); //Just telling the javascript that it has been added for some reason... } } } -else if(isset($_GET['vote'])){ //add vote - $vote=$_GET['vote']; - $id=$_GET['id']; - //$i = array_search($id, $data["songs"]); - //$i = array_search($id, array_keys($data["songs"])) - if($vote=='del'){ +else if(isset($_GET['vote'])){ //if the getvaluethingy is vote, this starts + $vote=$_GET['vote']; //The javascript either sends in neg or pos, this is where we save the value + $id=$_GET['id']; //id of the video/song the user is voting for + if($vote=='del'){ //This is so we don't have to make a seperate function for the delete $pass=$_GET['pass']; $x = explode("/", htmlspecialchars(strtolower($_SERVER["REQUEST_URI"]))); $pass=crypt($pass, '$6$rounds=9001$'.$x[1].'Fuck0ffuSn34kyn!ggerzZ$'); $adminpass='$6$rounds=9001$tritoenFuck0ffuS$si2Hi95ghCxSbVAfgeBN0dVzf5DTn1mQoizOuLEzr0N2q6fclGLrapscJQA0PsA2F0TlG5q0YAYrPHy9dZxpj0'; //$data["conf"]["admin"]; - if($adminpass == $pass){ + if($adminpass == $pass){ //checking if the password is correct, then deleting the song (this is not in use yet.) unset($data["songs"][$id]); file_put_contents($list, json_encode($data)); echo "removed song with ID: ".$id." from list: ".$list; } - }else + }else //if we don't get the del, we're voting, WOHO! { - if($vote == 'neg'){$voteAdd = -1;} - else if($vote == 'pos'){$voteAdd = 1;} + if($vote == 'neg'){$voteAdd = -1;} //setting the votetoadd to the array depending of what way you swing. + else if($vote == 'pos'){$voteAdd = 1;} //checking if the key exists in the array, and if we're already voted if(array_key_exists($id, $data["songs"]) && !in_array($guid, $data["songs"][$id]["guids"])) - { + { //finally adding the vote to the votings $data["songs"][$id]["votes"] = $data["songs"][$id]["votes"] + $voteAdd; - if($data["songs"][$id]["votes"] > -1) + if($data["songs"][$id]["votes"] > -1) //but only if we're still above or equal to 0 { - $data["songs"][$id]["added"] = time(); - array_push($data["songs"][$id]["guids"], $guid); + $data["songs"][$id]["added"] = time(); //updating the added time, so it comes on the bottom of its own "level" of votes + array_push($data["songs"][$id]["guids"], $guid); //pushing the users guid to the array so he/she can't vote again foreach($data["songs"] as $k=>$v) { - $sort['votes'][$k] = $v['votes']; + $sort['votes'][$k] = $v['votes']; //again, sorting $sort['added'][$k] = $v['added']; } array_multisort($sort['votes'], SORT_DESC, $sort['added'], SORT_ASC, $data["songs"]); file_put_contents($list, json_encode($data)); - echo "Vote registrated. I hope"; + echo "Vote registrated. I hope"; } }else { - echo array_key_exists($id, $data["songs"]); + echo array_key_exists($id, $data["songs"]); //not in use..i think.. } } } -else if(isset($_GET['skip'])){ //skip song request +else if(isset($_GET['skip'])){ //skip, really similar to the save function, not going in depth here. $viewers=$data["conf"]["views"]; - $skips=count($data["conf"]["skips"]); - if(!in_array($guid, $data["conf"]["skips"])){ + $skips=count($data["conf"]["skips"]); //Counting how many GUIDS there are under the skip key + if(!in_array($guid, $data["conf"]["skips"])){ //If the users GUID isn't in the array, its added array_push($data["conf"]["skips"], $guid); - $skips+=1; + $skips+=1; //and the number of skips is upped //$data["conf"]["skips"]=$skips; - if($skips>=$viewers/2){ + if($skips>=$viewers/2){ //checking if the skips wanted is larger than the viewers/2, if so its skipping, woohooo! array_shift($data["songs"]); $q = $data["conf"]; $q = array_key_exists("removeplay", $q); @@ -179,11 +176,11 @@ else if(isset($_GET['skip'])){ //skip song request } file_put_contents($list, json_encode($data)); } - echo($skips."/".$viewers); + echo($skips."/".$viewers); //always printing out the skip/viewer ratio -}else if(isset($_POST['conf'])) +}else if(isset($_POST['conf'])) //conf, this is for admin settings/channel settings { - $data["conf"]["vote"] = $_POST['vote']; + $data["conf"]["vote"] = $_POST['vote']; //setting all the settings from the post gotten from admin.js $data["conf"]["addsongs"] = $_POST['addsongs']; $data["conf"]["longsongs"] = $_POST['longsongs']; $$data["conf"]["frontpage"] = $_POST['frontpage']; @@ -202,22 +199,29 @@ else if(isset($_GET['skip'])){ //skip song request //$data["conf"]["frontpage"] = $frontpage; //$data["conf"]["onlymusic"] = $onlymusic; //$data["conf"]["removeplay"] = $removeplay; - if($data["conf"]["adminpass"] == $pass || $q != 1) + if($data["conf"]["adminpass"] == $pass || $q != 1) //if the password is the same as the one in the jsonfile, we are updating the settings (not in use yet) { echo "correct"; file_put_contents($list, json_encode($data)); } -}else if(isset($_GET['timedifference'])){ +}else if(isset($_GET['timedifference'])){ //deprecated i think $diff = (time() - $data["conf"]["startTime"]); $returnArray = array($diff, $firstSong[0]["id"], time(), $data["conf"]["startTime"], $firstSong[0]["title"], $data["conf"]["views"]); $returnArray = json_encode($returnArray); - echo($data); -}else{ + echo($data); +}else{ //printing the whole data array json encoded for youtube.js or list.js to pick up echo json_encode($data); } -function addSong($name, $id, $title) +// +// +//None of these are in use any more/yet +// +// +// + +function addSong($name, $id, $title) { } @@ -227,7 +231,7 @@ function nextSong(){ array_push($data[0], $data[0][0]); array_shift($data[0]); - array_push($data[2], 0); //reset votes + array_push($data[2], 0); array_shift($data[2]); array_push($data[3], $data[3][0]);