-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdirbrowser.php
More file actions
99 lines (86 loc) · 3.39 KB
/
dirbrowser.php
File metadata and controls
99 lines (86 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
include ("includes/vars.php");
include ("includes/functions.php");
include("international.php");
include ("player/mpd/connection.php");
$error = 0;
$dbterms = array( 'tags' => null, 'rating' => null );
$path = (array_key_exists('path', $_REQUEST)) ? rawurldecode($_REQUEST['path']) : "";
$prefix = (array_key_exists('prefix', $_REQUEST)) ? $_REQUEST['prefix'].'_' : "dirholder";
@open_mpd_connection();
if ($is_connected) {
if ($path == "") {
print '<div class="configtitle textcentre expand" style="margin-left:6px"><b>'.get_int_text('button_file_browser').'</b></div>';
}
doFileBrowse($path, $prefix);
} else {
header("HTTP/1.1 500 Internal Server Error");
}
close_mpd();
function doFileBrowse($path, $prefix) {
global $connection, $prefs;
debuglog("Browsing ".$path,"DIRBROWSER");
$parts = true;
$foundfile = false;
$filedata = array();
$dircount = 0;
fputs($connection, 'lsinfo "'.format_for_mpd($path).'"'."\n");
while(!feof($connection) && $parts) {
$parts = getline($connection);
if (is_array($parts)) {
$s = trim($parts[1]);
if (substr($s,0,1) != ".") {
switch ($parts[0]) {
case "file":
if (!$foundfile) {
$foundfile = true;
} else {
if (!($prefs['ignore_unplayable']) || (array_key_exists('Title', $filedata) && substr($filedata['Title'], 0, 12) != "[unplayable]")) {
printFileItem(getFormatName($filedata), $filedata['file'], $filedata['Time']);
}
$filedata = array();
}
$filedata[$parts[0]] = $parts[1];
break;
case "playlist":
if ($path != "") {
// Ignore playlists located at the root. This is cleaner and makes more sense
printPlaylistItem(basename($parts[1]), $parts[1]);
}
break;
case "directory":
printDirectoryItem($parts[1], basename($parts[1]), $prefix, $dircount, false);
$dircount++;
break;
case "Title":
case "Time":
case "Artist":
case "Album":
$filedata[$parts[0]] = $parts[1];
break;
}
}
}
}
if (array_key_exists('file', $filedata)) {
if (!($prefs['ignore_unplayable']) || (array_key_exists('Title', $filedata) && substr($filedata['Title'], 0, 12) != "[unplayable]")) {
printFileItem(getFormatName($filedata), $filedata['file'], $filedata['Time']);
}
}
}
function getFormatName($filedata) {
global $prefs;
if ($prefs['player_backend'] == "mopidy" && !preg_match('/local:track:/', $filedata['file'])) {
if (array_key_exists('Title', $filedata) && array_key_exists('Artist', $filedata)) {
return concatenate_artist_names(array_unique(explode(';',$filedata['Artist']))).' - '.$filedata['Title'];
}
if (array_key_exists('Title', $filedata)) {
return $filedata['Title'];
}
if (array_key_exists('Album', $filedata)) {
return "Album: ".$filedata['Album'];
}
}
return basename(rawurldecode($filedata['file']));
}
?>