-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.js
More file actions
203 lines (178 loc) · 5.2 KB
/
common.js
File metadata and controls
203 lines (178 loc) · 5.2 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*GRB*
Gerbera - https://gerbera.io/
common.js - this file is part of Gerbera.
Copyright (C) 2018 Gerbera Contributors
Gerbera is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
Gerbera is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Gerbera. If not, see <http://www.gnu.org/licenses/>.
$Id$
*/
function escapeSlash(name)
{
name = name.replace(/\\/g, "\\\\");
name = name.replace(/\//g, "\\/");
return name;
}
function createContainerChain(arr)
{
var path = '';
for (var i = 0; i < arr.length; i++)
{
path = path + '/' + escapeSlash(arr[i]);
}
return path;
}
function getYear(date)
{
var matches = date.match(/^([0-9]{4})-/);
if (matches)
return matches[1];
else
return date;
}
function getPlaylistType(mimetype)
{
if (mimetype == 'audio/x-mpegurl')
return 'm3u';
if (mimetype == 'audio/x-scpls')
return 'pls';
return '';
}
function getLastPath(location)
{
var path = location.split('/');
if ((path.length > 1) && (path[path.length - 2]))
return path[path.length - 2];
else
return '';
}
function getRootPath(rootpath, location)
{
var path = new Array();
if (rootpath && rootpath.length !== 0)
{
rootpath = rootpath.substring(0, rootpath.lastIndexOf('/'));
var dir = location.substring(rootpath.length,location.lastIndexOf('/'));
if (dir.charAt(0) == '/')
dir = dir.substring(1);
path = dir.split('/');
}
else
{
dir = getLastPath(location);
if (dir != '')
{
dir = escapeSlash(dir);
path.push(dir);
}
}
return path;
}
// Virtual folders which split collections into alphabetic groups.
// Example for box type 9 to create a list of artist folders:
//
// --all--
// -0-9-
// -ABCDE-
// A
// B
// C
// ...
// -FGHIJ-
// -KLMNO-
// -PQRS-
// -T- <-- tends to be big
// -UVWXYZ-
// -^&#'!-
//
// JS code:
// chain = new Array('-Artist-', '--all--', artist);
// obj.title = title + ' (' + album + ', ' + date + ')';
// addCdsObject(obj, createContainerChain(chain), UPNP_CLASS_CONTAINER_MUSIC_ARTIST);
// chain = new Array('-Artist-', abcbox(artist, 9, '-'), '-all-', artist);
// obj.title = title + ' (' + album + ', ' + date + ')';
// addCdsObject(obj, createContainerChain(chain), UPNP_CLASS_CONTAINER_MUSIC_ARTIST);
// chain = new Array('-Artist-', abcbox(artist, 9, '-'), artist.charAt(0).toUpperCase(), artist, '-all-');
// obj.title = title + ' (' + album + ', ' + date + ')';
// addCdsObject(obj, createContainerChain(chain), UPNP_CLASS_CONTAINER_MUSIC_ARTIST);
function abcbox(stringtobox, boxtype, divchar)
{
// get ascii value of first character
var intchar = stringtobox.toUpperCase().charCodeAt(0);
// check for numbers
if ( (intchar >= 48) && (intchar <= 57) )
{
return divchar + '0-9' + divchar;
}
// check for other characters
if ( !((intchar >= 65) && (intchar <= 90)) )
{
return divchar + '^\&#\'' + divchar;
}
// all other characters are letters
// definition of box types, adjust to your own needs
// as a start: the number is the same as the number of boxes, evenly spaced ... more or less.
switch (boxtype)
{
case 1:
var boxwidth = new Array();
boxwidth[0] = 26; // one large box of 26 letters
break;
case 2:
var boxwidth = new Array(13,13); // two boxes of 13 letters
break;
case 3:
var boxwidth = new Array(8,9,9); // and so on ...
break;
case 4:
var boxwidth = new Array(7,6,7,6);
break;
case 5:
var boxwidth = new Array(5,5,5,6,5);
break;
case 6:
var boxwidth = new Array(4,5,4,4,5,4);
break;
case 7:
var boxwidth = new Array(4,3,4,4,4,3,4);
break;
case 9:
var boxwidth = new Array(5,5,5,4,1,6); // When T is a large box...
break;
default:
var boxwidth = new Array(5,5,5,6,5);
break;
}
// check for a total of 26 characters for all boxes
charttl = 0;
for (cb=0;cb<boxwidth.length;cb++) { charttl = charttl + boxwidth[cb]; }
if (charttl != 26) {
print("Error in box-definition, length is " + charttl + ". Check the file common.js" );
// maybe an exit call here to stop processing the media ??
end;
}
// declaration of some variables
boxnum=0; // boxnumber start
sc=65; // first ascii character (corresponds to 'A')
ec=sc + boxwidth[boxnum] - 1; // last character of first box
// loop that will define first and last character of the right box
while (intchar>ec)
{
boxnum++; // next boxnumber
sc = ec + 1; // next startchar
ec = sc + boxwidth[boxnum] - 1; // next endchar
}
// construction of output string
output = divchar;
for (i=sc;i<=ec;i++) {
output = output + String.fromCharCode(i);
}
output = output + divchar;
return output;
}