Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mic break support to CSV import #500

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading