예제 #1
0
파일: functions.php 프로젝트: bycEEE/env
/**
 * addTracksToPlaylist function.
 *
 * @access public
 * @param mixed $w
 * @param mixed $tracks
 * @param mixed $playlist_uri
 * @param mixed $playlist_name
 * @param bool $allow_duplicate (default: true)
 * @param bool $refreshLibrary (default: true)
 * @return void
 */
function addTracksToPlaylist($w, $tracks, $playlist_uri, $playlist_name, $allow_duplicate = true, $refreshLibrary = true)
{
    //
    // Read settings from JSON
    //
    $settings = getSettings($w);
    $userid = $settings->userid;
    $tracks_with_no_dup = array();
    if (!$allow_duplicate) {
        $playlist_tracks = getThePlaylistTracks($w, $playlist_uri);
        foreach ((array) $tracks as $track) {
            if (!checkIfDuplicate($playlist_tracks, $track)) {
                $tracks_with_no_dup[] = $track;
            }
        }
        $tracks = $tracks_with_no_dup;
    }
    if (count($tracks) != 0) {
        try {
            $api = getSpotifyWebAPI($w);
            $tmp = explode(':', $playlist_uri);
            // Note: max 100 Ids
            $offset = 0;
            $i = 0;
            do {
                $output = array_slice($tracks, $offset, 100);
                $offset += 100;
                if (count($output)) {
                    // refresh api
                    $api = getSpotifyWebAPI($w, $api);
                    $api->addUserPlaylistTracks(urlencode($userid), $tmp[4], $output, array('position' => 0));
                    $i++;
                }
                /*
                if($i % 30 === 0) {
                sleep(60);
                echo "Info: Throttling in addTracksToPlaylist";
                }
                */
            } while (count($output) > 0);
        } catch (SpotifyWebAPI\SpotifyWebAPIException $e) {
            logMsg("Error(addTracksToPlaylist): (exception " . print_r($e) . ")");
            handleSpotifyWebAPIException($w, $e);
            return false;
        }
        if ($refreshLibrary) {
            refreshLibrary($w);
        }
    }
    return count($tracks);
}
예제 #2
0
     break;
 case 'upvote_Row':
     if (!empty($postdec['id'])) {
         $response = upvoteRow($postdec['id']);
         //returns true if successful, false otherwise
     }
     break;
 case 'downvote_Row':
     if (!empty($postdec['id'])) {
         $response = downvoteRow($postdec['id']);
         //returns true if successful, false otherwise
     }
     break;
 case 'check_IfDuplicate':
     if (!empty($postdec['create_shittalk_Text'])) {
         $response = checkIfDuplicate($postdec['create_shittalk_Text']);
         //returns true if successful, false otherwise
     }
     break;
 case 'get_RandomRows':
     if (!empty($postdec['limit'])) {
         $response = getRandomRows($postdec['limit']);
         //returns true if successful, false otherwise
     }
     break;
 case 'get_RateMoreTableRows':
     $response = createRateMoreTableRows();
     //returns an array of table rows
     break;
 case 'get_RandomList':
     $response = getRandomList();