Skip to content

Commit

Permalink
Merge branch 'develop' into patch-4
Browse files Browse the repository at this point in the history
  • Loading branch information
MiczFlor authored Jul 16, 2020
2 parents 944c0b3 + e42963e commit 63e4af7
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 54 deletions.
2 changes: 1 addition & 1 deletion components/gpio_control/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ else
done

fi
chown -R ${SUDO_USER}:${SUDO_USER} $FILE
chown -R ${SUDO_USER}:${SUDO_USER} $USER_HOME/.config/phoniebox/

echo
echo 'Installing GPIO_Control service, this will require to enter your password up to 3 times to enable the service'
Expand Down
7 changes: 6 additions & 1 deletion htdocs/ajax.loadMopidyStatus.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
$mopidystatus = exec("systemctl status mopidy | grep 'Active: '| sed 's/Active: //g'");
$mopidyserverstatus = exec("echo -e status\\nclose | nc -w 1 localhost 6600 | grep 'OK MPD'| sed 's/^.*$/ACTIVE/'");
if ($mopidyserverstatus == "ACTIVE") {
$mopidystatus = "Mopidy.Server: Connected<br>Mopidy.Service: " . exec("systemctl status mopidy | grep 'Active: '| sed 's/Active: //g'");
} else {
$mopidystatus = "Mopidy.Server: Disconnected!<br>Mopidy.Service: " . exec("systemctl status mopidy | grep 'Active: '| sed 's/Active: //g'");
}
?>
<div class="col-md-6"><?php echo trim($mopidystatus); ?></div>
33 changes: 30 additions & 3 deletions htdocs/func.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,29 @@ function index_folders_print($item, $key)
print '<img class="img-playlist-item-placeholder" src="" alt=""/>';
}
*/

/* filter */
if (in_array($contentTree[$key]['path_abs']."/spotify.txt", $contentTree[$key]['files'])) {
print "
<div class='filterDiv spotify col-md-12'>";

} elseif (in_array($contentTree[$key]['path_abs']."/livestream.txt", $contentTree[$key]['files'])) {
print "
<div class='filterDiv livestream col-md-12'>";

} elseif (in_array($contentTree[$key]['path_abs']."/podcast.txt", $contentTree[$key]['files'])) {
print "
<div class='filterDiv podcast col-md-12'>";

} elseif (in_array($contentTree[$key]['path_abs']."/youtube.txt", $contentTree[$key]['files'])) {
print "
<div class='filterDiv youtube col-md-12'>";

} else {
print "
<div class='filterDiv file col-md-12'>";
}

print "
<div class='panel ".$panelStyle."'>";

Expand All @@ -332,7 +355,7 @@ function index_folders_print($item, $key)
print "
<a onclick='playPlaylist(\"$playlist\", \"true\");' class='btn-panel-big btn-panel-col pb-plist-play' title='Play (sub)folders'><i class='mdi mdi-animation-play-outline'></i></a>";
}
if (!in_array($contentTree[$key]['path_abs']."/livestream.txt", $contentTree[$key]['files']) && !in_array($contentTree[$key]['path_abs']."/spotify.txt", $contentTree[$key]['files']) && !in_array($contentTree[$key]['path_abs']."/podcast.txt", $contentTree[$key]['files']) ) {
if (!in_array($contentTree[$key]['path_abs']."/livestream.txt", $contentTree[$key]['files']) && !in_array($contentTree[$key]['path_abs']."/spotify.txt", $contentTree[$key]['files']) && !in_array($contentTree[$key]['path_abs']."/podcast.txt", $contentTree[$key]['files']) && !in_array($contentTree[$key]['path_abs']."/youtube.txt", $contentTree[$key]['files']) ) {

print "
<span class='mb-0 playlist_headline' data-toggle='collapse' data-target='#collapse".$id."' aria-expanded='true' aria-controls='collapse".$id."' style='cursor:pointer;' title='Show contents'>";
Expand All @@ -355,11 +378,15 @@ function index_folders_print($item, $key)
print $contentTree[$key]['basename'];
}
} elseif (in_array($contentTree[$key]['path_abs']."/livestream.txt", $contentTree[$key]['files'])) {
print "<i class='mdi mdi-podcast mdi-36px'></i> ";
print "<i class='mdi mdi-radio mdi-36px'></i> ";
print $contentTree[$key]['basename'];

} elseif (in_array($contentTree[$key]['path_abs']."/podcast.txt", $contentTree[$key]['files'])) {
print "<i class='mdi mdi-cast mdi-36px'></i> ";
print "<i class='mdi mdi-cast-audio mdi-36px'></i> ";
print $contentTree[$key]['basename'];

} elseif (in_array($contentTree[$key]['path_abs']."/youtube.txt", $contentTree[$key]['files'])) {
print "<i class='mdi mdi-youtube mdi-36px'></i> ";
print $contentTree[$key]['basename'];

} else {
Expand Down
4 changes: 4 additions & 0 deletions htdocs/inc.processCheckCardEditRegister.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ function fillRfidArrAvailWithUsed($rfidAvailArr, $rfidUsedArr=array()) {
// New folder is created so we link a RFID to it. Write $post['audiofolderNew'] to cardID file in shortcuts
$exec = "rm ".$fileshortcuts."; echo '".$post['audiofolderNew']."' > ".$fileshortcuts."; chmod 777 ".$fileshortcuts;
exec($exec);
// write $streamfile and make accessible to anyone
$ytfile = "youtube.txt";
$exec = "echo '' > '".$foldername."/".$ytfile."'; sudo chmod -R 777 '".$foldername."'";
exec($exec);
} else {
// link to existing audiofolder
$foldername = $Audio_Folders_Path."/".$post['audiofolder'];
Expand Down
65 changes: 20 additions & 45 deletions htdocs/inc.viewFolderTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,53 +112,28 @@
$temp['type'] = "spotify";
$titlefile = $subfolder."/title.txt";
$coverfile = $subfolder."/cover.jpg";

// get title from Spotify if wasn't previously stored
if (!file_exists($titlefile)) {
$uri = file_get_contents($subfolder."/spotify.txt");

// check for mediatype ("track" / "playlist") because following Mopidy API request needs differing parameters
$mediatype = explode(':' , $uri)[1];

if ($mediatype == "playlist"){
// request media info via Mopidy's API
$method = 'core.playlists.lookup';
$params = '{
"uri": "'.trim($uri).'"
}';
$json = mopidyApiCall($method, $params);

$title = $json["result"]["name"];

} elseif ($mediatype == "track") {
// request media info via Mopidy's API
$method = 'core.library.lookup';
$params = '{
"uris": ["'.trim($uri).'"]
}';
$json = mopidyApiCall($method, $params);

$title = $json["result"][trim($uri)][0]["name"];
}
file_put_contents($titlefile, $title);

// this is a new and easier way for loading spotify informations!
$uri = file_get_contents($subfolder."/spotify.txt");
$url = "https://open.spotify.com/oembed/?url=".trim($uri)."&format=json";

if (!file_exists($coverfile)) {
$str = file_get_contents($url);
$json = json_decode($str, true);

$cover = $json['thumbnail_url'];
$coverdl = file_get_contents($cover);
file_put_contents($coverfile, $coverdl);
}

if (!file_exists($titlefile)) {
$str = file_get_contents($url);
$json = json_decode($str, true);

// get cover from Spotify if wasn't previously stored
if (!file_exists($coverfile)) {
$uri = file_get_contents($subfolder."/spotify.txt");

// request media-related images via Mopidy's API
$method = 'core.library.get_images';
$params = '{
"uris": ["'.trim($uri).'"]
}';
$json = mopidyApiCall($method, $params);

$coveruri = $json["result"][trim($uri)][0]["uri"];
$cover = file_get_contents($coveruri);

file_put_contents($coverfile, $cover);
$title = $json['title'];
file_put_contents($titlefile, $title);
}

} else {
$temp['type'] = "generic";
}
Expand Down Expand Up @@ -203,7 +178,7 @@
//}
}
if(count($contentTree) > 0) {
print "\n <div class='col-md-12'>";
//print "\n <div class='col-md-12'>";

$rootBranch = current($contentTree);

Expand Down
94 changes: 93 additions & 1 deletion htdocs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,45 @@
html_bootstrap3_createHeader("en","Phoniebox",$conf['base_url']);

?>
<style>
.filterDiv {
display: none;
}

.filtershow {
display: block;
}

.filtercontainer {
margin-top: 20px;
overflow: hidden;
}

/* Style the buttons */
.filterbtn {
border: none;
outline: none;
padding: 12px 16px;
margin-bottom: 3px;
background-color: #464545;
color: white;
cursor: pointer;
border-top-right-radius: 4px;
border-top-left-radius: 4px;
border-bottom-right-radius: 4px;
border-bottom-left-radius: 4px;
}

.filterbtn:hover {
background-color: #f1f1f1;
color: black;
}

.filterbtn.active {
background-color: #0ce3ac;
color: white;
}
</style>
<body>
<div class="container">

Expand Down Expand Up @@ -60,7 +99,15 @@
<div class="row">
<div class="col-lg-12">
<h3><?php print $lang['indexAvailAudio']; ?></h3>
<div class="row">
<div id="myfilterBtnContainer">
<button class="filterbtn active" onclick="filterSelection('all')"> <?php print $lang['filterall']; ?></button>
<button class="filterbtn" onclick="filterSelection('file')"> <?php print $lang['filterfile']; ?></button>
<button class="filterbtn" onclick="filterSelection('livestream')"> <?php print $lang['filterlivestream']; ?></button>
<button class="filterbtn" onclick="filterSelection('podcast')"> <?php print $lang['filterpodcast']; ?></button>
<button class="filterbtn" onclick="filterSelection('spotify')"> <?php print $lang['filterspotify']; ?></button>
<button class="filterbtn" onclick="filterSelection('youtube')"> <?php print $lang['filteryoutube']; ?></button>
</div>
<div class="filtercontainer row">
<?php

// read the shortcuts used
Expand Down Expand Up @@ -92,6 +139,51 @@
?>

</div><!-- / .col-lg-12 -->
<script>
filterSelection("all")
function filterSelection(c) {
var x, i;
x = document.getElementsByClassName("filterDiv");
if (c == "all") c = "";
for (i = 0; i < x.length; i++) {
w3RemoveClass(x[i], "filtershow");
if (x[i].className.indexOf(c) > -1) w3AddClass(x[i], "filtershow");
}
}

function w3AddClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
if (arr1.indexOf(arr2[i]) == -1) {element.className += " " + arr2[i];}
}
}

function w3RemoveClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
while (arr1.indexOf(arr2[i]) > -1) {
arr1.splice(arr1.indexOf(arr2[i]), 1);
}
}
element.className = arr1.join(" ");
}

// Add active class to the current button (highlight it)
var filterbtnContainer = document.getElementById("myfilterBtnContainer");
var btns = filterbtnContainer.getElementsByClassName("filterbtn");
for (var i = 0; i < btns.length; i++) {
btns[i].addEventListener("click", function(){
var current = document.getElementsByClassName("active");
current[0].className = current[0].className.replace(" active", "");
this.className += " active";
});
}
</script>

<!-- input-group -->
<div class="col-md-4 col-sm-6">
<div class="row" style="margin-bottom:1em;">
Expand Down
2 changes: 1 addition & 1 deletion htdocs/lang/lang-en-UK.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
$lang['cardFormStreamLegend'] = "Link Stream";
$lang['cardFormStreamLabel'] = "Stream URL (always requires new folder above)";
$lang['cardFormStreamPlaceholderClassic'] = "http(...).mp3 / .m3u / .ogg / .rss / .xml / ...";
$lang['cardFormStreamPlaceholderPlusSpotify'] = "spotify:album/artist/playlist/track/:### / Stream/Podcast like http....mp3 .xml .rss .ogg";
$lang['cardFormStreamPlaceholderPlusSpotify'] = "spotify:album/artist/playlist/track:### / Stream/Podcast like http....mp3 .xml .rss .ogg";
$lang['cardFormStreamHelp'] = "Add the URL for spotify, podcast, web radio, stream or other online media";
$lang['cardFormStreamTypeSelectDefault'] = "Select type";
$lang['cardFormStreamTypeHelp'] = "Select the type you are adding";
Expand Down
7 changes: 5 additions & 2 deletions scripts/startup-scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ sudo chmod -R 777 ${AUDIOFOLDERSPATH}
sudo chmod -R 777 ${PLAYLISTSFOLDERPATH}
sudo chmod -R 777 $PATHDATA/../shared/shortcuts

#########################################
# wait until mopidy/MPD server is running
STATUS=0
while [ "$STATUS" != "ACTIVE" ]; do STATUS=$(echo -e status\\nclose | nc -w 1 localhost 6600 | grep 'OK MPD'| sed 's/^.*$/ACTIVE/'); done

####################################
# check if and set volume on startup
/home/pi/RPi-Jukebox-RFID/scripts/playout_controls.sh -c=setvolumetostartup

####################
# play startup sound
# after some sleep
/bin/sleep 2
/usr/bin/mpg123 /home/pi/RPi-Jukebox-RFID/shared/startupsound.mp3

#######################
Expand Down

0 comments on commit 63e4af7

Please sign in to comment.