$result = mysql_query($newquery); if (mysql_num_rows($result) == 0) { $query = "DELETE FROM mp3act_currentsong"; mysql_query($query); if (file_exists("/tmp/mp3act")) { unlink("/tmp/mp3act"); } break; } else { $row = mysql_fetch_array($result); $pl_id = $row['pl_id']; updateNumPlays($row['song_id'], 0, $row['user_id']); setCurrentSong($row['song_id'], $row['pl_id']); playLocal($row['filename']); // could have changed $info = getCurrentSong('', ''); $pl_id = $info[2] == 0 ? 2147483647 : $info[1]; } } $query = "DELETE FROM mp3act_currentsong"; mysql_query($query); if (file_exists("/tmp/mp3act")) { unlink("/tmp/mp3act"); } } elseif ($_SERVER['argv'][1] == 4) { $query1 = "SELECT mp3act_songs.song_id,mp3act_songs.filename FROM mp3act_albums,mp3act_songs,mp3act_genres WHERE mp3act_albums.album_id=mp3act_songs.album_id AND mp3act_albums.album_genre=mp3act_genres.genre AND ("; for ($i = 3; $i < count($_SERVER['argv']); $i++) { $query1 .= " mp3act_genres.genre_id=" . $_SERVER['argv'][$i] . " OR"; } $query1 = preg_replace("/OR\$/", "", $query1); $query1 .= ") AND mp3act_songs.random!=1 ORDER BY RAND()+0 LIMIT 1";
} $loop = -1; if (substr($argv[1], 0, 4) == '-num') { $loop = intval(substr($argv[1], 4)); } if ($loop < 0 and loops()) { echo "_Are you sure you want to loop until the end while Spotify is on repeat? You must be mad. Please comment this out if you really want to do this."; exit(3); } // Start! $freq = []; $prevsong = false; $changetime = 170; //ms while ($loop != 0) { $song = getCurrentSong(); if ($song['trackid'] === $prevsong) { // The song did not change after nextSong() was called last. This means we're at the end and the last nextSong() made the music stop. if ($loop >= 0) { if ($changetime > 1500) { // 1500 is rather large, but necessary for remote playback. When playing locally, 500 or so should do fine. echo "_Err: see the warnings above. I've had enough; I'm giving up. You can go hit next by yourself.\n"; break; } $changetime *= 1.05; // some extra changing time echo "_Warn: uhm, the track did not change just now, but I'm not yet through with my -numX. I'll increase the latency to {$changetime}ms and continue like nothing happened.\n"; usleep(1000 * $changetime); // 200ms continue; }