Skip to content

Commit

Permalink
Merge pull request #785 from xn--nding-jua/AppendFileToPlaylist
Browse files Browse the repository at this point in the history
Append file to playlist
  • Loading branch information
MiczFlor authored Apr 14, 2020
2 parents dbe808b + d942176 commit 8837fea
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
36 changes: 36 additions & 0 deletions htdocs/api/playlist/appendFileToPlaylist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
namespace JukeBox\Api;

/**
* Appends a given file to the current playlist (and starts playing)
*/
include('../common.php');

/*
* debug? Conf file line:
* DEBUG_WebApp_API="TRUE"
*/
$debugLoggingConf = parse_ini_file("../../../settings/debugLogging.conf");
if($debugLoggingConf['DEBUG_WebApp_API'] == "TRUE") {
file_put_contents("../../../logs/debug.log", "\n# WebApp API # " . __FILE__ , FILE_APPEND | LOCK_EX);
file_put_contents("../../../logs/debug.log", "\n # \$_SERVER['REQUEST_METHOD']: " . $_SERVER['REQUEST_METHOD'] , FILE_APPEND | LOCK_EX);
}

if ($_SERVER['REQUEST_METHOD'] === 'PUT') {
$body = file_get_contents('php://input');
if($debugLoggingConf['DEBUG_WebApp_API'] == "TRUE") {
file_put_contents("../../../logs/debug.log", "\n # \$body: " . $body , FILE_APPEND | LOCK_EX);
}
execScriptWithoutCheck("playout_controls.sh -c=playlistappend -v='{$body}'");
} else {
$file = $_GET["file"];
if ($file !== "") {
print "Playing file " . $file;
execScriptWithoutCheck("playout_controls.sh -c=playlistappend -v='$file'");
}else{
http_response_code(405);
}
}

?>

1 change: 1 addition & 0 deletions htdocs/func.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ function printPlaylistHtml($files)
print "
<li class='list-group-item'>".$counter++." :
<a onclick='playSingleFile(\"$file\");' class='btn-panel-small btn-panel-col' title='Play song' style='cursor: pointer'><i class='mdi mdi-play-circle-outline'></i></a>
<a onclick='appendFileToPlaylist(\"$file\");' class='btn-panel-small btn-panel-col' title='Append song to playlist' style='cursor: pointer'><i class='mdi mdi-plus-circle-outline'></i></a>
<strong>".basename($file)."</strong>";
if(basename($file) != "livestream.txt" && basename($file) != "podcast.txt" && basename($file) != "spotify.txt") {
print"
Expand Down
10 changes: 10 additions & 0 deletions htdocs/js/jukebox.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ function playSongInPlaylist(song) {
});
}

function appendFileToPlaylist(file) {
$.ajax({
url: `api/playlist/appendfiletoplaylist.php`,
method: 'PUT',
data: file.toString()
}).success(data => {
loadStatus();
});
}

function playSingleFile(file) {
$.ajax({
url: `api/playlist/playsinglefile.php`,
Expand Down
2 changes: 2 additions & 0 deletions htdocs/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ function iterate_dir($path) {
print "<li class='list-group-item'>" .
"<a onclick='playSingleFile(\"$file\");' class='btn-panel-small btn-panel-col' title='Play song' style='cursor: pointer'>
<i class='mdi mdi-play-circle-outline'></i></a>
<a onclick='appendFileToPlaylist(\"$file\");' class='btn-panel-small btn-panel-col' title='Append song to playlist'
style='cursor: pointer'> <i class='mdi mdi-plus-circle-outline'></i></a>
<strong>".basename($file)."</strong>";
print "&nbsp;&nbsp; <a href='trackEdit.php?folder=".dirname($file)."&filename=".basename($file)."'><i class='mdi mdi-text'></i> Edit</a>";
print "</li>";
Expand Down
5 changes: 5 additions & 0 deletions scripts/playout_controls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ NOW=`date +%Y-%m-%d.%H:%M:%S`
# playlistclear
# playlistaddplay
# playlistadd
# playlistappend
# playsinglefile
# getidletime
# setidletime
Expand Down Expand Up @@ -451,6 +452,10 @@ case $COMMAND in
# save playlist playing
mpc load "${VALUE}"
;;
playlistappend)
mpc add "${VALUE}"
mpc play
;;
playsinglefile)
mpc clear
mpc add "${VALUE}"
Expand Down

0 comments on commit 8837fea

Please sign in to comment.