@christianriedl/media 1.0.285 → 1.0.286
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/booksService.d.ts +1 -0
- package/dist/booksService.js +4 -0
- package/dist/booksService.js.map +1 -1
- package/dist/iBooks.d.ts +2 -0
- package/dist/iMedia.d.ts +1 -0
- package/dist/mediaService.d.ts +90 -0
- package/dist/mediaService.js +714 -0
- package/dist/mediaService.js.map +1 -0
- package/dist/mediaServiceBin.d.ts +2 -1
- package/dist/mediaServiceBin.js +4 -0
- package/dist/mediaServiceBin.js.map +1 -1
- package/package.json +1 -1
- package/src/views/BooksSearchPage.vue +13 -6
- package/src/views/VideosPage.vue +78 -34
|
@@ -0,0 +1,714 @@
|
|
|
1
|
+
import { Helper } from '@christianriedl/utils';
|
|
2
|
+
import { EState, EMediaType, EItemType } from "./iMedia";
|
|
3
|
+
import { MediaHelper } from "./mediaHelper";
|
|
4
|
+
import { LocationHelper } from "./locationHelper";
|
|
5
|
+
export const getMediaSymbol = Symbol("get-media");
|
|
6
|
+
export class MediaService {
|
|
7
|
+
rest;
|
|
8
|
+
mediaUrl;
|
|
9
|
+
log;
|
|
10
|
+
user;
|
|
11
|
+
mainRoot = {
|
|
12
|
+
name: "Root", dlnaid: "0", itemType: EItemType.MainRoot,
|
|
13
|
+
state: EState.FolderReal, childCount: 4, folders: [], files: [], rating: 63, creatorIdx: -1, genreIdx: -1,
|
|
14
|
+
year: -1, description: "", dlnaParentId: "", url: "", thumbnailUrl: "", date: new Date()
|
|
15
|
+
};
|
|
16
|
+
roots = {};
|
|
17
|
+
folders = {};
|
|
18
|
+
realPictureAlbums = {};
|
|
19
|
+
medialists = {};
|
|
20
|
+
pictureLocation = { name: "", values: [] };
|
|
21
|
+
listsInitialized = 0;
|
|
22
|
+
lastFolderId = "";
|
|
23
|
+
realFolderId = "";
|
|
24
|
+
referenceDict = new Set();
|
|
25
|
+
privateIdx = -100;
|
|
26
|
+
pictureParentLimit = 0;
|
|
27
|
+
statistics;
|
|
28
|
+
countFolders;
|
|
29
|
+
countFiles;
|
|
30
|
+
countList;
|
|
31
|
+
countReferences;
|
|
32
|
+
photoSelection = { rating: 1, criteria: 'ye' };
|
|
33
|
+
constructor(rest, user, statistics, pictureParentLimit, log) {
|
|
34
|
+
this.log = log;
|
|
35
|
+
this.user = user;
|
|
36
|
+
this.rest = rest;
|
|
37
|
+
this.pictureParentLimit = pictureParentLimit;
|
|
38
|
+
this.statistics = statistics;
|
|
39
|
+
this.countFolders = statistics.searchOrCreate(log.name, "CountFolders");
|
|
40
|
+
this.countFiles = statistics.searchOrCreate(log.name, "CountFiles");
|
|
41
|
+
this.countList = statistics.searchOrCreate(log.name, "CountList");
|
|
42
|
+
this.countReferences = statistics.searchOrCreate(log.name, "CountReferences");
|
|
43
|
+
this.mediaUrl = rest.serviceUrl;
|
|
44
|
+
}
|
|
45
|
+
prepareFolders(folder) {
|
|
46
|
+
this.folders[folder.dlnaid] = folder;
|
|
47
|
+
folder.childCount = Number(folder.childCount);
|
|
48
|
+
folder.itemType = Number(folder.itemType);
|
|
49
|
+
folder.title = folder.name;
|
|
50
|
+
folder.state = Number(folder.state);
|
|
51
|
+
folder.year = Number(folder.year);
|
|
52
|
+
folder.title = folder.name;
|
|
53
|
+
folder.subTitle = '';
|
|
54
|
+
switch (folder.itemType) {
|
|
55
|
+
case EItemType.PictureRoot:
|
|
56
|
+
case EItemType.PictureFolder:
|
|
57
|
+
case EItemType.PictureRating:
|
|
58
|
+
case EItemType.PictureGenreType:
|
|
59
|
+
case EItemType.PictureCategory:
|
|
60
|
+
case EItemType.PictureYear:
|
|
61
|
+
case EItemType.PictureAlbum:
|
|
62
|
+
if (folder.mustExpand)
|
|
63
|
+
folder.info = folder.name;
|
|
64
|
+
else
|
|
65
|
+
folder.info = `${folder.name} (${folder.childCount})`;
|
|
66
|
+
break;
|
|
67
|
+
case EItemType.AudioAlbum:
|
|
68
|
+
folder.subTitle = folder.year.toString() + ' - ' + this.folders[folder.dlnaParentId].name;
|
|
69
|
+
folder.thumbnailUrl = this.getAlbumArtUrl(folder.thumbnailUrl);
|
|
70
|
+
break;
|
|
71
|
+
case EItemType.VideoGenreType:
|
|
72
|
+
folder.folders = [];
|
|
73
|
+
return false; // Remove it
|
|
74
|
+
}
|
|
75
|
+
if (folder.folders) {
|
|
76
|
+
for (var i = 0; i < folder.folders.length;)
|
|
77
|
+
if (this.prepareFolders(folder.folders[i]))
|
|
78
|
+
i++;
|
|
79
|
+
else
|
|
80
|
+
folder.folders.splice(i, 1); // remove
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
async initialize(mediaType) {
|
|
85
|
+
const rc = await this.getLists(mediaType ? mediaType : EMediaType.Picture);
|
|
86
|
+
let folder;
|
|
87
|
+
const stars = this.photoSelection.rating ? (this.photoSelection.rating == 1 ? '*' : '**') : 'all';
|
|
88
|
+
if (rc) {
|
|
89
|
+
switch (mediaType) {
|
|
90
|
+
case EMediaType.Audio:
|
|
91
|
+
folder = await this.initializeAudios();
|
|
92
|
+
break;
|
|
93
|
+
case EMediaType.Picture:
|
|
94
|
+
folder = await this.getPhotosByCriteria(stars, this.photoSelection.criteria);
|
|
95
|
+
break;
|
|
96
|
+
case EMediaType.Video:
|
|
97
|
+
folder = await this.initializeVideos();
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
getFolder(id) {
|
|
104
|
+
return this.folders[id];
|
|
105
|
+
}
|
|
106
|
+
prepare(folder) {
|
|
107
|
+
}
|
|
108
|
+
getRoot(mediaType) {
|
|
109
|
+
switch (mediaType) {
|
|
110
|
+
case EMediaType.Audio:
|
|
111
|
+
return this.audioRoot;
|
|
112
|
+
case EMediaType.Video:
|
|
113
|
+
return this.videoRoot;
|
|
114
|
+
case EMediaType.Picture:
|
|
115
|
+
return this.pictureRoot;
|
|
116
|
+
case EMediaType.Online:
|
|
117
|
+
return this.onlineRoot;
|
|
118
|
+
}
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
async getPhotosByCriteria(stars, criteria) {
|
|
122
|
+
const key = `${stars}.${criteria}`;
|
|
123
|
+
this.lastFolderId = this.realFolderId = "";
|
|
124
|
+
if (!this.roots[key]) {
|
|
125
|
+
this.log.trace("initializePhotos: " + key);
|
|
126
|
+
var critName = '';
|
|
127
|
+
switch (criteria) {
|
|
128
|
+
case 'ye':
|
|
129
|
+
critName = 'Jahr';
|
|
130
|
+
break;
|
|
131
|
+
case 'lo':
|
|
132
|
+
critName = 'Orte';
|
|
133
|
+
break;
|
|
134
|
+
case 'ev':
|
|
135
|
+
critName = 'Ereignisse';
|
|
136
|
+
break;
|
|
137
|
+
case 'pe':
|
|
138
|
+
critName = 'Personen';
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
const root = await this.browse("0", 6, true, false, `Root;Fotos;${stars};${critName}`);
|
|
142
|
+
this.prepareFolders(root);
|
|
143
|
+
this.roots[key] = root;
|
|
144
|
+
}
|
|
145
|
+
if (criteria == 'lo' && this.pictureParentLimit > 0) {
|
|
146
|
+
let ratingMap = 0;
|
|
147
|
+
switch (stars) {
|
|
148
|
+
case "all":
|
|
149
|
+
ratingMap = (1 << 2) | (1 << 1) | 1;
|
|
150
|
+
break;
|
|
151
|
+
case "*":
|
|
152
|
+
ratingMap = (1 << 2) | (1 << 1);
|
|
153
|
+
break;
|
|
154
|
+
case "**":
|
|
155
|
+
ratingMap = 1 << 2;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
LocationHelper.addLocationParents(this, this.pictureLocation, stars, ratingMap);
|
|
159
|
+
}
|
|
160
|
+
if (criteria == 'ye') // ??
|
|
161
|
+
return this.folders[`ph.${stars}.${criteria}|`];
|
|
162
|
+
else
|
|
163
|
+
return this.folders[`ph.${stars}.${criteria}`];
|
|
164
|
+
}
|
|
165
|
+
async initializeAudios() {
|
|
166
|
+
if (!this.roots['mu']) {
|
|
167
|
+
this.log.trace("initializeAudios");
|
|
168
|
+
const root = await this.browse("0", 4, true, false, 'Root;Musik');
|
|
169
|
+
this.prepareFolders(root);
|
|
170
|
+
this.roots['mu'] = root.folders[0];
|
|
171
|
+
}
|
|
172
|
+
return this.folders['mu'];
|
|
173
|
+
}
|
|
174
|
+
async initializeVideos() {
|
|
175
|
+
if (!this.roots['vi']) {
|
|
176
|
+
this.log.trace("initializeVideos");
|
|
177
|
+
const root = await this.browse("0", 2, true, false, 'Root;Videos');
|
|
178
|
+
this.prepareFolders(root);
|
|
179
|
+
this.roots['vi'] = root.folders[0];
|
|
180
|
+
}
|
|
181
|
+
return this.folders['vi'];
|
|
182
|
+
}
|
|
183
|
+
async getRecordedTVs() {
|
|
184
|
+
this.log.trace("getRecordedTVs");
|
|
185
|
+
const root = await this.browse("0", 3, false, false, 'Root;Online;Rec TV');
|
|
186
|
+
this.prepareFolders(root);
|
|
187
|
+
this.roots['online'] = root;
|
|
188
|
+
const videos = this.folders['online.rectv'];
|
|
189
|
+
this.log.trace(`getRecordedTVs ${videos.childCount}`);
|
|
190
|
+
videos.childCount = Number(videos.childCount);
|
|
191
|
+
videos.itemType = Number(videos.itemType);
|
|
192
|
+
videos.state = Number(videos.state);
|
|
193
|
+
videos.title = videos.name;
|
|
194
|
+
videos.subTitle = this.folders[videos.dlnaParentId]?.name;
|
|
195
|
+
videos.thumbnailUrl = "";
|
|
196
|
+
if (videos.files) {
|
|
197
|
+
for (var i = 0; i < videos.files.length; i++) {
|
|
198
|
+
const video = videos.files[i];
|
|
199
|
+
video.itemType = Number(video.itemType);
|
|
200
|
+
video.state = Number(video.state);
|
|
201
|
+
video.duration = Number(video.duration);
|
|
202
|
+
video.title = video.name;
|
|
203
|
+
video.info = MediaHelper.durationString(video.duration);
|
|
204
|
+
video.thumbnailUrl = "";
|
|
205
|
+
video.subTitle = video.description;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return videos;
|
|
209
|
+
}
|
|
210
|
+
async getOnlineTVs() {
|
|
211
|
+
this.log.trace("getOnlineTVs");
|
|
212
|
+
const root = await this.browse("0", 3, false, false, 'Root;Online;TV');
|
|
213
|
+
this.prepareFolders(root);
|
|
214
|
+
this.roots['online'] = root;
|
|
215
|
+
const videos = this.folders['online.tv'];
|
|
216
|
+
this.log.trace(`getTVs ${videos.childCount}`);
|
|
217
|
+
videos.childCount = Number(videos.childCount);
|
|
218
|
+
videos.itemType = Number(videos.itemType);
|
|
219
|
+
videos.state = Number(videos.state);
|
|
220
|
+
videos.title = videos.name;
|
|
221
|
+
videos.subTitle = this.folders[videos.dlnaParentId]?.name;
|
|
222
|
+
if (videos.files) {
|
|
223
|
+
for (var i = 0; i < videos.files.length; i++) {
|
|
224
|
+
const video = videos.files[i];
|
|
225
|
+
video.itemType = Number(video.itemType);
|
|
226
|
+
video.state = Number(video.state);
|
|
227
|
+
video.duration = Number(video.duration);
|
|
228
|
+
video.title = video.name;
|
|
229
|
+
video.info = MediaHelper.durationString(video.duration);
|
|
230
|
+
if (videos.url && video.url)
|
|
231
|
+
video.url = videos.url + video.url;
|
|
232
|
+
if (videos.thumbnailUrl && video.thumbnailUrl)
|
|
233
|
+
video.thumbnailUrl = videos.thumbnailUrl + video.thumbnailUrl;
|
|
234
|
+
video.subTitle = video.description;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
videos.thumbnailUrl = "";
|
|
238
|
+
return videos;
|
|
239
|
+
}
|
|
240
|
+
async getOnlineRadios() {
|
|
241
|
+
this.log.trace("getOnlineRadios");
|
|
242
|
+
const root = await this.browse("0", 3, false, false, 'Root;Online;Radio');
|
|
243
|
+
this.prepareFolders(root);
|
|
244
|
+
this.roots['online'] = root;
|
|
245
|
+
const audios = this.folders['online.radio'];
|
|
246
|
+
this.log.trace(`getRadios ${audios.childCount}`);
|
|
247
|
+
audios.childCount = Number(audios.childCount);
|
|
248
|
+
audios.itemType = Number(audios.itemType);
|
|
249
|
+
audios.state = Number(audios.state);
|
|
250
|
+
audios.title = audios.name;
|
|
251
|
+
audios.subTitle = this.folders[audios.dlnaParentId].name;
|
|
252
|
+
if (audios.files) {
|
|
253
|
+
for (var i = 0; i < audios.files.length; i++) {
|
|
254
|
+
const audio = audios.files[i];
|
|
255
|
+
audio.itemType = Number(audio.itemType);
|
|
256
|
+
audio.state = Number(audio.state);
|
|
257
|
+
audio.duration = Number(audio.duration);
|
|
258
|
+
audio.title = audio.name;
|
|
259
|
+
audio.info = MediaHelper.durationString(audio.duration);
|
|
260
|
+
audio.subTitle = audio.description;
|
|
261
|
+
if (audios.thumbnailUrl && audio.thumbnailUrl)
|
|
262
|
+
audio.thumbnailUrl = audios.thumbnailUrl + audio.thumbnailUrl;
|
|
263
|
+
audio.url = audios.url + audio.url;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
audios.thumbnailUrl = "";
|
|
267
|
+
return audios;
|
|
268
|
+
}
|
|
269
|
+
getListEntry(name, idx) {
|
|
270
|
+
var list = this.medialists[name];
|
|
271
|
+
if (list && idx < list.values.length)
|
|
272
|
+
return list.values[idx];
|
|
273
|
+
return `${name}.${idx}`;
|
|
274
|
+
}
|
|
275
|
+
async getPhotos(folder) {
|
|
276
|
+
let realPhotos;
|
|
277
|
+
const newFolder = this.lastFolderId !== folder.dlnaid;
|
|
278
|
+
this.lastFolderId = folder.dlnaid;
|
|
279
|
+
if (folder.state & EState.FolderVirtual) {
|
|
280
|
+
if (newFolder) {
|
|
281
|
+
const refs = await this.browseReferences(folder.dlnaid);
|
|
282
|
+
this.referenceDict.clear();
|
|
283
|
+
for (var i = 0; i < refs.files.length; i++) {
|
|
284
|
+
this.referenceDict.add(refs.files[i]);
|
|
285
|
+
}
|
|
286
|
+
this.realFolderId = folder.dlnaid;
|
|
287
|
+
var idx = this.realFolderId.indexOf('|');
|
|
288
|
+
this.realFolderId = 'ph.all.ye' + this.realFolderId.substr(idx);
|
|
289
|
+
this.log.trace(`getPhotos virtual ${refs.files.length} ${this.realFolderId}`);
|
|
290
|
+
}
|
|
291
|
+
realPhotos = this.realPictureAlbums[this.realFolderId];
|
|
292
|
+
if (!realPhotos) {
|
|
293
|
+
realPhotos = await this.browse(this.realFolderId, 1, false, false);
|
|
294
|
+
this.log.trace(`getPhotos virtual getReal ${realPhotos.files.length}`);
|
|
295
|
+
this.processPhotos(realPhotos);
|
|
296
|
+
this.removePrivate(realPhotos);
|
|
297
|
+
this.realPictureAlbums[this.realFolderId] = realPhotos;
|
|
298
|
+
}
|
|
299
|
+
folder.url = realPhotos.url;
|
|
300
|
+
var virtualPhotos = {
|
|
301
|
+
itemType: folder.itemType,
|
|
302
|
+
state: folder.state,
|
|
303
|
+
name: folder.name,
|
|
304
|
+
description: folder.description,
|
|
305
|
+
childCount: 0,
|
|
306
|
+
dlnaid: folder.dlnaid,
|
|
307
|
+
dlnaParentId: folder.dlnaParentId,
|
|
308
|
+
rating: folder.rating,
|
|
309
|
+
url: realPhotos.url,
|
|
310
|
+
thumbnailUrl: folder.thumbnailUrl,
|
|
311
|
+
year: folder.year,
|
|
312
|
+
folders: [],
|
|
313
|
+
files: [],
|
|
314
|
+
genreIdx: folder.genreIdx,
|
|
315
|
+
creatorIdx: folder.creatorIdx,
|
|
316
|
+
date: folder.date,
|
|
317
|
+
};
|
|
318
|
+
for (var i = 0; i < realPhotos.files.length; i++) {
|
|
319
|
+
if (this.referenceDict.has(realPhotos.files[i].dlnaid)) {
|
|
320
|
+
const photo = realPhotos.files[i];
|
|
321
|
+
if (newFolder)
|
|
322
|
+
photo.selected = false;
|
|
323
|
+
virtualPhotos.files.push(photo);
|
|
324
|
+
virtualPhotos.childCount++;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
this.log.trace(`getPhotos virtual get ${virtualPhotos.files.length}`);
|
|
328
|
+
folder.childCount = virtualPhotos.childCount;
|
|
329
|
+
return virtualPhotos;
|
|
330
|
+
}
|
|
331
|
+
realPhotos = this.realPictureAlbums[folder.dlnaid];
|
|
332
|
+
if (!realPhotos) {
|
|
333
|
+
realPhotos = await this.browse(folder.dlnaid, 1, false, false);
|
|
334
|
+
this.realPictureAlbums[folder.dlnaid] = realPhotos;
|
|
335
|
+
this.processPhotos(realPhotos);
|
|
336
|
+
this.removePrivate(realPhotos);
|
|
337
|
+
this.log.trace(`getPhotos real get ${realPhotos.files.length}`);
|
|
338
|
+
}
|
|
339
|
+
if (newFolder) {
|
|
340
|
+
for (var i = 0; i < realPhotos.files.length; i++)
|
|
341
|
+
realPhotos.files[i].selected = false;
|
|
342
|
+
}
|
|
343
|
+
folder.childCount = realPhotos.childCount;
|
|
344
|
+
return realPhotos;
|
|
345
|
+
}
|
|
346
|
+
processPhotos(folder) {
|
|
347
|
+
if (folder.files) {
|
|
348
|
+
for (var i = 0; i < folder.files.length; i++) {
|
|
349
|
+
const photo = folder.files[i];
|
|
350
|
+
if (photo.orientation && typeof photo.orientation === 'string')
|
|
351
|
+
photo.orientation = Number(photo.orientation);
|
|
352
|
+
if (photo.date) {
|
|
353
|
+
if (typeof photo.date === 'string') {
|
|
354
|
+
const date = new Date(Number(photo.year), 0, 1).getTime() + Number(photo.date) * 1000;
|
|
355
|
+
photo.date = new Date(date);
|
|
356
|
+
}
|
|
357
|
+
else if (typeof photo.date === 'number')
|
|
358
|
+
photo.date = Helper.fromMilliseconds1970(photo.date * 1000);
|
|
359
|
+
}
|
|
360
|
+
photo.title = MediaHelper.getPhotoDisplayName(folder, photo, this.pictureLocation, folder);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
removePrivate(folder) {
|
|
365
|
+
if (this.privateIdx >= 0 && folder.files) {
|
|
366
|
+
for (var i = 0; i < folder.files.length;) {
|
|
367
|
+
if (folder.files[i].creatorIdx == this.privateIdx)
|
|
368
|
+
folder.files.splice(i, 1);
|
|
369
|
+
else
|
|
370
|
+
i++;
|
|
371
|
+
}
|
|
372
|
+
folder.childCount = folder.files.length;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
async getAudios(folder) {
|
|
376
|
+
const audios = await this.browse(folder.dlnaid, 1, false, false);
|
|
377
|
+
this.prepareFolders(audios);
|
|
378
|
+
this.log.trace(`getAudios ${audios.childCount}`);
|
|
379
|
+
audios.childCount = Number(audios.childCount);
|
|
380
|
+
audios.itemType = Number(audios.itemType);
|
|
381
|
+
audios.state = Number(audios.state);
|
|
382
|
+
audios.title = audios.name;
|
|
383
|
+
audios.subTitle = this.folders[audios.dlnaParentId]?.name;
|
|
384
|
+
audios.thumbnailUrl = folder.thumbnailUrl;
|
|
385
|
+
if (audios.files) {
|
|
386
|
+
for (var i = 0; i < audios.files.length; i++) {
|
|
387
|
+
const audio = audios.files[i];
|
|
388
|
+
audio.itemType = Number(audio.itemType);
|
|
389
|
+
audio.state = Number(audio.state);
|
|
390
|
+
audio.duration = Number(audio.duration);
|
|
391
|
+
audio.title = `${audio.trackNo} ${audio.name}`;
|
|
392
|
+
audio.subTitle = MediaHelper.durationString(audio.duration);
|
|
393
|
+
audio.thumbnailUrl = "";
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return audios;
|
|
397
|
+
}
|
|
398
|
+
async getVideos(folder) {
|
|
399
|
+
const videos = await this.browse(folder.dlnaid, 1, false, false);
|
|
400
|
+
this.prepareFolders(videos);
|
|
401
|
+
this.log.trace(`getVideos ${videos.childCount}`);
|
|
402
|
+
videos.childCount = Number(videos.childCount);
|
|
403
|
+
videos.itemType = Number(videos.itemType);
|
|
404
|
+
videos.state = Number(videos.state);
|
|
405
|
+
videos.title = videos.name;
|
|
406
|
+
videos.subTitle = this.folders[videos.dlnaParentId]?.name;
|
|
407
|
+
videos.thumbnailUrl = folder.thumbnailUrl;
|
|
408
|
+
if (videos.files) {
|
|
409
|
+
for (var i = 0; i < videos.files.length; i++) {
|
|
410
|
+
const video = videos.files[i];
|
|
411
|
+
video.itemType = Number(video.itemType);
|
|
412
|
+
video.state = Number(video.state);
|
|
413
|
+
video.duration = Number(video.duration);
|
|
414
|
+
if (typeof video.countryIdx === 'string')
|
|
415
|
+
video.countryIdx = Number(video.countryIdx);
|
|
416
|
+
if (typeof video.creatorIdx === 'string')
|
|
417
|
+
video.creatorIdx = Number(video.creatorIdx);
|
|
418
|
+
if (typeof video.genreIdx === 'string')
|
|
419
|
+
video.genreIdx = Number(video.genreIdx);
|
|
420
|
+
video.title = video.name;
|
|
421
|
+
video.info = MediaHelper.durationString(video.duration);
|
|
422
|
+
video.thumbnailUrl = this.getAlbumArtUrl(video.thumbnailUrl);
|
|
423
|
+
video.subTitle = "";
|
|
424
|
+
if (video.year)
|
|
425
|
+
video.subTitle = video.year.toString();
|
|
426
|
+
if (video.countryIdx && video.countryIdx >= 0) {
|
|
427
|
+
const country = this.getListEntry('Video.Countries', video.countryIdx);
|
|
428
|
+
if (country)
|
|
429
|
+
video.subTitle += ' - ' + country;
|
|
430
|
+
}
|
|
431
|
+
if (video.creatorIdx && video.creatorIdx >= 0) {
|
|
432
|
+
const reg = this.getListEntry('Video.Director', video.creatorIdx);
|
|
433
|
+
if (reg)
|
|
434
|
+
video.subTitle += ' - ' + reg;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return videos;
|
|
439
|
+
}
|
|
440
|
+
async getPhotoTitles() {
|
|
441
|
+
const result = await this.rest.getData('apimedia/phototitles');
|
|
442
|
+
return result.result;
|
|
443
|
+
}
|
|
444
|
+
getPhotoUrl(folderUrl, url, format) {
|
|
445
|
+
const picurl = `${this.mediaUrl}apiimage/Picture/${format}${folderUrl}${url}`;
|
|
446
|
+
return encodeURI(picurl);
|
|
447
|
+
}
|
|
448
|
+
getPhotoDisplayName(folder, picture, album) {
|
|
449
|
+
return MediaHelper.getPhotoDisplayName(folder, picture, this.pictureLocation, album);
|
|
450
|
+
}
|
|
451
|
+
getAudioUrl(item) {
|
|
452
|
+
const album = this.folders[item.dlnaParentId];
|
|
453
|
+
const audiourl = `${this.mediaUrl}apistream/Audio${album.url}${item.url}`;
|
|
454
|
+
return encodeURI(audiourl);
|
|
455
|
+
}
|
|
456
|
+
getVideoUrl(url) {
|
|
457
|
+
const videourl = `${this.mediaUrl}apistream/Video${url}`;
|
|
458
|
+
return encodeURI(videourl);
|
|
459
|
+
}
|
|
460
|
+
getAlbumArtUrl(folderUrl) {
|
|
461
|
+
const albumarturl = `${this.mediaUrl}apiimage/Picture/0x0${folderUrl}`;
|
|
462
|
+
return encodeURI(albumarturl);
|
|
463
|
+
}
|
|
464
|
+
getAlbumDownloadUrl(folderUrl, codec, param) {
|
|
465
|
+
var downloadurl = `${this.mediaUrl}apistream/AudioZipped?media=${folderUrl}`;
|
|
466
|
+
if (codec || param)
|
|
467
|
+
downloadurl += `&codec=${codec}& param=${param}`;
|
|
468
|
+
return encodeURI(downloadurl);
|
|
469
|
+
}
|
|
470
|
+
getPhotosDownloadUrl(folder, resy, quality, photoIds) {
|
|
471
|
+
var name = folder.name.replaceAll(' ', '_');
|
|
472
|
+
var downloadurl = `${this.mediaUrl}apimedia/PhotosZipped/${name}?id=${folder.dlnaid}`;
|
|
473
|
+
if (resy)
|
|
474
|
+
downloadurl += `&resy=${resy}`;
|
|
475
|
+
if (quality)
|
|
476
|
+
downloadurl += `&quality=${quality}`;
|
|
477
|
+
if (photoIds && photoIds.length > 0)
|
|
478
|
+
downloadurl += `&photoIds=${photoIds.join(',')}`;
|
|
479
|
+
return encodeURI(downloadurl);
|
|
480
|
+
}
|
|
481
|
+
async browse(id, depth, onlyFolder, onlyReal, selectFolder) {
|
|
482
|
+
const folder = await this.rest.getData('apimedia/browse', { id: id, depth: depth, onlyFolder: onlyFolder, onlyReal: onlyReal, selectFolder: selectFolder });
|
|
483
|
+
const mediaFolder = folder.result;
|
|
484
|
+
this.buildStatistics(mediaFolder);
|
|
485
|
+
return mediaFolder;
|
|
486
|
+
}
|
|
487
|
+
async browseRealFiles(dlnaid, listMediaType, realFolderPrefix) {
|
|
488
|
+
const query = { dlnaid: dlnaid, realFolderPrefix: realFolderPrefix, listMediaType: listMediaType };
|
|
489
|
+
const res = await this.rest.getData('apimedia/browserealfiles', query);
|
|
490
|
+
const result = res.result;
|
|
491
|
+
if (result.folder)
|
|
492
|
+
this.buildStatistics(result.folder);
|
|
493
|
+
if (listMediaType && result.lists) {
|
|
494
|
+
this.initializeLists(listMediaType, result.lists, result.privateCreatorIdx);
|
|
495
|
+
}
|
|
496
|
+
return result;
|
|
497
|
+
}
|
|
498
|
+
async getPhotoService(id) {
|
|
499
|
+
const res = await this.rest.getData('apimedia/photoservice', { id: id });
|
|
500
|
+
const result = res.result;
|
|
501
|
+
if (result.folder)
|
|
502
|
+
this.buildStatistics(result.folder);
|
|
503
|
+
if (result.lists) {
|
|
504
|
+
this.initializeLists(EMediaType.Picture, result.lists, result.privateCreatorIdx);
|
|
505
|
+
}
|
|
506
|
+
return result;
|
|
507
|
+
}
|
|
508
|
+
async addPhotoService(id, user, dlnaid, daysValid = 365, photoIds) {
|
|
509
|
+
const data = { id: id, user: user, dlnaid: dlnaid, daysValid: daysValid, photoIds: photoIds };
|
|
510
|
+
const res = await this.rest.postDataEx('apimedia/photoservice', data);
|
|
511
|
+
return res;
|
|
512
|
+
}
|
|
513
|
+
buildStatistics(folder) {
|
|
514
|
+
if (folder.folders) {
|
|
515
|
+
this.statistics.increment(this.countFolders, folder.folders.length);
|
|
516
|
+
for (let i = 0; i < folder.folders.length; i++)
|
|
517
|
+
this.buildStatistics(folder.folders[i]);
|
|
518
|
+
}
|
|
519
|
+
if (folder.files)
|
|
520
|
+
this.statistics.increment(this.countFiles, folder.files.length);
|
|
521
|
+
}
|
|
522
|
+
async browseReferences(id) {
|
|
523
|
+
const ref = await this.rest.getData('apimedia/browse', { id: id, depth: 1, onlyFolder: false, onlyReal: false });
|
|
524
|
+
const folders = ref.result;
|
|
525
|
+
if (folders.files)
|
|
526
|
+
this.statistics.increment(this.countReferences, folders.files.length);
|
|
527
|
+
return folders;
|
|
528
|
+
}
|
|
529
|
+
async getExifInfo(folderId, mediaId) {
|
|
530
|
+
const info = await this.rest.getData('apimedia/info/exif', { folderId: folderId, mediaId: mediaId });
|
|
531
|
+
return info.result;
|
|
532
|
+
}
|
|
533
|
+
async getSatIpProbe(channelName, urlOrFileName) {
|
|
534
|
+
const info = await this.rest.getData('apistream/satipprobe', { channelName: channelName, url: urlOrFileName });
|
|
535
|
+
return info.result;
|
|
536
|
+
}
|
|
537
|
+
stopSatIpStream(channelName, media) {
|
|
538
|
+
const url = `apistream/satipstream/stop?channelName=${encodeURIComponent(channelName)}&media=${encodeURIComponent(media)}`;
|
|
539
|
+
const res = this.rest.postData(url);
|
|
540
|
+
return this.rest.toData(res);
|
|
541
|
+
}
|
|
542
|
+
async ping() {
|
|
543
|
+
try {
|
|
544
|
+
const res = await this.rest.getData('apistream/ping', { request: 'test' });
|
|
545
|
+
return res.ok && res.result.result === 'test';
|
|
546
|
+
}
|
|
547
|
+
catch (e) {
|
|
548
|
+
return false;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
getImage(url) {
|
|
552
|
+
const res = this.rest.getBlob(url, "image/jpeg");
|
|
553
|
+
return this.rest.toData(res);
|
|
554
|
+
}
|
|
555
|
+
async getLists(mediaType) {
|
|
556
|
+
if (this.listsInitialized & (1 << mediaType))
|
|
557
|
+
return true;
|
|
558
|
+
const res = await this.rest.getData('apimedia/medialist', { mediaType: mediaType });
|
|
559
|
+
const list = res.result;
|
|
560
|
+
this.initializeLists(mediaType, list.lists, list.privateCreatorIdx);
|
|
561
|
+
this.log.trace(`getLists get ${list.lists.length}`);
|
|
562
|
+
return true;
|
|
563
|
+
}
|
|
564
|
+
initializeLists(mediaType, entries, privateCreator) {
|
|
565
|
+
for (var i = 0; i < entries.length; i++) {
|
|
566
|
+
const li = entries[i];
|
|
567
|
+
if (li.values)
|
|
568
|
+
this.statistics.increment(this.countList, li.values.length);
|
|
569
|
+
if (mediaType == EMediaType.Picture) {
|
|
570
|
+
// Handle private creator
|
|
571
|
+
if (li.name == 'Picture.Creator') {
|
|
572
|
+
if (this.user != 'ric@rts.co.at' && this.user != 'rih@rts.co.at') {
|
|
573
|
+
this.privateIdx = privateCreator;
|
|
574
|
+
if (!this.privateIdx) {
|
|
575
|
+
for (var j = 0; j < li.values.length; j++) {
|
|
576
|
+
if (li.values[j] === "Christian Riedl Privat") {
|
|
577
|
+
this.privateIdx = j;
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
if (li.name == 'Picture.Location') {
|
|
585
|
+
this.pictureLocation = li;
|
|
586
|
+
li.children = [];
|
|
587
|
+
for (let i = 0; i < li.parents.length; i++) {
|
|
588
|
+
li.children.push([]);
|
|
589
|
+
}
|
|
590
|
+
for (let i = 0; i < li.parents.length; i++) {
|
|
591
|
+
const parentIdx = li.parents[i];
|
|
592
|
+
if (parentIdx >= 0) {
|
|
593
|
+
const childArray = li.children[parentIdx];
|
|
594
|
+
childArray.push(i);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
this.medialists[li.name] = li;
|
|
600
|
+
}
|
|
601
|
+
this.listsInitialized |= (1 << mediaType);
|
|
602
|
+
}
|
|
603
|
+
async upload(form) {
|
|
604
|
+
const res = await this.rest.postData('apistream/upload', form);
|
|
605
|
+
return res.ok && res.result.result;
|
|
606
|
+
}
|
|
607
|
+
async uploadBigFile(file, directory, progress) {
|
|
608
|
+
const guid = Helper.generateUUID();
|
|
609
|
+
if (!progress)
|
|
610
|
+
progress = (pos) => { }; // create dummy
|
|
611
|
+
let url = `apistream/uploadbigfile?directory=${directory}&file=${file.name}&uniqueid=${guid}`;
|
|
612
|
+
let res = await this.rest.postDataEx(url);
|
|
613
|
+
if (!res.ok) {
|
|
614
|
+
progress(res.statusText);
|
|
615
|
+
return false;
|
|
616
|
+
}
|
|
617
|
+
let result = res.result;
|
|
618
|
+
if (result.result != 'OK') {
|
|
619
|
+
progress(result.result);
|
|
620
|
+
return false;
|
|
621
|
+
}
|
|
622
|
+
progress("Start Upload");
|
|
623
|
+
const chunkSize = 1000000;
|
|
624
|
+
for (let start = 0; start < file.size; start += chunkSize) {
|
|
625
|
+
const end = Math.min(start + chunkSize, file.size);
|
|
626
|
+
const blob = file.slice(start, end);
|
|
627
|
+
const close = end == file.size;
|
|
628
|
+
let url = `apistream/uploaddata?&position=${start}&uniqueid=${guid}&close=${close}`;
|
|
629
|
+
res = await this.rest.postBlob(url, blob);
|
|
630
|
+
if (!res.ok) {
|
|
631
|
+
progress(res.statusText);
|
|
632
|
+
return false;
|
|
633
|
+
}
|
|
634
|
+
let result = res.result;
|
|
635
|
+
if (close) {
|
|
636
|
+
progress(result.result);
|
|
637
|
+
return result.result == 'OK';
|
|
638
|
+
}
|
|
639
|
+
progress(result.result);
|
|
640
|
+
if (isNaN(parseInt(result.result)))
|
|
641
|
+
return false;
|
|
642
|
+
}
|
|
643
|
+
return true;
|
|
644
|
+
}
|
|
645
|
+
async getDirectories(path) {
|
|
646
|
+
const res = await this.rest.getData('apimedia/documents/directories', { path: path });
|
|
647
|
+
if (res && res.ok) {
|
|
648
|
+
return res.result;
|
|
649
|
+
}
|
|
650
|
+
return [];
|
|
651
|
+
}
|
|
652
|
+
async getFiles(path) {
|
|
653
|
+
const res = await this.rest.getData('apimedia/documents/files', { path: path });
|
|
654
|
+
if (res && res.ok)
|
|
655
|
+
return res.result;
|
|
656
|
+
return [];
|
|
657
|
+
}
|
|
658
|
+
async getDirectoriesFull(path) {
|
|
659
|
+
const res = await this.rest.getData('apimedia/documents/directories', { path: path, full: true });
|
|
660
|
+
if (res && res.ok) {
|
|
661
|
+
const infos = res.result;
|
|
662
|
+
for (let i = 0; i < infos.length; i++) {
|
|
663
|
+
infos[i].date = new Date(infos[i].date);
|
|
664
|
+
}
|
|
665
|
+
return infos;
|
|
666
|
+
}
|
|
667
|
+
return [];
|
|
668
|
+
}
|
|
669
|
+
async getFilesFull(path) {
|
|
670
|
+
const res = await this.rest.getData('apimedia/documents/files', { path: path, full: true });
|
|
671
|
+
if (res && res.ok) {
|
|
672
|
+
const infos = res.result;
|
|
673
|
+
for (let i = 0; i < infos.length; i++) {
|
|
674
|
+
infos[i].date = new Date(infos[i].date);
|
|
675
|
+
}
|
|
676
|
+
return infos;
|
|
677
|
+
}
|
|
678
|
+
return [];
|
|
679
|
+
}
|
|
680
|
+
async speedTest(blockSize, numBlocks) {
|
|
681
|
+
const res = await this.rest.getData(`apistream/speedtest?blockSize=${blockSize}&numBlocks=${numBlocks}`, undefined, undefined, "text/plain");
|
|
682
|
+
return res;
|
|
683
|
+
/*
|
|
684
|
+
const self = this;
|
|
685
|
+
const url = `${this.rest.serviceUrl}apistream/speedtest?blockSize=${blockSize}&numBlocks=${numBlocks}`
|
|
686
|
+
const promise = new Promise<IRestResult<string>>(function (resolve, reject) {
|
|
687
|
+
Rest.fetch<string>(url, "GET", "same-origin", undefined, undefined, resolve, reject, self.log, undefined, "text/plain");
|
|
688
|
+
});
|
|
689
|
+
return promise;
|
|
690
|
+
*/
|
|
691
|
+
}
|
|
692
|
+
async getCloudUrl(folder, name) {
|
|
693
|
+
const res = await this.rest.getData('apimedia/onedriveurl', { folder: folder, name: name });
|
|
694
|
+
if (res && res.ok && res.result)
|
|
695
|
+
return res.result.result;
|
|
696
|
+
return "";
|
|
697
|
+
}
|
|
698
|
+
getFileUrl(path) {
|
|
699
|
+
return this.rest.serviceUrl + 'apimedia/document/' + encodeURI(path);
|
|
700
|
+
}
|
|
701
|
+
get audioRoot() {
|
|
702
|
+
return this.roots['mu'];
|
|
703
|
+
}
|
|
704
|
+
get videoRoot() {
|
|
705
|
+
return this.roots['vi'];
|
|
706
|
+
}
|
|
707
|
+
get pictureRoot() {
|
|
708
|
+
return this.roots['ph'];
|
|
709
|
+
}
|
|
710
|
+
get onlineRoot() {
|
|
711
|
+
return this.roots['online'];
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
//# sourceMappingURL=mediaService.js.map
|