$jzUSER->storePlaylist($pl); if (!defined('NO_AJAX_JUKEBOX')) { $blocks = new jzBlocks(); $blocks->playlistDisplay(); exit; } } } else { $pl = new jzPlaylist(); $pl->addFromForm(); $pl->flatten(); if (isset($_POST['limit'])) { $pl->truncate($_POST['limit']); } if (isset($_POST['sendListRandom'])) { $pl->shuffle(); } $pl->play(); } } } } } if ($exit) { exit; } break; case "playlistAction": writeLogData("messages", "Index: Preforming a playlist action"); if ($jzUSER->getSetting('stream') === false && $jzUSER->getSetting('lofi') === false && $jzUSER->getSetting('download') === false) { exit;
/** * 'Intelligently' creates a random playlist from the given list. * * @author Ben Dodson * @param The number of elements to return * @param type the type of the playlist. * * false - equally weights tracks * radio - creates a radio from the given artist playlist should only contain 1 artist) */ function getSmartPlaylist($count = 0, $type = "equi-track") { global $max_playlist_length, $jzSERVICES; if ($type == "radio") { if ($count == 0) { $lim = false; } else { $lim = $count; } $el = $this->getAt(0); $mainArray = $el->getSubNodes("tracks", -1, true, $lim); // Now let's get the top 5 similar artists $simArray = $jzSERVICES->getSimilar($el); $simArray = seperateSimilar($simArray); $i = 0; $limit = 6; // Now let's shuffle $similarArray = array(); for ($e = 0; $e < count($simArray['matches']); $e++) { if (isset($simArray['matches'][$e])) { // Ok, this is one that we want, let's get it's path $simArt = $simArray['matches'][$e]; if ($lim) { $subArray = $simArt->getSubNodes("tracks", -1, true, ceil($lim / 4)); } else { $subArray = $simArt->getSubNodes("tracks", -1, true); } $similarArray = array_merge($similarArray, $subArray); $i++; if ($limit) { if ($i > $limit) { break; } } } } $finArray = array_merge($similarArray, $mainArray); $pl =& new jzPlaylist($finArray); $pl->shuffle(); $pl->truncate($lim); return $pl; } //*****************// // default 'smartPlaylist' $trackcount = $this->getTrackCount(); if ($count <= 0) { $count = $trackcount; } if ($trackcount <= $count) { $pl = $this; $pl->flatten(); $pl->shuffle(); $pl->truncate($max_playlist_length); return $pl; } $pl = new jzPlaylist(); $numbers = range(0, $trackcount - 1); srand((double) microtime() * 1000000); $numbers = array_rand($numbers, $count); $size_list = array(); $list = $this->getList(); if ($list[0]->getType() == "jzMediaTrack") { $size_list[0] = 1; } else { if ($list[0]->getType() == "jzMediaNode") { $size_list[0] = $list[0]->getSubNodeCount("tracks", -1); } else { $size_list[0] = $list[0]->getTrackCount(); } } for ($i = 1; $i < sizeof($list); $i++) { if ($list[$i]->getType() == "jzMediaTrack") { $size_list[$i] = 1 + $size_list[$i - 1]; } else { if ($list[$i]->getType() == "jzMediaNode") { $size_list[$i] = $size_list[$i - 1] + $list[$i]->getSubNodeCount("tracks", -1); } else { $size_list[$i] = $size_list[$i - 1] + $list[$i]->getTrackCount(); } } } $element_count = array(); for ($i = 0; $i < sizeof($list); $i++) { $element_count[$i] = 0; } $j = 0; for ($i = 0; $i < sizeof($numbers); $i++) { if ($numbers[$i] < $size_list[$j]) { $element_count[$j]++; } else { $j++; $i--; } } $final = array(); for ($i = 0; $i < sizeof($list); $i++) { if ($element_count[$i] > 0) { switch ($list[$i]->getType()) { case "jzMediaNode": $final = array_merge($final, $list[$i]->getSubNodes("tracks", -1, true, $element_count[$i])); break; case "jzMediaTrack": $final[] = $list[$i]; break; default: $more = $list[$i]; $more->flatten(); $more->shuffle(); $more->truncate($element_count[$i]); $final = array_merge($final, $more); break; } } } $pl->add($final); $pl->shuffle(); return $pl; // for ($i = 0; $i < $count; $i++) { // $pl->add($this->getAt($numbers[$i],"track")); // Too slow... //} }