Skip to content
This repository has been archived by the owner on Nov 9, 2021. It is now read-only.

Commit

Permalink
Added selection of playlist in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Avdeev committed Sep 18, 2018
1 parent c73c447 commit 3269df2
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 7 deletions.
61 changes: 56 additions & 5 deletions modules/app_music/app_music.class.php
Expand Up @@ -83,9 +83,10 @@ function run() {
function admin(&$out) {
// Save action
if($this->edit_mode == 'save') {
global $terminal, $skin;
global $terminal, $skin, $playlist;
$this->config['terminal'] = $terminal;
$this->config['skin'] = $skin;
$this->config['playlist'] = $playlist;
$this->saveConfig();
// Redirect
$this->redirect('?ok');
Expand Down Expand Up @@ -113,17 +114,24 @@ function admin(&$out) {
}
}
}
// Playlists
$out['playlist'] = $this->config['playlist'];
$playlists = SQLSelect('SELECT `ID`, `PATH`, `TITLE` FROM `collections` ORDER BY `TITLE`');
if($playlists[0]['ID']) {
foreach($playlists as $playlist) {
$out['PLAYLISTS'][] = $playlist;
}
}
}

// Scan directory for audio files
/*
function scanDirectory($directory, $results=array()) {
private function scanDirectory($directory, $results=array()) {
if($dir = openDir($directory)) {
while($file = readDir($dir)) {
if(($file == '.') || ($file=='..')) {
continue;
}
if(Is_Dir($directory.'/'.$file)) {
if(is_dir($directory.'/'.$file)) {
$results = $this->scanDirectory($directory.'/'.$file, $results);
} else {
if(in_array(strtolower(pathinfo($file, PATHINFO_EXTENSION)), array('mp3'))) {
Expand All @@ -136,7 +144,6 @@ function scanDirectory($directory, $results=array()) {
asort($results);
return $results;
}
*/

// FrontEnd
function usual(&$out) {
Expand All @@ -151,6 +158,48 @@ function usual(&$out) {
);
// Command
switch($command) {
case 'get_playlist': // Get playlist
if(strlen($param)>0) {
if($playlist = SQLSelectOne('SELECT `PATH` FROM `collections` WHERE `ID` = '.DBSafe($param).' OR `TITLE` = \''.DBSafe($param).'\'')) {
$files = $this->scanDirectory($playlist['PATH']);
include_once('getid3/getid3.php');
$getid3 = new getID3;
header('Content-Type: audio/x-mpegurl');
echo '#EXTM3U'.PHP_EOL;
echo PHP_EOL;
foreach($files as $file) {
$info = $getid3->analyze($file);
if(!isset($info['error'])) {
$title = '';
if(isset($info['tags']['id3v2']['artist'])) {
$title .= implode(', ', $info['tags']['id3v2']['artist']);
}
if(isset($info['tags']['id3v2']['title'])) {
if(!empty($title)) { $title .= ' - '; }
$title .= implode(', ', $info['tags']['id3v2']['title']);
}
if(empty($title)) {
$title = basename($info['filename'], '.mp3');
}
$time = round($info['playtime_seconds']);
} else {
$title = basename($file, '.mp3');
$time = -1;
}
echo '#EXTINF:'.$time.', '.$title.PHP_EOL;
echo '/module/app_mediabrowser.html?play='.urlencode($file).PHP_EOL;
echo PHP_EOL;
}
exit;
} else {
$json['success'] = FALSE;
$json['message'] = 'Playlist doesn\'t exist!';
}
} else {
$json['success'] = FALSE;
$json['message'] = 'ID/Name is missing!';
}
break;
case 'check_cover': // Check cover
if(strlen($param)>0) {
include_once('getid3/getid3.php');
Expand Down Expand Up @@ -209,6 +258,7 @@ function usual(&$out) {
// Config
$out['terminal'] = (isset($this->terminal)?$this->terminal:$this->config['terminal']);
$out['skin'] = (isset($this->skin)?$this->skin:$this->config['skin']);
$out['playlist'] = (isset($this->playlist)?$this->playlist:$this->config['playlist']);
}
}

Expand All @@ -217,6 +267,7 @@ function install($parent_name='') {
$this->getConfig();
$this->config['terminal'] = '';
$this->config['skin'] = 'rtone1_audioUI';
$this->config['playlist'] = '';
$this->saveConfig();
parent::install($parent_name);
}
Expand Down
46 changes: 44 additions & 2 deletions templates/app_music/action_admin.html
Expand Up @@ -9,7 +9,7 @@
<select name="terminal" class="form-control">
<option value=""[#if terminal=""#] selected[#endif#]>Автоопределение</option>
[#begin TERMINALS#]
<option value="[#NAME#]"[#if NAME="<#terminal#>"#] selected[#endif#]>[#TITLE#]</option>
<option value="[#NAME#]"[#if NAME="<#terminal#>"#] selected[#endif#]>[#NAME#] ([#TITLE#])</option>
[#end TERMINALS#]
</select>
<small class="form-text text-muted">Терминал на котором будет воспроизводиться музыка.</small>
Expand All @@ -26,6 +26,47 @@
<small class="form-text text-muted">От выбранного скина зависит внешний вид плеера.</small>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Плейлист:</label>
<div class="col-lg-5">
<select name="playlist" class="form-control">
<option value=""[#if playlist=""#] selected[#endif#]>Не выбрано</option>
[#begin PLAYLISTS#]
<option value="[#ID#]"[#if ID="<#playlist#>" OR TITLE="<#playlist#>"#] selected[#endif#]>[#TITLE#] ([#PATH#])</option>
[#end PLAYLISTS#]
</select>
<small class="form-text text-muted">Музыкальная коллекция для проигрывания.</small>
</div>
<div class="col-lg-2">
<a class="btn btn-default" href="#" onclick="return load_playlist($('select[name=playlist]').val(), $('select[name=terminal]').val(), this);"><i class="glyphicon glyphicon-eject"></i> Загрузить в плеер</a>
<script type="text/javascript">
function load_playlist(playlist, play_terminal, button) {
var session_terminal = 'MAIN'; // FIXME
$(button).addClass('disabled');
$.ajax({
url: '/popup/app_player.html?ajax=1&command=pl_empty&play_terminal='+encodeURIComponent(play_terminal)+'&session_terminal='+encodeURIComponent(session_terminal),
dataType: 'json'
}).done(function(json) {
if(json.success) {
$.ajax({
url: '/popup/app_player.html?ajax=1&command=pl_add&param='+encodeURIComponent('http://localhost/popup/app_music.html?ajax=1&command=get_playlist&param='+playlist)+'&play_terminal='+encodeURIComponent(play_terminal)+'&session_terminal='+encodeURIComponent(session_terminal),
dataType: 'json'
}).done(function(json) {
if(json.success) {
$(button).removeClass('disabled');
} else {
console.error('pl_add(): '+json.message);
}
});
} else {
console.error('pl_empty(): '+json.message);
}
});
return false;
}
</script>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">&nbsp;</label>
<div class="col-lg-3">
Expand All @@ -43,6 +84,7 @@
<ul>
<li><b>terminal</b> - терминал для воспроизведения;
<li><b>skin</b> - скин для изменения внешнего вида плеера;
<li><b>playlist</b> - название используемого плейлиста;
</ul>
<p>Например:<br>
<strong>&#91;#module name="app_music" mode="menu" <font color="#8a8a8a">terminal="MAIN" skin="rtone1_audioUI"</font>#&#93;</strong></p>
<strong>&#91;#module name="app_music" mode="menu" <font color="#8a8a8a">terminal="MAIN" skin="ui-green-audio-player"</font>#&#93;</strong></p>

0 comments on commit 3269df2

Please sign in to comment.