Skip to content

Commit

Permalink
added support for mic break in CSV import
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketMan committed Jan 19, 2025
1 parent b890975 commit 752d90f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
27 changes: 26 additions & 1 deletion ui/Playlists.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zookeeper Online
*
* @author Jim Mason <[email protected]>
* @copyright Copyright (C) 1997-2024 Jim Mason <[email protected]>
* @copyright Copyright (C) 1997-2025 Jim Mason <[email protected]>
* @link https://zookeeper.ibinx.com/
* @license GPL-3.0
*
Expand Down Expand Up @@ -58,6 +58,7 @@ class Playlists extends MenuItem {

private $action;
private $subaction;
private $break;

public function getSubactions($action) {
return self::$subactions;
Expand Down Expand Up @@ -399,11 +400,28 @@ public function emitEditor() {
}

private function insertTrack($playlistId, $tag, $artist, $track, $album, $label, $spinTime) {
// $artist, $track, $album, and $label have already been trimmed
if(empty($artist) && empty($track) &&
empty($album) && empty($label)) {
// non-consecutive blank row inserts set separator
if(!$this->break) {
$entry = (new PlaylistEntry())->setSetSeparator();
if($spinTime)
$entry->setCreated($spinTime->format(IPlaylist::TIME_FORMAT_SQL));
Engine::api(IPlaylist::class)->insertTrackEntry($playlistId, $entry, $status);
$this->break = true;
}
return;
}

$id = 0;
$status = '';
// Run the query
$success = Engine::api(IPlaylist::class)->insertTrack($playlistId,
$tag, $artist, $track, $album, $label, $spinTime, $id, $status);

if($success)
$this->break = false;
}

public function emitImportList() {
Expand Down Expand Up @@ -643,6 +661,13 @@ public function emitImportList() {
$timestamp); // timestamp
$count++;
break;
case 1:
// fgetcsv returns array with single null on blank line
if(is_null($line[0])) {
// set separator
$this->insertTrack($playlist, 0, '', '', '', '', null);
}
break;
}
}
// echo "<B>Imported $count tracks.</B>\n";
Expand Down
2 changes: 1 addition & 1 deletion ui/templates/default/list/import.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ <h4>CSV Format</h4>
<pre style='padding-left: 20px; white-space: normal;'><b>artist&nbsp; track&nbsp; album&nbsp; label</b> &nbsp;<i>or</i><br>
<b>artist&nbsp; track&nbsp; album&nbsp; tag&nbsp;&nbsp; label</b> &nbsp;<i>or</i><br>
<b>artist&nbsp; track&nbsp; album&nbsp; tag&nbsp;&nbsp; label&nbsp; timestamp</b></pre>
<p>where each column is optionally enclosed by the specified field enclosure character, and separated by a delimiter character. If no delimiter is specified, tab is used.</p>
<p>where each column is optionally enclosed by the specified field enclosure character, and separated by a delimiter character. If no delimiter is specified, tab is used. An empty row inserts a mic break.</p>
<p>Any file data not in this format will be ignored.</p>
</div>
</div>
Expand Down

0 comments on commit 752d90f

Please sign in to comment.