@redseat/api 0.1.2 → 0.1.4

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/libraries.md CHANGED
@@ -1,1709 +1,1939 @@
1
- # LibraryApi
2
-
3
- The `LibraryApi` class provides comprehensive operations for managing media, tags, people, series, movies, and more within a specific library.
4
-
5
- ## Overview
6
-
7
- `LibraryApi` handles all library-specific operations including:
8
- - Media management (upload, download, update, delete)
9
- - Tags, people, series, and movies
10
- - Face recognition and clustering
11
- - Encryption support for encrypted libraries
12
- - Plugin integration
13
-
14
- ## Constructor
15
-
16
- ```typescript
17
- new LibraryApi(client: RedseatClient, libraryId: string, library: ILibrary)
18
- ```
19
-
20
- **Parameters:**
21
- - `client`: An initialized `RedseatClient` instance
22
- - `libraryId`: The ID of the library
23
- - `library`: The `ILibrary` object with library configuration
24
-
25
- **Example:**
26
- ```typescript
27
- import { RedseatClient, LibraryApi, ServerApi } from '@redseat/api';
28
-
29
- const client = new RedseatClient({ /* ... */ });
30
- const serverApi = new ServerApi(client);
31
- const libraries = await serverApi.getLibraries();
32
- const library = libraries[0];
33
-
34
- const libraryApi = new LibraryApi(client, library.id!, library);
35
- ```
36
-
37
- ## Initialization
38
-
39
- ### `setKey(passPhrase: string): Promise<void>`
40
-
41
- Sets the encryption key for encrypted libraries. Must be called before any operations on encrypted libraries.
42
-
43
- **Parameters:**
44
- - `passPhrase`: The passphrase to derive encryption keys from
45
-
46
- **Throws:** Error if the passphrase is incorrect (for encrypted libraries)
47
-
48
- **Example:**
49
- ```typescript
50
- if (library.crypt) {
51
- try {
52
- await libraryApi.setKey('my-secure-password');
53
- console.log('Encryption key set successfully');
54
- } catch (error) {
55
- console.error('Invalid encryption key:', error.message);
56
- }
57
- }
58
- ```
59
-
60
- **Note:** This method verifies the key by attempting to decrypt a media thumbnail. If decryption fails, it throws an error.
61
-
62
- ---
63
-
64
- ## Tags
65
-
66
- ### `getTags(query?: { name?: string; parent?: string; path?: string; after?: number }): Promise<ITag[]>`
67
-
68
- Retrieves tags in the library with optional filtering.
69
-
70
- **Parameters:**
71
- - `query`: Optional query object with filtering parameters:
72
- - `name`: Filter tags by name
73
- - `parent`: Filter tags by parent tag ID
74
- - `path`: Filter tags by path
75
- - `after`: Filter tags modified after this timestamp (integer unix milliseconds)
76
-
77
- **Returns:** Promise resolving to an array of `ITag` objects
78
-
79
- **Example:**
80
- ```typescript
81
- // Get all tags
82
- const tags = await libraryApi.getTags();
83
- tags.forEach(tag => console.log(tag.name));
84
-
85
- // Get tags with filters
86
- const filteredTags = await libraryApi.getTags({
87
- name: 'Vacation',
88
- after: Date.now() - 86400000 // Last 24 hours
89
- });
90
- ```
91
-
92
- ### `createTag(tag: Partial<ITag>): Promise<ITag>`
93
-
94
- Creates a new tag.
95
-
96
- **Parameters:**
97
- - `tag`: Partial tag object with at least `name` property
98
-
99
- **Returns:** Promise resolving to the created `ITag` object
100
-
101
- **Example:**
102
- ```typescript
103
- const newTag = await libraryApi.createTag({ name: 'Vacation' });
104
- ```
105
-
106
- ### `removeTag(tagId: string): Promise<void>`
107
-
108
- Deletes a tag.
109
-
110
- **Parameters:**
111
- - `tagId`: The ID of the tag to remove
112
-
113
- **Example:**
114
- ```typescript
115
- await libraryApi.removeTag('tag-id-123');
116
- ```
117
-
118
- ### `renameTag(tagId: string, newName: string): Promise<ITag>`
119
-
120
- Renames a tag.
121
-
122
- **Parameters:**
123
- - `tagId`: The ID of the tag
124
- - `newName`: The new name for the tag
125
-
126
- **Returns:** Promise resolving to the updated `ITag` object
127
-
128
- **Example:**
129
- ```typescript
130
- const updated = await libraryApi.renameTag('tag-id', 'New Tag Name');
131
- ```
132
-
133
- ### `tagChangeParent(tagId: string, newParent?: string): Promise<ITag>`
134
-
135
- Changes the parent tag (for tag hierarchy).
136
-
137
- **Parameters:**
138
- - `tagId`: The ID of the tag
139
- - `newParent`: Optional parent tag ID (undefined to remove parent)
140
-
141
- **Returns:** Promise resolving to the updated `ITag` object
142
-
143
- **Example:**
144
- ```typescript
145
- // Set parent
146
- await libraryApi.tagChangeParent('child-tag-id', 'parent-tag-id');
147
-
148
- // Remove parent
149
- await libraryApi.tagChangeParent('tag-id', undefined);
150
- ```
151
-
152
- ### `tagMerge(fromId: string, intoId: string): Promise<ITag>`
153
-
154
- Merges one tag into another.
155
-
156
- **Parameters:**
157
- - `fromId`: The tag ID to merge from (will be deleted)
158
- - `intoId`: The tag ID to merge into
159
-
160
- **Returns:** Promise resolving to the merged `ITag` object
161
-
162
- **Example:**
163
- ```typescript
164
- await libraryApi.tagMerge('old-tag-id', 'new-tag-id');
165
- ```
166
-
167
- ### `tagAddAlt(tagId: string, alt: string): Promise<ITag>`
168
-
169
- Adds an alternative name to a tag.
170
-
171
- **Parameters:**
172
- - `tagId`: The ID of the tag
173
- - `alt`: Alternative name to add
174
-
175
- **Returns:** Promise resolving to the updated `ITag` object
176
-
177
- **Example:**
178
- ```typescript
179
- await libraryApi.tagAddAlt('tag-id', 'alternative-name');
180
- ```
181
-
182
- ### `tagRemoveAlt(tagId: string, alt: string): Promise<ITag>`
183
-
184
- Removes an alternative name from a tag.
185
-
186
- **Parameters:**
187
- - `tagId`: The ID of the tag
188
- - `alt`: Alternative name to remove
189
-
190
- **Returns:** Promise resolving to the updated `ITag` object
191
-
192
- **Example:**
193
- ```typescript
194
- await libraryApi.tagRemoveAlt('tag-id', 'alternative-name');
195
- ```
196
-
197
- ---
198
-
199
- ## People
200
-
201
- ### `getPeople(query?: { name?: string; after?: number }): Promise<IPerson[]>`
202
-
203
- Retrieves people in the library with optional filtering.
204
-
205
- **Parameters:**
206
- - `query`: Optional query object with filtering parameters:
207
- - `name`: Filter people by name
208
- - `after`: Filter people modified after this timestamp (integer unix milliseconds)
209
-
210
- **Returns:** Promise resolving to an array of `IPerson` objects
211
-
212
- **Example:**
213
- ```typescript
214
- // Get all people
215
- const people = await libraryApi.getPeople();
216
-
217
- // Get people with filters
218
- const filteredPeople = await libraryApi.getPeople({
219
- name: 'John',
220
- after: Date.now() - 86400000 // Last 24 hours
221
- });
222
- ```
223
-
224
- ### `createPerson(person: Partial<IPerson>): Promise<IPerson>`
225
-
226
- Creates a new person.
227
-
228
- **Parameters:**
229
- - `person`: Partial person object with at least `name` property
230
-
231
- **Returns:** Promise resolving to the created `IPerson` object
232
-
233
- **Example:**
234
- ```typescript
235
- const person = await libraryApi.createPerson({ name: 'John Doe' });
236
- ```
237
-
238
- ### `removePerson(personId: string): Promise<void>`
239
-
240
- Deletes a person.
241
-
242
- **Parameters:**
243
- - `personId`: The ID of the person to remove
244
-
245
- **Example:**
246
- ```typescript
247
- await libraryApi.removePerson('person-id');
248
- ```
249
-
250
- ### `updatePerson(personId: string, updates: Partial<IPerson>): Promise<IPerson>`
251
-
252
- Updates a person's information.
253
-
254
- **Parameters:**
255
- - `personId`: The ID of the person
256
- - `updates`: Partial person object with fields to update
257
-
258
- **Returns:** Promise resolving to the updated `IPerson` object
259
-
260
- **Example:**
261
- ```typescript
262
- await libraryApi.updatePerson('person-id', { birthday: 1234567890 });
263
- ```
264
-
265
- ### `personRename(personId: string, newName: string): Promise<IPerson>`
266
-
267
- Renames a person.
268
-
269
- **Parameters:**
270
- - `personId`: The ID of the person
271
- - `newName`: The new name
272
-
273
- **Returns:** Promise resolving to the updated `IPerson` object
274
-
275
- **Example:**
276
- ```typescript
277
- await libraryApi.personRename('person-id', 'Jane Doe');
278
- ```
279
-
280
- ### `personAddAlt(personId: string, alt: string): Promise<IPerson>`
281
-
282
- Adds an alternative name to a person.
283
-
284
- **Parameters:**
285
- - `personId`: The ID of the person
286
- - `alt`: Alternative name to add
287
-
288
- **Returns:** Promise resolving to the updated `IPerson` object
289
-
290
- **Example:**
291
- ```typescript
292
- await libraryApi.personAddAlt('person-id', 'nickname');
293
- ```
294
-
295
- ### `personRemoveAlt(personId: string, alt: string): Promise<IPerson>`
296
-
297
- Removes an alternative name from a person.
298
-
299
- **Parameters:**
300
- - `personId`: The ID of the person
301
- - `alt`: Alternative name to remove
302
-
303
- **Returns:** Promise resolving to the updated `IPerson` object
304
-
305
- **Example:**
306
- ```typescript
307
- await libraryApi.personRemoveAlt('person-id', 'nickname');
308
- ```
309
-
310
- ### `personAddSocial(personId: string, social: any): Promise<IPerson>`
311
-
312
- Adds a social media link to a person.
313
-
314
- **Parameters:**
315
- - `personId`: The ID of the person
316
- - `social`: Social media object with `id`, `type`, and `platform`
317
-
318
- **Returns:** Promise resolving to the updated `IPerson` object
319
-
320
- **Example:**
321
- ```typescript
322
- await libraryApi.personAddSocial('person-id', {
323
- id: 'username',
324
- type: 'profile',
325
- platform: 'instagram'
326
- });
327
- ```
328
-
329
- ### `personRemoveSocial(personId: string, social: any): Promise<IPerson>`
330
-
331
- Removes a social media link from a person.
332
-
333
- **Parameters:**
334
- - `personId`: The ID of the person
335
- - `social`: Social media object to remove
336
-
337
- **Returns:** Promise resolving to the updated `IPerson` object
338
-
339
- **Example:**
340
- ```typescript
341
- await libraryApi.personRemoveSocial('person-id', socialObject);
342
- ```
343
-
344
- ### `updatePersonPortrait(personId: string, portrait: FormData): Promise<void>`
345
-
346
- Updates a person's portrait image.
347
-
348
- **Parameters:**
349
- - `personId`: The ID of the person
350
- - `portrait`: FormData containing the portrait image
351
-
352
- **Example:**
353
- ```typescript
354
- const formData = new FormData();
355
- formData.append('file', imageBlob);
356
- await libraryApi.updatePersonPortrait('person-id', formData);
357
- ```
358
-
359
- ---
360
-
361
- ## Series
362
-
363
- ### `getSeries(query?: { after?: number; name?: string; watched?: boolean; sort?: RsSort; order?: 'ASC' | 'DESC' }): Promise<ISerie[]>`
364
-
365
- Retrieves series in the library with optional filtering.
366
-
367
- **Parameters:**
368
- - `query`: Optional query object with filtering parameters:
369
- - `after`: Filter series modified after this timestamp (integer unix milliseconds)
370
- - `name`: Filter series by name
371
- - `watched`: Filter by watched status
372
- - `sort`: Sort key using `RsSort` enum (`Modified`, `Added`, `Created`, `Rating`, `Name`, `Size`)
373
- - `order`: Sort direction (`'ASC'` or `'DESC'`)
374
-
375
- **Returns:** Promise resolving to an array of `ISerie` objects
376
-
377
- **Example:**
378
- ```typescript
379
- // Get all series
380
- const series = await libraryApi.getSeries();
381
-
382
- // Get series with filters and sorting
383
- const filteredSeries = await libraryApi.getSeries({
384
- watched: false,
385
- sort: RsSort.Rating,
386
- order: 'DESC',
387
- after: Date.now() - 86400000 // Last 24 hours
388
- });
389
-
390
-
391
- ### `createSerie(serie: Partial<ISerie>): Promise<ISerie>`
392
-
393
- Creates a new series.
394
-
395
- **Parameters:**
396
- - `serie`: Partial series object
397
-
398
- **Returns:** Promise resolving to the created `ISerie` object
399
-
400
- **Example:**
401
- ```typescript
402
- const serie = await libraryApi.createSerie({ name: 'Breaking Bad' });
403
- ```
404
-
405
- ### `createEpisode(episode: Partial<IEpisode>): Promise<IEpisode>`
406
-
407
- Creates a new episode.
408
-
409
- **Parameters:**
410
- - `episode`: Partial episode object
411
-
412
- **Returns:** Promise resolving to the created `IEpisode` object
413
-
414
- **Example:**
415
- ```typescript
416
- const episode = await libraryApi.createEpisode({
417
- serie: 'serie-id',
418
- season: 1,
419
- number: 1,
420
- name: 'Pilot'
421
- });
422
- ```
423
-
424
- ### `serieScrap(serieId: string, date?: number): Promise<void>`
425
-
426
- Triggers metadata scraping for a series.
427
-
428
- **Parameters:**
429
- - `serieId`: The ID of the series
430
- - `date`: Optional date parameter
431
-
432
- **Example:**
433
- ```typescript
434
- await libraryApi.serieScrap('serie-id');
435
- ```
436
-
437
- ### `removeSerie(serieId: string): Promise<void>`
438
-
439
- Deletes a series.
440
-
441
- **Parameters:**
442
- - `serieId`: The ID of the series to remove
443
-
444
- **Example:**
445
- ```typescript
446
- await libraryApi.removeSerie('serie-id');
447
- ```
448
-
449
- ### `updateSerie(serieId: string, updates: Partial<ISerie>): Promise<ISerie>`
450
-
451
- Updates a series.
452
-
453
- **Parameters:**
454
- - `serieId`: The ID of the series
455
- - `updates`: Partial series object with fields to update
456
-
457
- **Returns:** Promise resolving to the updated `ISerie` object
458
-
459
- **Example:**
460
- ```typescript
461
- await libraryApi.updateSerie('serie-id', { description: 'New description' });
462
- ```
463
-
464
- ### `getSerieImages(serieId: string): Promise<ExternalImage[]>`
465
-
466
- Gets available images for a series from external sources.
467
-
468
- **Parameters:**
469
- - `serieId`: The ID of the series
470
-
471
- **Returns:** Promise resolving to an array of `ExternalImage` objects
472
-
473
- **Example:**
474
- ```typescript
475
- const images = await libraryApi.getSerieImages('serie-id');
476
- ```
477
-
478
- ### `updateSeriePoster(serieId: string, poster: FormData, type: string): Promise<void>`
479
-
480
- Updates a series poster image.
481
-
482
- **Parameters:**
483
- - `serieId`: The ID of the series
484
- - `poster`: FormData containing the poster image
485
- - `type`: Poster type (e.g., 'poster', 'backdrop')
486
-
487
- **Example:**
488
- ```typescript
489
- const formData = new FormData();
490
- formData.append('file', posterBlob);
491
- await libraryApi.updateSeriePoster('serie-id', formData, 'poster');
492
- ```
493
-
494
- ### `updateSeriePosterWithMediaThumb(serieId: string, mediaId: string, type: string): Promise<ISerie>`
495
-
496
- Sets a series poster using a media thumbnail.
497
-
498
- **Parameters:**
499
- - `serieId`: The ID of the series
500
- - `mediaId`: The ID of the media to use as poster
501
- - `type`: Poster type
502
-
503
- **Returns:** Promise resolving to the updated `ISerie` object
504
-
505
- **Example:**
506
- ```typescript
507
- await libraryApi.updateSeriePosterWithMediaThumb('serie-id', 'media-id', 'poster');
508
- ```
509
-
510
- ### `updateSerieImageFetch(serieId: string, image: ExternalImage): Promise<void>`
511
-
512
- Fetches and sets an external image as series poster.
513
-
514
- **Parameters:**
515
- - `serieId`: The ID of the series
516
- - `image`: External image object to fetch
517
-
518
- **Example:**
519
- ```typescript
520
- await libraryApi.updateSerieImageFetch('serie-id', externalImage);
521
- ```
522
-
523
- ### `serieRename(serieId: string, newName: string): Promise<ISerie>`
524
-
525
- Renames a series.
526
-
527
- **Parameters:**
528
- - `serieId`: The ID of the series
529
- - `newName`: The new name
530
-
531
- **Returns:** Promise resolving to the updated `ISerie` object
532
-
533
- **Example:**
534
- ```typescript
535
- await libraryApi.serieRename('serie-id', 'New Series Name');
536
- ```
537
-
538
- ### `serieAddAlt(serieId: string, alt: string): Promise<ISerie>`
539
-
540
- Adds an alternative name to a series.
541
-
542
- **Parameters:**
543
- - `serieId`: The ID of the series
544
- - `alt`: Alternative name to add
545
-
546
- **Returns:** Promise resolving to the updated `ISerie` object
547
-
548
- **Example:**
549
- ```typescript
550
- await libraryApi.serieAddAlt('serie-id', 'alternative-name');
551
- ```
552
-
553
- ### `serieRemoveAlt(serieId: string, alt: string): Promise<ISerie>`
554
-
555
- Removes an alternative name from a series.
556
-
557
- **Parameters:**
558
- - `serieId`: The ID of the series
559
- - `alt`: Alternative name to remove
560
-
561
- **Returns:** Promise resolving to the updated `ISerie` object
562
-
563
- **Example:**
564
- ```typescript
565
- await libraryApi.serieRemoveAlt('serie-id', 'alternative-name');
566
- ```
567
-
568
- ### `searchSeries(name: string): Promise<ISerie[]>`
569
-
570
- Searches for series by name.
571
-
572
- **Parameters:**
573
- - `name`: Search query
574
-
575
- **Returns:** Promise resolving to an array of matching `ISerie` objects
576
-
577
- **Example:**
578
- ```typescript
579
- const results = await libraryApi.searchSeries('Breaking');
580
- ```
581
-
582
- ### `setEpisodeWatched(serieId: string, season: number, number: number, date: number): Promise<void>`
583
-
584
- Marks an episode as watched.
585
-
586
- **Parameters:**
587
- - `serieId`: The ID of the series
588
- - `season`: Season number
589
- - `number`: Episode number
590
- - `date`: Timestamp of when it was watched
591
-
592
- **Example:**
593
- ```typescript
594
- await libraryApi.setEpisodeWatched('serie-id', 1, 1, Date.now());
595
- ```
596
-
597
- ---
598
-
599
- ## Movies
600
-
601
- ### `getMovies(query?: { after?: number; inDigital?: boolean; watched?: boolean; sort?: MovieSort }): Promise<IMovie[]>`
602
-
603
- Retrieves movies in the library with optional filtering.
604
-
605
- **Parameters:**
606
- - `query`: Optional query object with filtering parameters:
607
- - `after`: Filter movies modified after this timestamp (integer unix milliseconds)
608
- - `inDigital`: Filter by digital release availability
609
- - `watched`: Filter by watched status
610
- - `sort`: Sort key (`'modified'`, `'added'`, `'created'`, `'name'`, or `'digitalairdate'`)
611
-
612
- **Returns:** Promise resolving to an array of `IMovie` objects
613
-
614
- **Example:**
615
- ```typescript
616
- // Get all movies
617
- const movies = await libraryApi.getMovies();
618
-
619
- // Get movies with filters
620
- const filteredMovies = await libraryApi.getMovies({
621
- inDigital: true,
622
- sort: 'digitalairdate',
623
- after: Date.now() - 86400000 // Last 24 hours
624
- });
625
-
626
- ### `createMovie(movie: Partial<IMovie>): Promise<IMovie>`
627
-
628
- Creates a new movie.
629
-
630
- **Parameters:**
631
- - `movie`: Partial movie object
632
-
633
- **Returns:** Promise resolving to the created `IMovie` object
634
-
635
- **Example:**
636
- ```typescript
637
- const movie = await libraryApi.createMovie({ name: 'The Matrix' });
638
- ```
639
-
640
- ### `movieScrap(movieId: string, date?: number): Promise<void>`
641
-
642
- Triggers metadata scraping for a movie.
643
-
644
- **Parameters:**
645
- - `movieId`: The ID of the movie
646
- - `date`: Optional date parameter
647
-
648
- **Example:**
649
- ```typescript
650
- await libraryApi.movieScrap('movie-id');
651
- ```
652
-
653
- ### `removeMovie(movieId: string): Promise<void>`
654
-
655
- Deletes a movie.
656
-
657
- **Parameters:**
658
- - `movieId`: The ID of the movie to remove
659
-
660
- **Example:**
661
- ```typescript
662
- await libraryApi.removeMovie('movie-id');
663
- ```
664
-
665
- ### `updateMovie(movieId: string, updates: Partial<IMovie>): Promise<IMovie>`
666
-
667
- Updates a movie.
668
-
669
- **Parameters:**
670
- - `movieId`: The ID of the movie
671
- - `updates`: Partial movie object with fields to update
672
-
673
- **Returns:** Promise resolving to the updated `IMovie` object
674
-
675
- **Example:**
676
- ```typescript
677
- await libraryApi.updateMovie('movie-id', { description: 'New description' });
678
- ```
679
-
680
- ### `getMovieImages(movieId: string): Promise<ExternalImage[]>`
681
-
682
- Gets available images for a movie from external sources.
683
-
684
- **Parameters:**
685
- - `movieId`: The ID of the movie
686
-
687
- **Returns:** Promise resolving to an array of `ExternalImage` objects
688
-
689
- **Example:**
690
- ```typescript
691
- const images = await libraryApi.getMovieImages('movie-id');
692
- ```
693
-
694
- ### `setMovieWatched(movieId: string, date: number): Promise<void>`
695
-
696
- Marks a movie as watched.
697
-
698
- **Parameters:**
699
- - `movieId`: The ID of the movie
700
- - `date`: Timestamp of when it was watched
701
-
702
- **Example:**
703
- ```typescript
704
- await libraryApi.setMovieWatched('movie-id', Date.now());
705
- ```
706
-
707
- ### `searchMovies(name: string): Promise<IMovie[]>`
708
-
709
- Searches for movies by name.
710
-
711
- **Parameters:**
712
- - `name`: Search query
713
-
714
- **Returns:** Promise resolving to an array of matching `IMovie` objects
715
-
716
- **Example:**
717
- ```typescript
718
- const results = await libraryApi.searchMovies('Matrix');
719
- ```
720
-
721
- ### `movieRename(movieId: string, newName: string): Promise<IMovie>`
722
-
723
- Renames a movie.
724
-
725
- **Parameters:**
726
- - `movieId`: The ID of the movie
727
- - `newName`: The new name
728
-
729
- **Returns:** Promise resolving to the updated `IMovie` object
730
-
731
- **Example:**
732
- ```typescript
733
- await libraryApi.movieRename('movie-id', 'New Movie Name');
734
- ```
735
-
736
- ### `updateMoviePoster(movieId: string, poster: FormData, type: string): Promise<void>`
737
-
738
- Updates a movie poster image.
739
-
740
- **Parameters:**
741
- - `movieId`: The ID of the movie
742
- - `poster`: FormData containing the poster image
743
- - `type`: Poster type
744
-
745
- **Example:**
746
- ```typescript
747
- const formData = new FormData();
748
- formData.append('file', posterBlob);
749
- await libraryApi.updateMoviePoster('movie-id', formData, 'poster');
750
- ```
751
-
752
- ### `updateMovieImageFetch(movieId: string, image: ExternalImage): Promise<void>`
753
-
754
- Fetches and sets an external image as movie poster.
755
-
756
- **Parameters:**
757
- - `movieId`: The ID of the movie
758
- - `image`: External image object to fetch
759
-
760
- **Example:**
761
- ```typescript
762
- await libraryApi.updateMovieImageFetch('movie-id', externalImage);
763
- ```
764
-
765
- ---
766
-
767
- ## Media
768
-
769
- ### `getMedias(filter?: MediaRequest): Promise<IFile[]>`
770
-
771
- Retrieves media files with optional filtering.
772
-
773
- **Parameters:**
774
- - `filter`: Optional `MediaRequest` object for filtering/sorting
775
-
776
- **Returns:** Promise resolving to an array of `IFile` objects
777
-
778
- **Example:**
779
- ```typescript
780
- // Get all media
781
- const allMedias = await libraryApi.getMedias();
782
-
783
- // Get filtered media
784
- const photos = await libraryApi.getMedias({
785
- type: 'photo',
786
- limit: 50,
787
- offset: 0
788
- });
789
- ```
790
-
791
- ### `getMedia(mediaId: string, options?: { type?: 'stream' | 'arraybuffer' | 'blob' }): Promise<ReadableStream | ArrayBuffer | Blob>`
792
-
793
- Downloads a media file.
794
-
795
- **Parameters:**
796
- - `mediaId`: The ID of the media
797
- - `options`: Optional object with `type` property ('stream', 'arraybuffer', or 'blob')
798
-
799
- **Returns:** Promise resolving to the media data in the requested format
800
-
801
- **Example:**
802
- ```typescript
803
- // Get as blob
804
- const blob = await libraryApi.getMedia('media-id', { type: 'blob' });
805
-
806
- // Get as stream
807
- const stream = await libraryApi.getMedia('media-id', { type: 'stream' });
808
-
809
- // For encrypted libraries, decrypt after getting
810
- if (library.crypt) {
811
- const encryptedBlob = await libraryApi.getMedia('media-id', { type: 'arraybuffer' });
812
- const decrypted = await libraryApi.decryptFile('passphrase', encryptedBlob);
813
- }
814
- ```
815
-
816
- ### `getThumb(mediaId: string, options?: { type?: 'stream' | 'arraybuffer' | 'blob' }): Promise<ReadableStream | ArrayBuffer | Blob>`
817
-
818
- Gets a media thumbnail.
819
-
820
- **Parameters:**
821
- - `mediaId`: The ID of the media
822
- - `options`: Optional object with `type` property
823
-
824
- **Returns:** Promise resolving to the thumbnail data
825
-
826
- **Example:**
827
- ```typescript
828
- // Get thumbnail as blob
829
- const thumbBlob = await libraryApi.getThumb('media-id', { type: 'blob' });
830
-
831
- // For encrypted libraries, decrypt thumbnail
832
- if (library.crypt) {
833
- const media = await libraryApi.getMediaMetadata('media-id');
834
- const iv = uint8ArrayFromBase64(media.iv!);
835
- const encryptedThumb = await libraryApi.getThumb('media-id', { type: 'arraybuffer' });
836
- const decryptedThumb = await libraryApi.decryptMedia('passphrase', encryptedThumb, iv);
837
- }
838
- ```
839
-
840
- ### `getMediaMetadata(mediaId: string): Promise<IFile>`
841
-
842
- Gets metadata for a media file.
843
-
844
- **Parameters:**
845
- - `mediaId`: The ID of the media
846
-
847
- **Returns:** Promise resolving to `IFile` object with metadata
848
-
849
- **Example:**
850
- ```typescript
851
- const metadata = await libraryApi.getMediaMetadata('media-id');
852
- console.log(`File: ${metadata.name}, Size: ${metadata.size}`);
853
- ```
854
-
855
- ### `getMediaBackupMetadatas(mediaId: string): Promise<IBackupFile[]>`
856
-
857
- Gets backup metadata for a media file.
858
-
859
- **Parameters:**
860
- - `mediaId`: The ID of the media
861
-
862
- **Returns:** Promise resolving to an array of `IBackupFile` objects
863
-
864
- **Example:**
865
- ```typescript
866
- const backups = await libraryApi.getMediaBackupMetadatas('media-id');
867
- ```
868
-
869
- ### `uploadMedia(data: ArrayBuffer | Uint8Array, options: UploadMediaOptions): Promise<IFile>`
870
-
871
- Uploads a media file to the library.
872
-
873
- **Parameters:**
874
- - `data`: File data as `ArrayBuffer` or `Uint8Array`
875
- - `options`: Upload options object:
876
- - `thumb?`: Optional thumbnail data (`ArrayBuffer` or `Uint8Array`) - only for encrypted libraries
877
- - `metadata`: Media metadata (see `MediaForUpdate` interface)
878
- - `fileMime`: MIME type of the file (e.g., 'image/jpeg')
879
- - `thumbMime?`: Optional MIME type of thumbnail (default: 'image/jpeg')
880
- - `progressCallback?`: Optional callback for upload progress `(loaded: number, total: number) => void`
881
-
882
- **Returns:** Promise resolving to the created `IFile` object
883
-
884
- **Throws:** Error if encryption key not set for encrypted libraries, or if thumbnail provided for non-encrypted libraries
885
-
886
- **Example:**
887
- ```typescript
888
- // Upload to non-encrypted library
889
- const fileData = await file.arrayBuffer();
890
- const uploaded = await libraryApi.uploadMedia(fileData, {
891
- metadata: {
892
- name: 'photo.jpg',
893
- description: 'My photo'
894
- },
895
- fileMime: 'image/jpeg',
896
- progressCallback: (loaded, total) => {
897
- console.log(`Upload: ${(loaded / total * 100).toFixed(1)}%`);
898
- }
899
- });
900
-
901
- // Upload to encrypted library
902
- if (library.crypt) {
903
- await libraryApi.setKey('passphrase');
904
- const fileData = await file.arrayBuffer();
905
- const thumbData = await thumbnail.arrayBuffer();
906
-
907
- const uploaded = await libraryApi.uploadMedia(fileData, {
908
- thumb: thumbData,
909
- metadata: {
910
- name: 'photo.jpg'
911
- },
912
- fileMime: 'image/jpeg',
913
- thumbMime: 'image/jpeg'
914
- });
915
- // uploaded.iv contains the IV for decryption
916
- }
917
- ```
918
-
919
- ### `removeMedias(mediaIds: string[]): Promise<void>`
920
-
921
- Deletes multiple media files.
922
-
923
- **Parameters:**
924
- - `mediaIds`: Array of media IDs to delete
925
-
926
- **Example:**
927
- ```typescript
928
- await libraryApi.removeMedias(['media-1', 'media-2', 'media-3']);
929
- ```
930
-
931
- ### `mediaTransfer(formData: FormData): Promise<void>`
932
-
933
- Transfers media using FormData (legacy method).
934
-
935
- **Parameters:**
936
- - `formData`: FormData containing transfer information
937
-
938
- **Example:**
939
- ```typescript
940
- const formData = new FormData();
941
- formData.append('ids', JSON.stringify(['media-1', 'media-2']));
942
- formData.append('toLibrary', 'target-library-id');
943
- await libraryApi.mediaTransfer(formData);
944
- ```
945
-
946
- ### `mediaTransferMany(medias: string[], deleteOriginal: boolean, toLibraryId: string): Promise<void>`
947
-
948
- Transfers multiple media files to another library.
949
-
950
- **Parameters:**
951
- - `medias`: Array of media IDs to transfer
952
- - `deleteOriginal`: Whether to delete originals after transfer
953
- - `toLibraryId`: Target library ID
954
-
955
- **Example:**
956
- ```typescript
957
- await libraryApi.mediaTransferMany(
958
- ['media-1', 'media-2'],
959
- false, // Keep originals
960
- 'target-library-id'
961
- );
962
- ```
963
-
964
- ### `mediaTransferSingle(mediaId: string, toLibraryId: string, formData: FormData, params?: Map<string, string>): Promise<void>`
965
-
966
- Transfers a single media file to another library.
967
-
968
- **Parameters:**
969
- - `mediaId`: The ID of the media to transfer
970
- - `toLibraryId`: Target library ID
971
- - `formData`: FormData with additional transfer data
972
- - `params`: Optional query parameters
973
-
974
- **Example:**
975
- ```typescript
976
- const formData = new FormData();
977
- formData.append('option', 'value');
978
- await libraryApi.mediaTransferSingle('media-id', 'target-library-id', formData);
979
- ```
980
-
981
- ### `addTagToMedia(mediaId: string, tagId: string): Promise<void>`
982
-
983
- Adds a tag to a media file.
984
-
985
- **Parameters:**
986
- - `mediaId`: The ID of the media
987
- - `tagId`: The ID of the tag to add
988
-
989
- **Example:**
990
- ```typescript
991
- await libraryApi.addTagToMedia('media-id', 'tag-id');
992
- ```
993
-
994
- ### `removeTagFromMedia(mediaId: string, tagId: string): Promise<void>`
995
-
996
- Removes a tag from a media file.
997
-
998
- **Parameters:**
999
- - `mediaId`: The ID of the media
1000
- - `tagId`: The ID of the tag to remove
1001
-
1002
- **Example:**
1003
- ```typescript
1004
- await libraryApi.removeTagFromMedia('media-id', 'tag-id');
1005
- ```
1006
-
1007
- ### `mediaUpdate(mediaId: string, update: any): Promise<IFile[]>`
1008
-
1009
- Updates a media file's metadata.
1010
-
1011
- **Parameters:**
1012
- - `mediaId`: The ID of the media
1013
- - `update`: Update object (see `MediaForUpdate` interface)
1014
-
1015
- **Returns:** Promise resolving to an array of updated `IFile` objects
1016
-
1017
- **Example:**
1018
- ```typescript
1019
- await libraryApi.mediaUpdate('media-id', {
1020
- description: 'New description',
1021
- rating: 5
1022
- });
1023
- ```
1024
-
1025
- ### `mediaUpdateMany(update: any, ids: string[]): Promise<IFile[]>`
1026
-
1027
- Updates multiple media files.
1028
-
1029
- **Parameters:**
1030
- - `update`: Update object
1031
- - `ids`: Array of media IDs to update
1032
-
1033
- **Returns:** Promise resolving to an array of updated `IFile` objects
1034
-
1035
- **Example:**
1036
- ```typescript
1037
- await libraryApi.mediaUpdateMany(
1038
- { rating: 5 },
1039
- ['media-1', 'media-2', 'media-3']
1040
- );
1041
- ```
1042
-
1043
- ### `mediaUpdateProgress(mediaId: string, progress: number): Promise<{ progress: number }>`
1044
-
1045
- Updates the watch progress for a media file.
1046
-
1047
- **Parameters:**
1048
- - `mediaId`: The ID of the media
1049
- - `progress`: Progress value (0-100 or time-based)
1050
-
1051
- **Returns:** Promise resolving to object with updated progress
1052
-
1053
- **Example:**
1054
- ```typescript
1055
- await libraryApi.mediaUpdateProgress('media-id', 50);
1056
- ```
1057
-
1058
- ### `mediaUpdateChannel(mediaId: string, update: any): Promise<IFile[]>`
1059
-
1060
- Updates channel information for a media file.
1061
-
1062
- **Parameters:**
1063
- - `mediaId`: The ID of the media
1064
- - `update`: Channel update object
1065
-
1066
- **Returns:** Promise resolving to an array of updated `IFile` objects
1067
-
1068
- **Example:**
1069
- ```typescript
1070
- await libraryApi.mediaUpdateChannel('media-id', { channel: 'new-channel' });
1071
- ```
1072
-
1073
- ### `refreshMedia(mediaId: string): Promise<IFile[]>`
1074
-
1075
- Refreshes metadata for a media file.
1076
-
1077
- **Parameters:**
1078
- - `mediaId`: The ID of the media
1079
-
1080
- **Returns:** Promise resolving to an array of updated `IFile` objects
1081
-
1082
- **Example:**
1083
- ```typescript
1084
- await libraryApi.refreshMedia('media-id');
1085
- ```
1086
-
1087
- ### `aiTagMedia(mediaId: string): Promise<IFile[]>`
1088
-
1089
- Triggers AI tagging for a media file.
1090
-
1091
- **Parameters:**
1092
- - `mediaId`: The ID of the media
1093
-
1094
- **Returns:** Promise resolving to an array of updated `IFile` objects with new tags
1095
-
1096
- **Example:**
1097
- ```typescript
1098
- await libraryApi.aiTagMedia('media-id');
1099
- ```
1100
-
1101
- ### `splitZip(mediaId: string, from: number, to: number): Promise<IFile>`
1102
-
1103
- Splits a ZIP archive into a new archive containing pages from `from` to `to`.
1104
-
1105
- **Parameters:**
1106
- - `mediaId`: The ID of the ZIP media
1107
- - `from`: Starting page number
1108
- - `to`: Ending page number
1109
-
1110
- **Returns:** Promise resolving to the new `IFile` object
1111
-
1112
- **Example:**
1113
- ```typescript
1114
- const newZip = await libraryApi.splitZip('zip-id', 1, 10);
1115
- ```
1116
-
1117
- ### `deleteFromZip(mediaId: string, pages: number[]): Promise<IFile>`
1118
-
1119
- Deletes pages from a ZIP archive.
1120
-
1121
- **Parameters:**
1122
- - `mediaId`: The ID of the ZIP media
1123
- - `pages`: Array of page numbers to delete
1124
-
1125
- **Returns:** Promise resolving to the updated `IFile` object
1126
-
1127
- **Example:**
1128
- ```typescript
1129
- await libraryApi.deleteFromZip('zip-id', [5, 6, 7]);
1130
- ```
1131
-
1132
- ### `updateMediaThumb(mediaId: string, thumb: FormData): Promise<void>`
1133
-
1134
- Updates the thumbnail for a media file.
1135
-
1136
- **Parameters:**
1137
- - `mediaId`: The ID of the media
1138
- - `thumb`: FormData containing the thumbnail image
1139
-
1140
- **Example:**
1141
- ```typescript
1142
- const formData = new FormData();
1143
- formData.append('file', thumbBlob);
1144
- await libraryApi.updateMediaThumb('media-id', formData);
1145
- ```
1146
-
1147
- ### `getMediaShares(mediaId: string): Promise<any>`
1148
-
1149
- Gets sharing information for a media file.
1150
-
1151
- **Parameters:**
1152
- - `mediaId`: The ID of the media
1153
-
1154
- **Returns:** Promise resolving to sharing information
1155
-
1156
- **Example:**
1157
- ```typescript
1158
- const shares = await libraryApi.getMediaShares('media-id');
1159
- ```
1160
-
1161
- ### `shareMediaToProvider(mediaId: string, provider: string, formData?: FormData): Promise<any>`
1162
-
1163
- Shares a media file to an external provider.
1164
-
1165
- **Parameters:**
1166
- - `mediaId`: The ID of the media
1167
- - `provider`: Provider name (e.g., 'instagram', 'twitter')
1168
- - `formData`: Optional FormData with additional sharing data
1169
-
1170
- **Returns:** Promise resolving to sharing result
1171
-
1172
- **Example:**
1173
- ```typescript
1174
- const result = await libraryApi.shareMediaToProvider('media-id', 'instagram');
1175
- ```
1176
-
1177
- ---
1178
-
1179
- ## Faces
1180
-
1181
- ### `getUnassignedFaces(params?: Map<string, string>): Promise<any>`
1182
-
1183
- Gets unassigned faces (faces not yet linked to a person).
1184
-
1185
- **Parameters:**
1186
- - `params`: Optional query parameters
1187
-
1188
- **Returns:** Promise resolving to unassigned faces data
1189
-
1190
- **Example:**
1191
- ```typescript
1192
- const params = new Map([['limit', '50']]);
1193
- const faces = await libraryApi.getUnassignedFaces(params);
1194
- ```
1195
-
1196
- ### `getClusters(): Promise<any>`
1197
-
1198
- Gets face clusters (groups of similar faces).
1199
-
1200
- **Returns:** Promise resolving to clusters data
1201
-
1202
- **Example:**
1203
- ```typescript
1204
- const clusters = await libraryApi.getClusters();
1205
- ```
1206
-
1207
- ### `assignFaces(request: any): Promise<any>`
1208
-
1209
- Assigns faces to a person.
1210
-
1211
- **Parameters:**
1212
- - `request`: Assignment request object with face IDs and person ID
1213
-
1214
- **Returns:** Promise resolving to assignment result
1215
-
1216
- **Example:**
1217
- ```typescript
1218
- await libraryApi.assignFaces({
1219
- faceIds: ['face-1', 'face-2'],
1220
- personId: 'person-id'
1221
- });
1222
- ```
1223
-
1224
- ### `createPersonFromCluster(request: any): Promise<any>`
1225
-
1226
- Creates a new person from a face cluster.
1227
-
1228
- **Parameters:**
1229
- - `request`: Request object with cluster ID and person name
1230
-
1231
- **Returns:** Promise resolving to created person
1232
-
1233
- **Example:**
1234
- ```typescript
1235
- await libraryApi.createPersonFromCluster({
1236
- clusterId: 'cluster-id',
1237
- name: 'John Doe'
1238
- });
1239
- ```
1240
-
1241
- ### `splitCluster(request: any): Promise<any>`
1242
-
1243
- Splits a face cluster into multiple clusters.
1244
-
1245
- **Parameters:**
1246
- - `request`: Split request object
1247
-
1248
- **Returns:** Promise resolving to split result
1249
-
1250
- **Example:**
1251
- ```typescript
1252
- await libraryApi.splitCluster({
1253
- clusterId: 'cluster-id',
1254
- faceIds: ['face-1', 'face-2']
1255
- });
1256
- ```
1257
-
1258
- ### `unassignFace(request: any): Promise<any>`
1259
-
1260
- Unassigns a face from a person.
1261
-
1262
- **Parameters:**
1263
- - `request`: Unassign request object with face ID
1264
-
1265
- **Returns:** Promise resolving to unassign result
1266
-
1267
- **Example:**
1268
- ```typescript
1269
- await libraryApi.unassignFace({ faceId: 'face-id' });
1270
- ```
1271
-
1272
- ### `deleteFace(faceId: string): Promise<any>`
1273
-
1274
- Deletes a face.
1275
-
1276
- **Parameters:**
1277
- - `faceId`: The ID of the face to delete
1278
-
1279
- **Returns:** Promise resolving to deletion result
1280
-
1281
- **Example:**
1282
- ```typescript
1283
- await libraryApi.deleteFace('face-id');
1284
- ```
1285
-
1286
- ### `getAssignedFaces(personId: string): Promise<any>`
1287
-
1288
- Gets all faces assigned to a person.
1289
-
1290
- **Parameters:**
1291
- - `personId`: The ID of the person
1292
-
1293
- **Returns:** Promise resolving to assigned faces
1294
-
1295
- **Example:**
1296
- ```typescript
1297
- const faces = await libraryApi.getAssignedFaces('person-id');
1298
- ```
1299
-
1300
- ### `faceClusterPerson(personId: string): Promise<void>`
1301
-
1302
- Triggers face clustering for a person.
1303
-
1304
- **Parameters:**
1305
- - `personId`: The ID of the person
1306
-
1307
- **Example:**
1308
- ```typescript
1309
- await libraryApi.faceClusterPerson('person-id');
1310
- ```
1311
-
1312
- ### `mergePeople(request: any): Promise<any>`
1313
-
1314
- Merges multiple people into one.
1315
-
1316
- **Parameters:**
1317
- - `request`: Merge request object with source and target person IDs
1318
-
1319
- **Returns:** Promise resolving to merge result
1320
-
1321
- **Example:**
1322
- ```typescript
1323
- await libraryApi.mergePeople({
1324
- fromIds: ['person-1', 'person-2'],
1325
- intoId: 'person-3'
1326
- });
1327
- ```
1328
-
1329
- ### `clusterFaces(personId: string): Promise<any>`
1330
-
1331
- Clusters faces for a person.
1332
-
1333
- **Parameters:**
1334
- - `personId`: The ID of the person
1335
-
1336
- **Returns:** Promise resolving to clustering result
1337
-
1338
- **Example:**
1339
- ```typescript
1340
- await libraryApi.clusterFaces('person-id');
1341
- ```
1342
-
1343
- ---
1344
-
1345
- ## Encryption
1346
-
1347
- These methods are convenience wrappers around the encryption module. For detailed encryption documentation, see [encryption.md](encryption.md).
1348
-
1349
- ### `encryptText(passPhrase: string, text: string): Promise<string>`
1350
-
1351
- Encrypts a text string using a passphrase.
1352
-
1353
- **Parameters:**
1354
- - `passPhrase`: The passphrase to derive the key from
1355
- - `text`: The plaintext to encrypt
1356
-
1357
- **Returns:** Promise resolving to encrypted string in format `${IV}.${encryptedData}` (base64url encoded)
1358
-
1359
- **Example:**
1360
- ```typescript
1361
- const encrypted = await libraryApi.encryptText('password', 'Hello World');
1362
- ```
1363
-
1364
- ### `decryptText(passPhrase: string, encryptedText: string): Promise<string>`
1365
-
1366
- Decrypts a text string using a passphrase.
1367
-
1368
- **Parameters:**
1369
- - `passPhrase`: The passphrase to derive the key from
1370
- - `encryptedText`: The encrypted text in format `${IV}.${encryptedData}`
1371
-
1372
- **Returns:** Promise resolving to decrypted plaintext
1373
-
1374
- **Example:**
1375
- ```typescript
1376
- const decrypted = await libraryApi.decryptText('password', encryptedText);
1377
- ```
1378
-
1379
- ### `encryptMedia(passPhrase: string, buffer: ArrayBuffer | Uint8Array, iv?: ArrayBuffer | Uint8Array): Promise<ArrayBuffer>`
1380
-
1381
- Encrypts binary media data using a passphrase.
1382
-
1383
- **Parameters:**
1384
- - `passPhrase`: The passphrase to derive the key from
1385
- - `buffer`: The binary data to encrypt
1386
- - `iv`: Optional IV (if not provided, a random one is generated)
1387
-
1388
- **Returns:** Promise resolving to encrypted ArrayBuffer
1389
-
1390
- **Example:**
1391
- ```typescript
1392
- const encrypted = await libraryApi.encryptMedia('password', fileBuffer);
1393
- ```
1394
-
1395
- ### `decryptMedia(passPhrase: string, buffer: ArrayBuffer | Uint8Array, iv: ArrayBuffer | Uint8Array): Promise<ArrayBuffer>`
1396
-
1397
- Decrypts binary media data using a passphrase.
1398
-
1399
- **Parameters:**
1400
- - `passPhrase`: The passphrase to derive the key from
1401
- - `buffer`: The encrypted binary data
1402
- - `iv`: The IV used during encryption
1403
-
1404
- **Returns:** Promise resolving to decrypted ArrayBuffer
1405
-
1406
- **Example:**
1407
- ```typescript
1408
- const decrypted = await libraryApi.decryptMedia('password', encryptedBuffer, iv);
1409
- ```
1410
-
1411
- ### `encryptFile(passPhrase: string, options: EncryptFileOptions): Promise<EncryptedFile>`
1412
-
1413
- Encrypts a complete file with thumbnail and metadata.
1414
-
1415
- **Parameters:**
1416
- - `passPhrase`: The passphrase to derive the key from
1417
- - `options`: Encryption options (see `EncryptFileOptions` interface)
1418
-
1419
- **Returns:** Promise resolving to `EncryptedFile` object
1420
-
1421
- **Example:**
1422
- ```typescript
1423
- const encrypted = await libraryApi.encryptFile('password', {
1424
- filename: 'photo.jpg',
1425
- buffer: fileBuffer,
1426
- thumb: thumbBuffer,
1427
- thumbMime: 'image/jpeg',
1428
- mime: 'image/jpeg'
1429
- });
1430
- ```
1431
-
1432
- ### `decryptFile(passPhrase: string, buffer: ArrayBuffer): Promise<ArrayBuffer>`
1433
-
1434
- Decrypts file data from an encrypted file structure.
1435
-
1436
- **Parameters:**
1437
- - `passPhrase`: The passphrase to derive the key from
1438
- - `buffer`: The complete encrypted file structure
1439
-
1440
- **Returns:** Promise resolving to decrypted file ArrayBuffer
1441
-
1442
- **Example:**
1443
- ```typescript
1444
- const decrypted = await libraryApi.decryptFile('password', encryptedFileBlob);
1445
- ```
1446
-
1447
- ### `decryptMediaThumb(passPhrase: string, buffer: ArrayBuffer): Promise<ArrayBuffer>`
1448
-
1449
- Decrypts thumbnail from an encrypted file structure.
1450
-
1451
- **Parameters:**
1452
- - `passPhrase`: The passphrase to derive the key from
1453
- - `buffer`: The complete encrypted file structure
1454
-
1455
- **Returns:** Promise resolving to decrypted thumbnail ArrayBuffer
1456
-
1457
- **Example:**
1458
- ```typescript
1459
- const decryptedThumb = await libraryApi.decryptMediaThumb('password', encryptedFileBlob);
1460
- ```
1461
-
1462
- ### `encryptFilename(passPhrase: string, filename: string, iv: ArrayBuffer | Uint8Array): Promise<string>`
1463
-
1464
- Encrypts a filename using a passphrase and IV.
1465
-
1466
- **Parameters:**
1467
- - `passPhrase`: The passphrase to derive the key from
1468
- - `filename`: The filename to encrypt
1469
- - `iv`: The IV to use (should match the file's IV)
1470
-
1471
- **Returns:** Promise resolving to base64url encoded encrypted filename
1472
-
1473
- **Example:**
1474
- ```typescript
1475
- const iv = libraryApi.getRandomIV();
1476
- const encryptedFilename = await libraryApi.encryptFilename('password', 'photo.jpg', iv);
1477
- ```
1478
-
1479
- ### `getRandomIV(): Uint8Array`
1480
-
1481
- Generates a random 16-byte IV (Initialization Vector).
1482
-
1483
- **Returns:** `Uint8Array` of 16 random bytes
1484
-
1485
- **Example:**
1486
- ```typescript
1487
- const iv = libraryApi.getRandomIV();
1488
- ```
1489
-
1490
- ---
1491
-
1492
- ## Utilities
1493
-
1494
- ### `getCryptChallenge(): Promise<string>`
1495
-
1496
- Gets a cryptographic challenge for encryption verification.
1497
-
1498
- **Returns:** Promise resolving to challenge string
1499
-
1500
- **Example:**
1501
- ```typescript
1502
- const challenge = await libraryApi.getCryptChallenge();
1503
- ```
1504
-
1505
- ### `getChannels(): Promise<any[]>`
1506
-
1507
- Gets all channels (for IPTV libraries).
1508
-
1509
- **Returns:** Promise resolving to an array of channel objects
1510
-
1511
- **Example:**
1512
- ```typescript
1513
- const channels = await libraryApi.getChannels();
1514
- ```
1515
-
1516
- ### `getWatermarks(): Promise<string[]>`
1517
-
1518
- Gets list of available watermark names.
1519
-
1520
- **Returns:** Promise resolving to an array of watermark names
1521
-
1522
- **Example:**
1523
- ```typescript
1524
- const watermarks = await libraryApi.getWatermarks();
1525
- ```
1526
-
1527
- ### `getWatermark(watermark: string, options?: { type?: 'blob' | 'arraybuffer' }): Promise<Blob | ArrayBuffer>`
1528
-
1529
- Gets a watermark image.
1530
-
1531
- **Parameters:**
1532
- - `watermark`: Watermark name (or 'default')
1533
- - `options`: Optional object with `type` property
1534
-
1535
- **Returns:** Promise resolving to watermark data
1536
-
1537
- **Example:**
1538
- ```typescript
1539
- const watermark = await libraryApi.getWatermark('default', { type: 'blob' });
1540
- ```
1541
-
1542
- ### `expandUrl(parsedUrl: any): Promise<string | undefined>`
1543
-
1544
- Expands a parsed URL using plugins.
1545
-
1546
- **Parameters:**
1547
- - `parsedUrl`: Parsed URL object
1548
-
1549
- **Returns:** Promise resolving to expanded URL or undefined
1550
-
1551
- **Example:**
1552
- ```typescript
1553
- const expanded = await libraryApi.expandUrl(parsedUrl);
1554
- ```
1555
-
1556
- ### `parseUrl(url: string): Promise<any>`
1557
-
1558
- Parses a URL using plugins.
1559
-
1560
- **Parameters:**
1561
- - `url`: URL string to parse
1562
-
1563
- **Returns:** Promise resolving to parsed URL object
1564
-
1565
- **Example:**
1566
- ```typescript
1567
- const parsed = await libraryApi.parseUrl('https://example.com/video');
1568
- ```
1569
-
1570
- ### `listVideoConvertPlugins(): Promise<any[]>`
1571
-
1572
- Lists available video conversion plugins.
1573
-
1574
- **Returns:** Promise resolving to an array of plugin objects
1575
-
1576
- **Example:**
1577
- ```typescript
1578
- const plugins = await libraryApi.listVideoConvertPlugins();
1579
- ```
1580
-
1581
- ### `clean(): Promise<string>`
1582
-
1583
- Triggers library cleanup operation.
1584
-
1585
- **Returns:** Promise resolving to cleanup result message
1586
-
1587
- **Example:**
1588
- ```typescript
1589
- const result = await libraryApi.clean();
1590
- ```
1591
-
1592
- ### `locs(): Promise<any>`
1593
-
1594
- Gets location data.
1595
-
1596
- **Returns:** Promise resolving to location data
1597
-
1598
- **Example:**
1599
- ```typescript
1600
- const locations = await libraryApi.locs();
1601
- ```
1602
-
1603
- ### `mergeMedias(request: any): Promise<IFile>`
1604
-
1605
- Merges multiple media files into one.
1606
-
1607
- **Parameters:**
1608
- - `request`: Merge request object with media IDs
1609
-
1610
- **Returns:** Promise resolving to merged `IFile` object
1611
-
1612
- **Example:**
1613
- ```typescript
1614
- const merged = await libraryApi.mergeMedias({
1615
- ids: ['media-1', 'media-2']
1616
- });
1617
- ```
1618
-
1619
- ---
1620
-
1621
- ## Common Workflows
1622
-
1623
- ### Uploading Media to Encrypted Library
1624
-
1625
- ```typescript
1626
- // 1. Set encryption key
1627
- await libraryApi.setKey('my-password');
1628
-
1629
- // 2. Prepare file and thumbnail
1630
- const fileData = await file.arrayBuffer();
1631
- const thumbData = await thumbnail.arrayBuffer();
1632
-
1633
- // 3. Upload with progress tracking
1634
- const uploaded = await libraryApi.uploadMedia(fileData, {
1635
- thumb: thumbData,
1636
- metadata: {
1637
- name: 'photo.jpg',
1638
- description: 'My encrypted photo'
1639
- },
1640
- fileMime: 'image/jpeg',
1641
- thumbMime: 'image/jpeg',
1642
- progressCallback: (loaded, total) => {
1643
- console.log(`Upload: ${(loaded / total * 100).toFixed(1)}%`);
1644
- }
1645
- });
1646
-
1647
- console.log(`Uploaded with IV: ${uploaded.iv}`);
1648
- ```
1649
-
1650
- ### Downloading and Decrypting Media
1651
-
1652
- ```typescript
1653
- // 1. Set encryption key
1654
- await libraryApi.setKey('my-password');
1655
-
1656
- // 2. Get media metadata
1657
- const metadata = await libraryApi.getMediaMetadata('media-id');
1658
-
1659
- // 3. Download encrypted file
1660
- const encryptedBlob = await libraryApi.getMedia('media-id', { type: 'arraybuffer' });
1661
-
1662
- // 4. Decrypt file
1663
- const decrypted = await libraryApi.decryptFile('my-password', encryptedBlob);
1664
-
1665
- // 5. Use decrypted data
1666
- const blob = new Blob([decrypted], { type: metadata.mimetype });
1667
- const url = URL.createObjectURL(blob);
1668
- ```
1669
-
1670
- ### Tagging Media
1671
-
1672
- ```typescript
1673
- // 1. Get or create tags
1674
- const tags = await libraryApi.getTags();
1675
- let vacationTag = tags.find(t => t.name === 'Vacation');
1676
- if (!vacationTag) {
1677
- vacationTag = await libraryApi.createTag({ name: 'Vacation' });
1678
- }
1679
-
1680
- // 2. Add tag to media
1681
- await libraryApi.addTagToMedia('media-id', vacationTag.id!);
1682
- ```
1683
-
1684
- ### Managing People and Faces
1685
-
1686
- ```typescript
1687
- // 1. Create person
1688
- const person = await libraryApi.createPerson({ name: 'John Doe' });
1689
-
1690
- // 2. Get unassigned faces
1691
- const faces = await libraryApi.getUnassignedFaces();
1692
-
1693
- // 3. Assign faces to person
1694
- await libraryApi.assignFaces({
1695
- faceIds: ['face-1', 'face-2'],
1696
- personId: person.id!
1697
- });
1698
-
1699
- // 4. Cluster faces for better organization
1700
- await libraryApi.faceClusterPerson(person.id!);
1701
- ```
1702
-
1703
- ## Related Documentation
1704
-
1705
- - [RedseatClient Documentation](client.md) - HTTP client used by LibraryApi
1706
- - [ServerApi Documentation](server.md) - Server-level operations
1707
- - [Encryption Documentation](encryption.md) - Detailed encryption module documentation
1708
- - [README](README.md) - Package overview
1709
-
1
+ # LibraryApi
2
+
3
+ The `LibraryApi` class provides comprehensive operations for managing media, tags, people, series, movies, and more within a specific library.
4
+
5
+ ## Overview
6
+
7
+ `LibraryApi` handles all library-specific operations including:
8
+
9
+ - Media management (upload, download, update, delete)
10
+ - Tags, people, series, and movies
11
+ - Face recognition and clustering
12
+ - Encryption support for encrypted libraries
13
+ - Plugin integration
14
+
15
+ ## Constructor
16
+
17
+ ```typescript
18
+ new LibraryApi(client: RedseatClient, libraryId: string, library: ILibrary)
19
+ ```
20
+
21
+ **Parameters:**
22
+
23
+ - `client`: An initialized `RedseatClient` instance
24
+ - `libraryId`: The ID of the library
25
+ - `library`: The `ILibrary` object with library configuration
26
+
27
+ **Example:**
28
+
29
+ ```typescript
30
+ import { RedseatClient, LibraryApi, ServerApi } from '@redseat/api';
31
+
32
+ const client = new RedseatClient({
33
+ /* ... */
34
+ });
35
+ const serverApi = new ServerApi(client);
36
+ const libraries = await serverApi.getLibraries();
37
+ const library = libraries[0];
38
+
39
+ const libraryApi = new LibraryApi(client, library.id!, library);
40
+ ```
41
+
42
+ ## Initialization
43
+
44
+ ### `setKey(passPhrase: string): Promise<void>`
45
+
46
+ Sets the encryption key for encrypted libraries. Must be called before any operations on encrypted libraries.
47
+
48
+ **Parameters:**
49
+
50
+ - `passPhrase`: The passphrase to derive encryption keys from
51
+
52
+ **Throws:** Error if the passphrase is incorrect (for encrypted libraries)
53
+
54
+ **Example:**
55
+
56
+ ```typescript
57
+ if (library.crypt) {
58
+ try {
59
+ await libraryApi.setKey('my-secure-password');
60
+ console.log('Encryption key set successfully');
61
+ } catch (error) {
62
+ console.error('Invalid encryption key:', error.message);
63
+ }
64
+ }
65
+ ```
66
+
67
+ **Note:** This method verifies the key by attempting to decrypt a media thumbnail. If decryption fails, it throws an error.
68
+
69
+ ---
70
+
71
+ ## Tags
72
+
73
+ ### `getTags(query?: { name?: string; parent?: string; path?: string; after?: number }): Promise<ITag[]>`
74
+
75
+ Retrieves tags in the library with optional filtering.
76
+
77
+ **Parameters:**
78
+
79
+ - `query`: Optional query object with filtering parameters:
80
+ - `name`: Filter tags by name
81
+ - `parent`: Filter tags by parent tag ID
82
+ - `path`: Filter tags by path
83
+ - `after`: Filter tags modified after this timestamp (integer unix milliseconds)
84
+
85
+ **Returns:** Promise resolving to an array of `ITag` objects
86
+
87
+ **Example:**
88
+
89
+ ```typescript
90
+ // Get all tags
91
+ const tags = await libraryApi.getTags();
92
+ tags.forEach((tag) => console.log(tag.name));
93
+
94
+ // Get tags with filters
95
+ const filteredTags = await libraryApi.getTags({
96
+ name: 'Vacation',
97
+ after: Date.now() - 86400000 // Last 24 hours
98
+ });
99
+ ```
100
+
101
+ ### `createTag(tag: Partial<ITag>): Promise<ITag>`
102
+
103
+ Creates a new tag.
104
+
105
+ **Parameters:**
106
+
107
+ - `tag`: Partial tag object with at least `name` property
108
+
109
+ **Returns:** Promise resolving to the created `ITag` object
110
+
111
+ **Example:**
112
+
113
+ ```typescript
114
+ const newTag = await libraryApi.createTag({ name: 'Vacation' });
115
+ ```
116
+
117
+ ### `removeTag(tagId: string): Promise<void>`
118
+
119
+ Deletes a tag.
120
+
121
+ **Parameters:**
122
+
123
+ - `tagId`: The ID of the tag to remove
124
+
125
+ **Example:**
126
+
127
+ ```typescript
128
+ await libraryApi.removeTag('tag-id-123');
129
+ ```
130
+
131
+ ### `renameTag(tagId: string, newName: string): Promise<ITag>`
132
+
133
+ Renames a tag.
134
+
135
+ **Parameters:**
136
+
137
+ - `tagId`: The ID of the tag
138
+ - `newName`: The new name for the tag
139
+
140
+ **Returns:** Promise resolving to the updated `ITag` object
141
+
142
+ **Example:**
143
+
144
+ ```typescript
145
+ const updated = await libraryApi.renameTag('tag-id', 'New Tag Name');
146
+ ```
147
+
148
+ ### `tagChangeParent(tagId: string, newParent?: string): Promise<ITag>`
149
+
150
+ Changes the parent tag (for tag hierarchy).
151
+
152
+ **Parameters:**
153
+
154
+ - `tagId`: The ID of the tag
155
+ - `newParent`: Optional parent tag ID (undefined to remove parent)
156
+
157
+ **Returns:** Promise resolving to the updated `ITag` object
158
+
159
+ **Example:**
160
+
161
+ ```typescript
162
+ // Set parent
163
+ await libraryApi.tagChangeParent('child-tag-id', 'parent-tag-id');
164
+
165
+ // Remove parent
166
+ await libraryApi.tagChangeParent('tag-id', undefined);
167
+ ```
168
+
169
+ ### `tagMerge(fromId: string, intoId: string): Promise<ITag>`
170
+
171
+ Merges one tag into another.
172
+
173
+ **Parameters:**
174
+
175
+ - `fromId`: The tag ID to merge from (will be deleted)
176
+ - `intoId`: The tag ID to merge into
177
+
178
+ **Returns:** Promise resolving to the merged `ITag` object
179
+
180
+ **Example:**
181
+
182
+ ```typescript
183
+ await libraryApi.tagMerge('old-tag-id', 'new-tag-id');
184
+ ```
185
+
186
+ ### `tagAddAlt(tagId: string, alt: string): Promise<ITag>`
187
+
188
+ Adds an alternative name to a tag.
189
+
190
+ **Parameters:**
191
+
192
+ - `tagId`: The ID of the tag
193
+ - `alt`: Alternative name to add
194
+
195
+ **Returns:** Promise resolving to the updated `ITag` object
196
+
197
+ **Example:**
198
+
199
+ ```typescript
200
+ await libraryApi.tagAddAlt('tag-id', 'alternative-name');
201
+ ```
202
+
203
+ ### `tagRemoveAlt(tagId: string, alt: string): Promise<ITag>`
204
+
205
+ Removes an alternative name from a tag.
206
+
207
+ **Parameters:**
208
+
209
+ - `tagId`: The ID of the tag
210
+ - `alt`: Alternative name to remove
211
+
212
+ **Returns:** Promise resolving to the updated `ITag` object
213
+
214
+ **Example:**
215
+
216
+ ```typescript
217
+ await libraryApi.tagRemoveAlt('tag-id', 'alternative-name');
218
+ ```
219
+
220
+ ---
221
+
222
+ ## People
223
+
224
+ ### `getPeople(query?: { name?: string; after?: number }): Promise<IPerson[]>`
225
+
226
+ Retrieves people in the library with optional filtering.
227
+
228
+ **Parameters:**
229
+
230
+ - `query`: Optional query object with filtering parameters:
231
+ - `name`: Filter people by name
232
+ - `after`: Filter people modified after this timestamp (integer unix milliseconds)
233
+
234
+ **Returns:** Promise resolving to an array of `IPerson` objects
235
+
236
+ **Example:**
237
+
238
+ ```typescript
239
+ // Get all people
240
+ const people = await libraryApi.getPeople();
241
+
242
+ // Get people with filters
243
+ const filteredPeople = await libraryApi.getPeople({
244
+ name: 'John',
245
+ after: Date.now() - 86400000 // Last 24 hours
246
+ });
247
+ ```
248
+
249
+ ### `createPerson(person: Partial<IPerson>): Promise<IPerson>`
250
+
251
+ Creates a new person.
252
+
253
+ **Parameters:**
254
+
255
+ - `person`: Partial person object with at least `name` property
256
+
257
+ **Returns:** Promise resolving to the created `IPerson` object
258
+
259
+ **Example:**
260
+
261
+ ```typescript
262
+ const person = await libraryApi.createPerson({ name: 'John Doe' });
263
+ ```
264
+
265
+ ### `removePerson(personId: string): Promise<void>`
266
+
267
+ Deletes a person.
268
+
269
+ **Parameters:**
270
+
271
+ - `personId`: The ID of the person to remove
272
+
273
+ **Example:**
274
+
275
+ ```typescript
276
+ await libraryApi.removePerson('person-id');
277
+ ```
278
+
279
+ ### `updatePerson(personId: string, updates: Partial<IPerson>): Promise<IPerson>`
280
+
281
+ Updates a person's information.
282
+
283
+ **Parameters:**
284
+
285
+ - `personId`: The ID of the person
286
+ - `updates`: Partial person object with fields to update
287
+
288
+ **Returns:** Promise resolving to the updated `IPerson` object
289
+
290
+ **Example:**
291
+
292
+ ```typescript
293
+ await libraryApi.updatePerson('person-id', { birthday: 1234567890 });
294
+ ```
295
+
296
+ ### `personRename(personId: string, newName: string): Promise<IPerson>`
297
+
298
+ Renames a person.
299
+
300
+ **Parameters:**
301
+
302
+ - `personId`: The ID of the person
303
+ - `newName`: The new name
304
+
305
+ **Returns:** Promise resolving to the updated `IPerson` object
306
+
307
+ **Example:**
308
+
309
+ ```typescript
310
+ await libraryApi.personRename('person-id', 'Jane Doe');
311
+ ```
312
+
313
+ ### `personAddAlt(personId: string, alt: string): Promise<IPerson>`
314
+
315
+ Adds an alternative name to a person.
316
+
317
+ **Parameters:**
318
+
319
+ - `personId`: The ID of the person
320
+ - `alt`: Alternative name to add
321
+
322
+ **Returns:** Promise resolving to the updated `IPerson` object
323
+
324
+ **Example:**
325
+
326
+ ```typescript
327
+ await libraryApi.personAddAlt('person-id', 'nickname');
328
+ ```
329
+
330
+ ### `personRemoveAlt(personId: string, alt: string): Promise<IPerson>`
331
+
332
+ Removes an alternative name from a person.
333
+
334
+ **Parameters:**
335
+
336
+ - `personId`: The ID of the person
337
+ - `alt`: Alternative name to remove
338
+
339
+ **Returns:** Promise resolving to the updated `IPerson` object
340
+
341
+ **Example:**
342
+
343
+ ```typescript
344
+ await libraryApi.personRemoveAlt('person-id', 'nickname');
345
+ ```
346
+
347
+ ### `personAddSocial(personId: string, social: any): Promise<IPerson>`
348
+
349
+ Adds a social media link to a person.
350
+
351
+ **Parameters:**
352
+
353
+ - `personId`: The ID of the person
354
+ - `social`: Social media object with `id`, `type`, and `platform`
355
+
356
+ **Returns:** Promise resolving to the updated `IPerson` object
357
+
358
+ **Example:**
359
+
360
+ ```typescript
361
+ await libraryApi.personAddSocial('person-id', {
362
+ id: 'username',
363
+ type: 'profile',
364
+ platform: 'instagram'
365
+ });
366
+ ```
367
+
368
+ ### `personRemoveSocial(personId: string, social: any): Promise<IPerson>`
369
+
370
+ Removes a social media link from a person.
371
+
372
+ **Parameters:**
373
+
374
+ - `personId`: The ID of the person
375
+ - `social`: Social media object to remove
376
+
377
+ **Returns:** Promise resolving to the updated `IPerson` object
378
+
379
+ **Example:**
380
+
381
+ ```typescript
382
+ await libraryApi.personRemoveSocial('person-id', socialObject);
383
+ ```
384
+
385
+ ### `updatePersonPortrait(personId: string, portrait: FormData): Promise<void>`
386
+
387
+ Updates a person's portrait image.
388
+
389
+ **Parameters:**
390
+
391
+ - `personId`: The ID of the person
392
+ - `portrait`: FormData containing the portrait image
393
+
394
+ **Example:**
395
+
396
+ ```typescript
397
+ const formData = new FormData();
398
+ formData.append('file', imageBlob);
399
+ await libraryApi.updatePersonPortrait('person-id', formData);
400
+ ```
401
+
402
+ ---
403
+
404
+ ## Series
405
+
406
+ ### `getSeries(query?: { after?: number; name?: string; watched?: boolean; sort?: RsSort; order?: 'ASC' | 'DESC' }): Promise<ISerie[]>`
407
+
408
+ Retrieves series in the library with optional filtering.
409
+
410
+ **Parameters:**
411
+
412
+ - `query`: Optional query object with filtering parameters:
413
+ - `after`: Filter series modified after this timestamp (integer unix milliseconds)
414
+ - `name`: Filter series by name
415
+ - `watched`: Filter by watched status
416
+ - `sort`: Sort key using `RsSort` enum (`Modified`, `Added`, `Created`, `Rating`, `Name`, `Size`)
417
+ - `order`: Sort direction (`'ASC'` or `'DESC'`)
418
+
419
+ **Returns:** Promise resolving to an array of `ISerie` objects
420
+
421
+ **Example:**
422
+
423
+ ````typescript
424
+ // Get all series
425
+ const series = await libraryApi.getSeries();
426
+
427
+ // Get series with filters and sorting
428
+ const filteredSeries = await libraryApi.getSeries({
429
+ watched: false,
430
+ sort: RsSort.Rating,
431
+ order: 'DESC',
432
+ after: Date.now() - 86400000 // Last 24 hours
433
+ });
434
+
435
+
436
+ ### `getEpisodes(query?: EpisodeQuery): Promise<IEpisode[]>`
437
+
438
+ Retrieves episodes in the library with optional filtering and sorting.
439
+
440
+ **Parameters:**
441
+ - `query`: Optional query object with filtering parameters:
442
+ - `serieRef`: Filter episodes by series reference ID
443
+ - `season`: Filter episodes by season number
444
+ - `notSeasons`: Exclude episodes from these season numbers
445
+ - `after`: Filter episodes modified after this timestamp (integer unix milliseconds)
446
+ - `airedBefore`: Filter episodes that aired before this timestamp
447
+ - `airedAfter`: Filter episodes that aired after this timestamp
448
+ - `sorts`: Array of sort orders `{ sort: RsSort; order: SqlOrder }[]`
449
+ - `limit`: Maximum number of episodes to return
450
+
451
+ **Returns:** Promise resolving to an array of `IEpisode` objects
452
+
453
+ **Example:**
454
+ ```typescript
455
+ // Get all episodes
456
+ const episodes = await libraryApi.getEpisodes();
457
+
458
+ // Get episodes for a specific series
459
+ const seriesEpisodes = await libraryApi.getEpisodes({
460
+ serieRef: 'serie-id'
461
+ });
462
+
463
+ // Get episodes with filters and sorting
464
+ const filteredEpisodes = await libraryApi.getEpisodes({
465
+ serieRef: 'serie-id',
466
+ season: 1,
467
+ airedAfter: Date.now() - 86400000 * 30, // Last 30 days
468
+ sorts: [{ sort: RsSort.Added, order: SqlOrder.DESC }],
469
+ limit: 20
470
+ });
471
+
472
+ // Exclude specific seasons
473
+ const nonSpecialEpisodes = await libraryApi.getEpisodes({
474
+ serieRef: 'serie-id',
475
+ notSeasons: [0] // Exclude season 0 (specials)
476
+ });
477
+ ````
478
+
479
+ ### `createSerie(serie: Partial<ISerie>): Promise<ISerie>`
480
+
481
+ Creates a new series.
482
+
483
+ **Parameters:**
484
+
485
+ - `serie`: Partial series object
486
+
487
+ **Returns:** Promise resolving to the created `ISerie` object
488
+
489
+ **Example:**
490
+
491
+ ```typescript
492
+ const serie = await libraryApi.createSerie({ name: 'Breaking Bad' });
493
+ ```
494
+
495
+ ### `createEpisode(episode: Partial<IEpisode>): Promise<IEpisode>`
496
+
497
+ Creates a new episode.
498
+
499
+ **Parameters:**
500
+
501
+ - `episode`: Partial episode object
502
+
503
+ **Returns:** Promise resolving to the created `IEpisode` object
504
+
505
+ **Example:**
506
+
507
+ ```typescript
508
+ const episode = await libraryApi.createEpisode({
509
+ serie: 'serie-id',
510
+ season: 1,
511
+ number: 1,
512
+ name: 'Pilot'
513
+ });
514
+ ```
515
+
516
+ ### `serieScrap(serieId: string, date?: number): Promise<void>`
517
+
518
+ Triggers metadata scraping for a series.
519
+
520
+ **Parameters:**
521
+
522
+ - `serieId`: The ID of the series
523
+ - `date`: Optional date parameter
524
+
525
+ **Example:**
526
+
527
+ ```typescript
528
+ await libraryApi.serieScrap('serie-id');
529
+ ```
530
+
531
+ ### `removeSerie(serieId: string): Promise<void>`
532
+
533
+ Deletes a series.
534
+
535
+ **Parameters:**
536
+
537
+ - `serieId`: The ID of the series to remove
538
+
539
+ **Example:**
540
+
541
+ ```typescript
542
+ await libraryApi.removeSerie('serie-id');
543
+ ```
544
+
545
+ ### `updateSerie(serieId: string, updates: Partial<ISerie>): Promise<ISerie>`
546
+
547
+ Updates a series.
548
+
549
+ **Parameters:**
550
+
551
+ - `serieId`: The ID of the series
552
+ - `updates`: Partial series object with fields to update
553
+
554
+ **Returns:** Promise resolving to the updated `ISerie` object
555
+
556
+ **Example:**
557
+
558
+ ```typescript
559
+ await libraryApi.updateSerie('serie-id', { description: 'New description' });
560
+ ```
561
+
562
+ ### `getSerieImages(serieId: string): Promise<ExternalImage[]>`
563
+
564
+ Gets available images for a series from external sources.
565
+
566
+ **Parameters:**
567
+
568
+ - `serieId`: The ID of the series
569
+
570
+ **Returns:** Promise resolving to an array of `ExternalImage` objects
571
+
572
+ **Example:**
573
+
574
+ ```typescript
575
+ const images = await libraryApi.getSerieImages('serie-id');
576
+ ```
577
+
578
+ ### `updateSeriePoster(serieId: string, poster: FormData, type: string): Promise<void>`
579
+
580
+ Updates a series poster image.
581
+
582
+ **Parameters:**
583
+
584
+ - `serieId`: The ID of the series
585
+ - `poster`: FormData containing the poster image
586
+ - `type`: Poster type (e.g., 'poster', 'backdrop')
587
+
588
+ **Example:**
589
+
590
+ ```typescript
591
+ const formData = new FormData();
592
+ formData.append('file', posterBlob);
593
+ await libraryApi.updateSeriePoster('serie-id', formData, 'poster');
594
+ ```
595
+
596
+ ### `updateSeriePosterWithMediaThumb(serieId: string, mediaId: string, type: string): Promise<ISerie>`
597
+
598
+ Sets a series poster using a media thumbnail.
599
+
600
+ **Parameters:**
601
+
602
+ - `serieId`: The ID of the series
603
+ - `mediaId`: The ID of the media to use as poster
604
+ - `type`: Poster type
605
+
606
+ **Returns:** Promise resolving to the updated `ISerie` object
607
+
608
+ **Example:**
609
+
610
+ ```typescript
611
+ await libraryApi.updateSeriePosterWithMediaThumb('serie-id', 'media-id', 'poster');
612
+ ```
613
+
614
+ ### `updateSerieImageFetch(serieId: string, image: ExternalImage): Promise<void>`
615
+
616
+ Fetches and sets an external image as series poster.
617
+
618
+ **Parameters:**
619
+
620
+ - `serieId`: The ID of the series
621
+ - `image`: External image object to fetch
622
+
623
+ **Example:**
624
+
625
+ ```typescript
626
+ await libraryApi.updateSerieImageFetch('serie-id', externalImage);
627
+ ```
628
+
629
+ ### `serieRename(serieId: string, newName: string): Promise<ISerie>`
630
+
631
+ Renames a series.
632
+
633
+ **Parameters:**
634
+
635
+ - `serieId`: The ID of the series
636
+ - `newName`: The new name
637
+
638
+ **Returns:** Promise resolving to the updated `ISerie` object
639
+
640
+ **Example:**
641
+
642
+ ```typescript
643
+ await libraryApi.serieRename('serie-id', 'New Series Name');
644
+ ```
645
+
646
+ ### `serieAddAlt(serieId: string, alt: string): Promise<ISerie>`
647
+
648
+ Adds an alternative name to a series.
649
+
650
+ **Parameters:**
651
+
652
+ - `serieId`: The ID of the series
653
+ - `alt`: Alternative name to add
654
+
655
+ **Returns:** Promise resolving to the updated `ISerie` object
656
+
657
+ **Example:**
658
+
659
+ ```typescript
660
+ await libraryApi.serieAddAlt('serie-id', 'alternative-name');
661
+ ```
662
+
663
+ ### `serieRemoveAlt(serieId: string, alt: string): Promise<ISerie>`
664
+
665
+ Removes an alternative name from a series.
666
+
667
+ **Parameters:**
668
+
669
+ - `serieId`: The ID of the series
670
+ - `alt`: Alternative name to remove
671
+
672
+ **Returns:** Promise resolving to the updated `ISerie` object
673
+
674
+ **Example:**
675
+
676
+ ```typescript
677
+ await libraryApi.serieRemoveAlt('serie-id', 'alternative-name');
678
+ ```
679
+
680
+ ### `searchSeries(name: string): Promise<ISerie[]>`
681
+
682
+ Searches for series by name.
683
+
684
+ **Parameters:**
685
+
686
+ - `name`: Search query
687
+
688
+ **Returns:** Promise resolving to an array of matching `ISerie` objects
689
+
690
+ **Example:**
691
+
692
+ ```typescript
693
+ const results = await libraryApi.searchSeries('Breaking');
694
+ ```
695
+
696
+ ### `setEpisodeWatched(serieId: string, season: number, number: number, date: number): Promise<void>`
697
+
698
+ Marks an episode as watched.
699
+
700
+ **Parameters:**
701
+
702
+ - `serieId`: The ID of the series
703
+ - `season`: Season number
704
+ - `number`: Episode number
705
+ - `date`: Timestamp of when it was watched
706
+
707
+ **Example:**
708
+
709
+ ```typescript
710
+ await libraryApi.setEpisodeWatched('serie-id', 1, 1, Date.now());
711
+ ```
712
+
713
+ ---
714
+
715
+ ## Movies
716
+
717
+ ### `getMovies(query?: { after?: number; inDigital?: boolean; watched?: boolean; sort?: MovieSort }): Promise<IMovie[]>`
718
+
719
+ Retrieves movies in the library with optional filtering.
720
+
721
+ **Parameters:**
722
+
723
+ - `query`: Optional query object with filtering parameters:
724
+ - `after`: Filter movies modified after this timestamp (integer unix milliseconds)
725
+ - `inDigital`: Filter by digital release availability
726
+ - `watched`: Filter by watched status
727
+ - `sort`: Sort key (`'modified'`, `'added'`, `'created'`, `'name'`, or `'digitalairdate'`)
728
+
729
+ **Returns:** Promise resolving to an array of `IMovie` objects
730
+
731
+ **Example:**
732
+
733
+ ````typescript
734
+ // Get all movies
735
+ const movies = await libraryApi.getMovies();
736
+
737
+ // Get movies with filters
738
+ const filteredMovies = await libraryApi.getMovies({
739
+ inDigital: true,
740
+ sort: 'digitalairdate',
741
+ after: Date.now() - 86400000 // Last 24 hours
742
+ });
743
+
744
+ ### `createMovie(movie: Partial<IMovie>): Promise<IMovie>`
745
+
746
+ Creates a new movie.
747
+
748
+ **Parameters:**
749
+ - `movie`: Partial movie object
750
+
751
+ **Returns:** Promise resolving to the created `IMovie` object
752
+
753
+ **Example:**
754
+ ```typescript
755
+ const movie = await libraryApi.createMovie({ name: 'The Matrix' });
756
+ ````
757
+
758
+ ### `movieScrap(movieId: string, date?: number): Promise<void>`
759
+
760
+ Triggers metadata scraping for a movie.
761
+
762
+ **Parameters:**
763
+
764
+ - `movieId`: The ID of the movie
765
+ - `date`: Optional date parameter
766
+
767
+ **Example:**
768
+
769
+ ```typescript
770
+ await libraryApi.movieScrap('movie-id');
771
+ ```
772
+
773
+ ### `removeMovie(movieId: string): Promise<void>`
774
+
775
+ Deletes a movie.
776
+
777
+ **Parameters:**
778
+
779
+ - `movieId`: The ID of the movie to remove
780
+
781
+ **Example:**
782
+
783
+ ```typescript
784
+ await libraryApi.removeMovie('movie-id');
785
+ ```
786
+
787
+ ### `updateMovie(movieId: string, updates: Partial<IMovie>): Promise<IMovie>`
788
+
789
+ Updates a movie.
790
+
791
+ **Parameters:**
792
+
793
+ - `movieId`: The ID of the movie
794
+ - `updates`: Partial movie object with fields to update
795
+
796
+ **Returns:** Promise resolving to the updated `IMovie` object
797
+
798
+ **Example:**
799
+
800
+ ```typescript
801
+ await libraryApi.updateMovie('movie-id', { description: 'New description' });
802
+ ```
803
+
804
+ ### `getMovieImages(movieId: string): Promise<ExternalImage[]>`
805
+
806
+ Gets available images for a movie from external sources.
807
+
808
+ **Parameters:**
809
+
810
+ - `movieId`: The ID of the movie
811
+
812
+ **Returns:** Promise resolving to an array of `ExternalImage` objects
813
+
814
+ **Example:**
815
+
816
+ ```typescript
817
+ const images = await libraryApi.getMovieImages('movie-id');
818
+ ```
819
+
820
+ ### `setMovieWatched(movieId: string, date: number): Promise<void>`
821
+
822
+ Marks a movie as watched.
823
+
824
+ **Parameters:**
825
+
826
+ - `movieId`: The ID of the movie
827
+ - `date`: Timestamp of when it was watched
828
+
829
+ **Example:**
830
+
831
+ ```typescript
832
+ await libraryApi.setMovieWatched('movie-id', Date.now());
833
+ ```
834
+
835
+ ### `searchMovies(name: string): Promise<IMovie[]>`
836
+
837
+ Searches for movies by name.
838
+
839
+ **Parameters:**
840
+
841
+ - `name`: Search query
842
+
843
+ **Returns:** Promise resolving to an array of matching `IMovie` objects
844
+
845
+ **Example:**
846
+
847
+ ```typescript
848
+ const results = await libraryApi.searchMovies('Matrix');
849
+ ```
850
+
851
+ ### `movieRename(movieId: string, newName: string): Promise<IMovie>`
852
+
853
+ Renames a movie.
854
+
855
+ **Parameters:**
856
+
857
+ - `movieId`: The ID of the movie
858
+ - `newName`: The new name
859
+
860
+ **Returns:** Promise resolving to the updated `IMovie` object
861
+
862
+ **Example:**
863
+
864
+ ```typescript
865
+ await libraryApi.movieRename('movie-id', 'New Movie Name');
866
+ ```
867
+
868
+ ### `updateMoviePoster(movieId: string, poster: FormData, type: string): Promise<void>`
869
+
870
+ Updates a movie poster image.
871
+
872
+ **Parameters:**
873
+
874
+ - `movieId`: The ID of the movie
875
+ - `poster`: FormData containing the poster image
876
+ - `type`: Poster type
877
+
878
+ **Example:**
879
+
880
+ ```typescript
881
+ const formData = new FormData();
882
+ formData.append('file', posterBlob);
883
+ await libraryApi.updateMoviePoster('movie-id', formData, 'poster');
884
+ ```
885
+
886
+ ### `updateMovieImageFetch(movieId: string, image: ExternalImage): Promise<void>`
887
+
888
+ Fetches and sets an external image as movie poster.
889
+
890
+ **Parameters:**
891
+
892
+ - `movieId`: The ID of the movie
893
+ - `image`: External image object to fetch
894
+
895
+ **Example:**
896
+
897
+ ```typescript
898
+ await libraryApi.updateMovieImageFetch('movie-id', externalImage);
899
+ ```
900
+
901
+ ---
902
+
903
+ ## Media
904
+
905
+ ### `getMedias(filter?: MediaRequest): Promise<IFile[]>`
906
+
907
+ Retrieves media files with optional filtering.
908
+
909
+ **Parameters:**
910
+
911
+ - `filter`: Optional `MediaRequest` object for filtering/sorting
912
+
913
+ **Returns:** Promise resolving to an array of `IFile` objects
914
+
915
+ **Example:**
916
+
917
+ ```typescript
918
+ // Get all media
919
+ const allMedias = await libraryApi.getMedias();
920
+
921
+ // Get filtered media
922
+ const photos = await libraryApi.getMedias({
923
+ type: 'photo',
924
+ limit: 50,
925
+ offset: 0
926
+ });
927
+ ```
928
+
929
+ ### `getMedia(mediaId: string, options?: { type?: 'stream' | 'arraybuffer' | 'blob' }): Promise<ReadableStream | ArrayBuffer | Blob>`
930
+
931
+ Downloads a media file.
932
+
933
+ **Parameters:**
934
+
935
+ - `mediaId`: The ID of the media
936
+ - `options`: Optional object with `type` property ('stream', 'arraybuffer', or 'blob')
937
+
938
+ **Returns:** Promise resolving to the media data in the requested format
939
+
940
+ **Example:**
941
+
942
+ ```typescript
943
+ // Get as blob
944
+ const blob = await libraryApi.getMedia('media-id', { type: 'blob' });
945
+
946
+ // Get as stream
947
+ const stream = await libraryApi.getMedia('media-id', { type: 'stream' });
948
+
949
+ // For encrypted libraries, decrypt after getting
950
+ if (library.crypt) {
951
+ const encryptedBlob = await libraryApi.getMedia('media-id', { type: 'arraybuffer' });
952
+ const decrypted = await libraryApi.decryptFile('passphrase', encryptedBlob);
953
+ }
954
+ ```
955
+
956
+ ### `getThumb(mediaId: string, options?: { type?: 'stream' | 'arraybuffer' | 'blob' }): Promise<ReadableStream | ArrayBuffer | Blob>`
957
+
958
+ Gets a media thumbnail.
959
+
960
+ **Parameters:**
961
+
962
+ - `mediaId`: The ID of the media
963
+ - `options`: Optional object with `type` property
964
+
965
+ **Returns:** Promise resolving to the thumbnail data
966
+
967
+ **Example:**
968
+
969
+ ```typescript
970
+ // Get thumbnail as blob
971
+ const thumbBlob = await libraryApi.getThumb('media-id', { type: 'blob' });
972
+
973
+ // For encrypted libraries, decrypt thumbnail
974
+ if (library.crypt) {
975
+ const media = await libraryApi.getMediaMetadata('media-id');
976
+ const iv = uint8ArrayFromBase64(media.iv!);
977
+ const encryptedThumb = await libraryApi.getThumb('media-id', { type: 'arraybuffer' });
978
+ const decryptedThumb = await libraryApi.decryptMedia('passphrase', encryptedThumb, iv);
979
+ }
980
+ ```
981
+
982
+ ### `getMediaMetadata(mediaId: string): Promise<IFile>`
983
+
984
+ Gets metadata for a media file.
985
+
986
+ **Parameters:**
987
+
988
+ - `mediaId`: The ID of the media
989
+
990
+ **Returns:** Promise resolving to `IFile` object with metadata
991
+
992
+ **Example:**
993
+
994
+ ```typescript
995
+ const metadata = await libraryApi.getMediaMetadata('media-id');
996
+ console.log(`File: ${metadata.name}, Size: ${metadata.size}`);
997
+ ```
998
+
999
+ ### `getMediaBackupMetadatas(mediaId: string): Promise<IBackupFile[]>`
1000
+
1001
+ Gets backup metadata for a media file.
1002
+
1003
+ **Parameters:**
1004
+
1005
+ - `mediaId`: The ID of the media
1006
+
1007
+ **Returns:** Promise resolving to an array of `IBackupFile` objects
1008
+
1009
+ **Example:**
1010
+
1011
+ ```typescript
1012
+ const backups = await libraryApi.getMediaBackupMetadatas('media-id');
1013
+ ```
1014
+
1015
+ ### `uploadMedia(data: ArrayBuffer | Uint8Array, options: UploadMediaOptions): Promise<IFile>`
1016
+
1017
+ Uploads a media file to the library.
1018
+
1019
+ **Parameters:**
1020
+
1021
+ - `data`: File data as `ArrayBuffer` or `Uint8Array`
1022
+ - `options`: Upload options object:
1023
+ - `thumb?`: Optional thumbnail data (`ArrayBuffer` or `Uint8Array`) - only for encrypted libraries
1024
+ - `metadata`: Media metadata (see `MediaForUpdate` interface)
1025
+ - `fileMime`: MIME type of the file (e.g., 'image/jpeg')
1026
+ - `thumbMime?`: Optional MIME type of thumbnail (default: 'image/jpeg')
1027
+ - `progressCallback?`: Optional callback for upload progress `(loaded: number, total: number) => void`
1028
+
1029
+ **Returns:** Promise resolving to the created `IFile` object
1030
+
1031
+ **Throws:** Error if encryption key not set for encrypted libraries, or if thumbnail provided for non-encrypted libraries
1032
+
1033
+ **Example:**
1034
+
1035
+ ```typescript
1036
+ // Upload to non-encrypted library
1037
+ const fileData = await file.arrayBuffer();
1038
+ const uploaded = await libraryApi.uploadMedia(fileData, {
1039
+ metadata: {
1040
+ name: 'photo.jpg',
1041
+ description: 'My photo'
1042
+ },
1043
+ fileMime: 'image/jpeg',
1044
+ progressCallback: (loaded, total) => {
1045
+ console.log(`Upload: ${((loaded / total) * 100).toFixed(1)}%`);
1046
+ }
1047
+ });
1048
+
1049
+ // Upload to encrypted library
1050
+ if (library.crypt) {
1051
+ await libraryApi.setKey('passphrase');
1052
+ const fileData = await file.arrayBuffer();
1053
+ const thumbData = await thumbnail.arrayBuffer();
1054
+
1055
+ const uploaded = await libraryApi.uploadMedia(fileData, {
1056
+ thumb: thumbData,
1057
+ metadata: {
1058
+ name: 'photo.jpg'
1059
+ },
1060
+ fileMime: 'image/jpeg',
1061
+ thumbMime: 'image/jpeg'
1062
+ });
1063
+ // uploaded.iv contains the IV for decryption
1064
+ }
1065
+ ```
1066
+
1067
+ ### `removeMedias(mediaIds: string[]): Promise<void>`
1068
+
1069
+ Deletes multiple media files.
1070
+
1071
+ **Parameters:**
1072
+
1073
+ - `mediaIds`: Array of media IDs to delete
1074
+
1075
+ **Example:**
1076
+
1077
+ ```typescript
1078
+ await libraryApi.removeMedias(['media-1', 'media-2', 'media-3']);
1079
+ ```
1080
+
1081
+ ### `mediaTransfer(formData: FormData): Promise<void>`
1082
+
1083
+ Transfers media using FormData (legacy method).
1084
+
1085
+ **Parameters:**
1086
+
1087
+ - `formData`: FormData containing transfer information
1088
+
1089
+ **Example:**
1090
+
1091
+ ```typescript
1092
+ const formData = new FormData();
1093
+ formData.append('ids', JSON.stringify(['media-1', 'media-2']));
1094
+ formData.append('toLibrary', 'target-library-id');
1095
+ await libraryApi.mediaTransfer(formData);
1096
+ ```
1097
+
1098
+ ### `mediaTransferMany(medias: string[], deleteOriginal: boolean, toLibraryId: string): Promise<void>`
1099
+
1100
+ Transfers multiple media files to another library.
1101
+
1102
+ **Parameters:**
1103
+
1104
+ - `medias`: Array of media IDs to transfer
1105
+ - `deleteOriginal`: Whether to delete originals after transfer
1106
+ - `toLibraryId`: Target library ID
1107
+
1108
+ **Example:**
1109
+
1110
+ ```typescript
1111
+ await libraryApi.mediaTransferMany(
1112
+ ['media-1', 'media-2'],
1113
+ false, // Keep originals
1114
+ 'target-library-id'
1115
+ );
1116
+ ```
1117
+
1118
+ ### `mediaTransferSingle(mediaId: string, toLibraryId: string, formData: FormData, params?: Map<string, string>): Promise<void>`
1119
+
1120
+ Transfers a single media file to another library.
1121
+
1122
+ **Parameters:**
1123
+
1124
+ - `mediaId`: The ID of the media to transfer
1125
+ - `toLibraryId`: Target library ID
1126
+ - `formData`: FormData with additional transfer data
1127
+ - `params`: Optional query parameters
1128
+
1129
+ **Example:**
1130
+
1131
+ ```typescript
1132
+ const formData = new FormData();
1133
+ formData.append('option', 'value');
1134
+ await libraryApi.mediaTransferSingle('media-id', 'target-library-id', formData);
1135
+ ```
1136
+
1137
+ ### `addTagToMedia(mediaId: string, tagId: string): Promise<void>`
1138
+
1139
+ Adds a tag to a media file.
1140
+
1141
+ **Parameters:**
1142
+
1143
+ - `mediaId`: The ID of the media
1144
+ - `tagId`: The ID of the tag to add
1145
+
1146
+ **Example:**
1147
+
1148
+ ```typescript
1149
+ await libraryApi.addTagToMedia('media-id', 'tag-id');
1150
+ ```
1151
+
1152
+ ### `removeTagFromMedia(mediaId: string, tagId: string): Promise<void>`
1153
+
1154
+ Removes a tag from a media file.
1155
+
1156
+ **Parameters:**
1157
+
1158
+ - `mediaId`: The ID of the media
1159
+ - `tagId`: The ID of the tag to remove
1160
+
1161
+ **Example:**
1162
+
1163
+ ```typescript
1164
+ await libraryApi.removeTagFromMedia('media-id', 'tag-id');
1165
+ ```
1166
+
1167
+ ### `mediaUpdate(mediaId: string, update: any): Promise<IFile[]>`
1168
+
1169
+ Updates a media file's metadata.
1170
+
1171
+ **Parameters:**
1172
+
1173
+ - `mediaId`: The ID of the media
1174
+ - `update`: Update object (see `MediaForUpdate` interface)
1175
+
1176
+ **Returns:** Promise resolving to an array of updated `IFile` objects
1177
+
1178
+ **Example:**
1179
+
1180
+ ```typescript
1181
+ await libraryApi.mediaUpdate('media-id', {
1182
+ description: 'New description',
1183
+ rating: 5
1184
+ });
1185
+ ```
1186
+
1187
+ ### `mediaUpdateMany(update: any, ids: string[]): Promise<IFile[]>`
1188
+
1189
+ Updates multiple media files.
1190
+
1191
+ **Parameters:**
1192
+
1193
+ - `update`: Update object
1194
+ - `ids`: Array of media IDs to update
1195
+
1196
+ **Returns:** Promise resolving to an array of updated `IFile` objects
1197
+
1198
+ **Example:**
1199
+
1200
+ ```typescript
1201
+ await libraryApi.mediaUpdateMany({ rating: 5 }, ['media-1', 'media-2', 'media-3']);
1202
+ ```
1203
+
1204
+ ### `mediaUpdateProgress(mediaId: string, progress: number): Promise<{ progress: number }>`
1205
+
1206
+ Updates the watch progress for a media file.
1207
+
1208
+ **Parameters:**
1209
+
1210
+ - `mediaId`: The ID of the media
1211
+ - `progress`: Progress value (0-100 or time-based)
1212
+
1213
+ **Returns:** Promise resolving to object with updated progress
1214
+
1215
+ **Example:**
1216
+
1217
+ ```typescript
1218
+ await libraryApi.mediaUpdateProgress('media-id', 50);
1219
+ ```
1220
+
1221
+ ### `mediaUpdateChannel(mediaId: string, update: any): Promise<IFile[]>`
1222
+
1223
+ Updates channel information for a media file.
1224
+
1225
+ **Parameters:**
1226
+
1227
+ - `mediaId`: The ID of the media
1228
+ - `update`: Channel update object
1229
+
1230
+ **Returns:** Promise resolving to an array of updated `IFile` objects
1231
+
1232
+ **Example:**
1233
+
1234
+ ```typescript
1235
+ await libraryApi.mediaUpdateChannel('media-id', { channel: 'new-channel' });
1236
+ ```
1237
+
1238
+ ### `refreshMedia(mediaId: string): Promise<IFile[]>`
1239
+
1240
+ Refreshes metadata for a media file.
1241
+
1242
+ **Parameters:**
1243
+
1244
+ - `mediaId`: The ID of the media
1245
+
1246
+ **Returns:** Promise resolving to an array of updated `IFile` objects
1247
+
1248
+ **Example:**
1249
+
1250
+ ```typescript
1251
+ await libraryApi.refreshMedia('media-id');
1252
+ ```
1253
+
1254
+ ### `aiTagMedia(mediaId: string): Promise<IFile[]>`
1255
+
1256
+ Triggers AI tagging for a media file.
1257
+
1258
+ **Parameters:**
1259
+
1260
+ - `mediaId`: The ID of the media
1261
+
1262
+ **Returns:** Promise resolving to an array of updated `IFile` objects with new tags
1263
+
1264
+ **Example:**
1265
+
1266
+ ```typescript
1267
+ await libraryApi.aiTagMedia('media-id');
1268
+ ```
1269
+
1270
+ ### `splitZip(mediaId: string, from: number, to: number): Promise<IFile>`
1271
+
1272
+ Splits a ZIP archive into a new archive containing pages from `from` to `to`.
1273
+
1274
+ **Parameters:**
1275
+
1276
+ - `mediaId`: The ID of the ZIP media
1277
+ - `from`: Starting page number
1278
+ - `to`: Ending page number
1279
+
1280
+ **Returns:** Promise resolving to the new `IFile` object
1281
+
1282
+ **Example:**
1283
+
1284
+ ```typescript
1285
+ const newZip = await libraryApi.splitZip('zip-id', 1, 10);
1286
+ ```
1287
+
1288
+ ### `deleteFromZip(mediaId: string, pages: number[]): Promise<IFile>`
1289
+
1290
+ Deletes pages from a ZIP archive.
1291
+
1292
+ **Parameters:**
1293
+
1294
+ - `mediaId`: The ID of the ZIP media
1295
+ - `pages`: Array of page numbers to delete
1296
+
1297
+ **Returns:** Promise resolving to the updated `IFile` object
1298
+
1299
+ **Example:**
1300
+
1301
+ ```typescript
1302
+ await libraryApi.deleteFromZip('zip-id', [5, 6, 7]);
1303
+ ```
1304
+
1305
+ ### `updateMediaThumb(mediaId: string, thumb: FormData): Promise<void>`
1306
+
1307
+ Updates the thumbnail for a media file.
1308
+
1309
+ **Parameters:**
1310
+
1311
+ - `mediaId`: The ID of the media
1312
+ - `thumb`: FormData containing the thumbnail image
1313
+
1314
+ **Example:**
1315
+
1316
+ ```typescript
1317
+ const formData = new FormData();
1318
+ formData.append('file', thumbBlob);
1319
+ await libraryApi.updateMediaThumb('media-id', formData);
1320
+ ```
1321
+
1322
+ ### `getMediaShares(mediaId: string): Promise<any>`
1323
+
1324
+ Gets sharing information for a media file.
1325
+
1326
+ **Parameters:**
1327
+
1328
+ - `mediaId`: The ID of the media
1329
+
1330
+ **Returns:** Promise resolving to sharing information
1331
+
1332
+ **Example:**
1333
+
1334
+ ```typescript
1335
+ const shares = await libraryApi.getMediaShares('media-id');
1336
+ ```
1337
+
1338
+ ### `shareMediaToProvider(mediaId: string, provider: string, formData?: FormData): Promise<any>`
1339
+
1340
+ Shares a media file to an external provider.
1341
+
1342
+ **Parameters:**
1343
+
1344
+ - `mediaId`: The ID of the media
1345
+ - `provider`: Provider name (e.g., 'instagram', 'twitter')
1346
+ - `formData`: Optional FormData with additional sharing data
1347
+
1348
+ **Returns:** Promise resolving to sharing result
1349
+
1350
+ **Example:**
1351
+
1352
+ ```typescript
1353
+ const result = await libraryApi.shareMediaToProvider('media-id', 'instagram');
1354
+ ```
1355
+
1356
+ ---
1357
+
1358
+ ## Faces
1359
+
1360
+ ### `getUnassignedFaces(params?: Map<string, string>): Promise<any>`
1361
+
1362
+ Gets unassigned faces (faces not yet linked to a person).
1363
+
1364
+ **Parameters:**
1365
+
1366
+ - `params`: Optional query parameters
1367
+
1368
+ **Returns:** Promise resolving to unassigned faces data
1369
+
1370
+ **Example:**
1371
+
1372
+ ```typescript
1373
+ const params = new Map([['limit', '50']]);
1374
+ const faces = await libraryApi.getUnassignedFaces(params);
1375
+ ```
1376
+
1377
+ ### `getClusters(): Promise<any>`
1378
+
1379
+ Gets face clusters (groups of similar faces).
1380
+
1381
+ **Returns:** Promise resolving to clusters data
1382
+
1383
+ **Example:**
1384
+
1385
+ ```typescript
1386
+ const clusters = await libraryApi.getClusters();
1387
+ ```
1388
+
1389
+ ### `assignFaces(request: any): Promise<any>`
1390
+
1391
+ Assigns faces to a person.
1392
+
1393
+ **Parameters:**
1394
+
1395
+ - `request`: Assignment request object with face IDs and person ID
1396
+
1397
+ **Returns:** Promise resolving to assignment result
1398
+
1399
+ **Example:**
1400
+
1401
+ ```typescript
1402
+ await libraryApi.assignFaces({
1403
+ faceIds: ['face-1', 'face-2'],
1404
+ personId: 'person-id'
1405
+ });
1406
+ ```
1407
+
1408
+ ### `createPersonFromCluster(request: any): Promise<any>`
1409
+
1410
+ Creates a new person from a face cluster.
1411
+
1412
+ **Parameters:**
1413
+
1414
+ - `request`: Request object with cluster ID and person name
1415
+
1416
+ **Returns:** Promise resolving to created person
1417
+
1418
+ **Example:**
1419
+
1420
+ ```typescript
1421
+ await libraryApi.createPersonFromCluster({
1422
+ clusterId: 'cluster-id',
1423
+ name: 'John Doe'
1424
+ });
1425
+ ```
1426
+
1427
+ ### `splitCluster(request: any): Promise<any>`
1428
+
1429
+ Splits a face cluster into multiple clusters.
1430
+
1431
+ **Parameters:**
1432
+
1433
+ - `request`: Split request object
1434
+
1435
+ **Returns:** Promise resolving to split result
1436
+
1437
+ **Example:**
1438
+
1439
+ ```typescript
1440
+ await libraryApi.splitCluster({
1441
+ clusterId: 'cluster-id',
1442
+ faceIds: ['face-1', 'face-2']
1443
+ });
1444
+ ```
1445
+
1446
+ ### `unassignFace(request: any): Promise<any>`
1447
+
1448
+ Unassigns a face from a person.
1449
+
1450
+ **Parameters:**
1451
+
1452
+ - `request`: Unassign request object with face ID
1453
+
1454
+ **Returns:** Promise resolving to unassign result
1455
+
1456
+ **Example:**
1457
+
1458
+ ```typescript
1459
+ await libraryApi.unassignFace({ faceId: 'face-id' });
1460
+ ```
1461
+
1462
+ ### `deleteFace(faceId: string): Promise<any>`
1463
+
1464
+ Deletes a face.
1465
+
1466
+ **Parameters:**
1467
+
1468
+ - `faceId`: The ID of the face to delete
1469
+
1470
+ **Returns:** Promise resolving to deletion result
1471
+
1472
+ **Example:**
1473
+
1474
+ ```typescript
1475
+ await libraryApi.deleteFace('face-id');
1476
+ ```
1477
+
1478
+ ### `getAssignedFaces(personId: string): Promise<any>`
1479
+
1480
+ Gets all faces assigned to a person.
1481
+
1482
+ **Parameters:**
1483
+
1484
+ - `personId`: The ID of the person
1485
+
1486
+ **Returns:** Promise resolving to assigned faces
1487
+
1488
+ **Example:**
1489
+
1490
+ ```typescript
1491
+ const faces = await libraryApi.getAssignedFaces('person-id');
1492
+ ```
1493
+
1494
+ ### `faceClusterPerson(personId: string): Promise<void>`
1495
+
1496
+ Triggers face clustering for a person.
1497
+
1498
+ **Parameters:**
1499
+
1500
+ - `personId`: The ID of the person
1501
+
1502
+ **Example:**
1503
+
1504
+ ```typescript
1505
+ await libraryApi.faceClusterPerson('person-id');
1506
+ ```
1507
+
1508
+ ### `mergePeople(request: any): Promise<any>`
1509
+
1510
+ Merges multiple people into one.
1511
+
1512
+ **Parameters:**
1513
+
1514
+ - `request`: Merge request object with source and target person IDs
1515
+
1516
+ **Returns:** Promise resolving to merge result
1517
+
1518
+ **Example:**
1519
+
1520
+ ```typescript
1521
+ await libraryApi.mergePeople({
1522
+ fromIds: ['person-1', 'person-2'],
1523
+ intoId: 'person-3'
1524
+ });
1525
+ ```
1526
+
1527
+ ### `clusterFaces(personId: string): Promise<any>`
1528
+
1529
+ Clusters faces for a person.
1530
+
1531
+ **Parameters:**
1532
+
1533
+ - `personId`: The ID of the person
1534
+
1535
+ **Returns:** Promise resolving to clustering result
1536
+
1537
+ **Example:**
1538
+
1539
+ ```typescript
1540
+ await libraryApi.clusterFaces('person-id');
1541
+ ```
1542
+
1543
+ ---
1544
+
1545
+ ## Encryption
1546
+
1547
+ These methods are convenience wrappers around the encryption module. For detailed encryption documentation, see [encryption.md](encryption.md).
1548
+
1549
+ ### `encryptText(passPhrase: string, text: string): Promise<string>`
1550
+
1551
+ Encrypts a text string using a passphrase.
1552
+
1553
+ **Parameters:**
1554
+
1555
+ - `passPhrase`: The passphrase to derive the key from
1556
+ - `text`: The plaintext to encrypt
1557
+
1558
+ **Returns:** Promise resolving to encrypted string in format `${IV}.${encryptedData}` (base64url encoded)
1559
+
1560
+ **Example:**
1561
+
1562
+ ```typescript
1563
+ const encrypted = await libraryApi.encryptText('password', 'Hello World');
1564
+ ```
1565
+
1566
+ ### `decryptText(passPhrase: string, encryptedText: string): Promise<string>`
1567
+
1568
+ Decrypts a text string using a passphrase.
1569
+
1570
+ **Parameters:**
1571
+
1572
+ - `passPhrase`: The passphrase to derive the key from
1573
+ - `encryptedText`: The encrypted text in format `${IV}.${encryptedData}`
1574
+
1575
+ **Returns:** Promise resolving to decrypted plaintext
1576
+
1577
+ **Example:**
1578
+
1579
+ ```typescript
1580
+ const decrypted = await libraryApi.decryptText('password', encryptedText);
1581
+ ```
1582
+
1583
+ ### `encryptMedia(passPhrase: string, buffer: ArrayBuffer | Uint8Array, iv?: ArrayBuffer | Uint8Array): Promise<ArrayBuffer>`
1584
+
1585
+ Encrypts binary media data using a passphrase.
1586
+
1587
+ **Parameters:**
1588
+
1589
+ - `passPhrase`: The passphrase to derive the key from
1590
+ - `buffer`: The binary data to encrypt
1591
+ - `iv`: Optional IV (if not provided, a random one is generated)
1592
+
1593
+ **Returns:** Promise resolving to encrypted ArrayBuffer
1594
+
1595
+ **Example:**
1596
+
1597
+ ```typescript
1598
+ const encrypted = await libraryApi.encryptMedia('password', fileBuffer);
1599
+ ```
1600
+
1601
+ ### `decryptMedia(passPhrase: string, buffer: ArrayBuffer | Uint8Array, iv: ArrayBuffer | Uint8Array): Promise<ArrayBuffer>`
1602
+
1603
+ Decrypts binary media data using a passphrase.
1604
+
1605
+ **Parameters:**
1606
+
1607
+ - `passPhrase`: The passphrase to derive the key from
1608
+ - `buffer`: The encrypted binary data
1609
+ - `iv`: The IV used during encryption
1610
+
1611
+ **Returns:** Promise resolving to decrypted ArrayBuffer
1612
+
1613
+ **Example:**
1614
+
1615
+ ```typescript
1616
+ const decrypted = await libraryApi.decryptMedia('password', encryptedBuffer, iv);
1617
+ ```
1618
+
1619
+ ### `encryptFile(passPhrase: string, options: EncryptFileOptions): Promise<EncryptedFile>`
1620
+
1621
+ Encrypts a complete file with thumbnail and metadata.
1622
+
1623
+ **Parameters:**
1624
+
1625
+ - `passPhrase`: The passphrase to derive the key from
1626
+ - `options`: Encryption options (see `EncryptFileOptions` interface)
1627
+
1628
+ **Returns:** Promise resolving to `EncryptedFile` object
1629
+
1630
+ **Example:**
1631
+
1632
+ ```typescript
1633
+ const encrypted = await libraryApi.encryptFile('password', {
1634
+ filename: 'photo.jpg',
1635
+ buffer: fileBuffer,
1636
+ thumb: thumbBuffer,
1637
+ thumbMime: 'image/jpeg',
1638
+ mime: 'image/jpeg'
1639
+ });
1640
+ ```
1641
+
1642
+ ### `decryptFile(passPhrase: string, buffer: ArrayBuffer): Promise<ArrayBuffer>`
1643
+
1644
+ Decrypts file data from an encrypted file structure.
1645
+
1646
+ **Parameters:**
1647
+
1648
+ - `passPhrase`: The passphrase to derive the key from
1649
+ - `buffer`: The complete encrypted file structure
1650
+
1651
+ **Returns:** Promise resolving to decrypted file ArrayBuffer
1652
+
1653
+ **Example:**
1654
+
1655
+ ```typescript
1656
+ const decrypted = await libraryApi.decryptFile('password', encryptedFileBlob);
1657
+ ```
1658
+
1659
+ ### `decryptMediaThumb(passPhrase: string, buffer: ArrayBuffer): Promise<ArrayBuffer>`
1660
+
1661
+ Decrypts thumbnail from an encrypted file structure.
1662
+
1663
+ **Parameters:**
1664
+
1665
+ - `passPhrase`: The passphrase to derive the key from
1666
+ - `buffer`: The complete encrypted file structure
1667
+
1668
+ **Returns:** Promise resolving to decrypted thumbnail ArrayBuffer
1669
+
1670
+ **Example:**
1671
+
1672
+ ```typescript
1673
+ const decryptedThumb = await libraryApi.decryptMediaThumb('password', encryptedFileBlob);
1674
+ ```
1675
+
1676
+ ### `encryptFilename(passPhrase: string, filename: string, iv: ArrayBuffer | Uint8Array): Promise<string>`
1677
+
1678
+ Encrypts a filename using a passphrase and IV.
1679
+
1680
+ **Parameters:**
1681
+
1682
+ - `passPhrase`: The passphrase to derive the key from
1683
+ - `filename`: The filename to encrypt
1684
+ - `iv`: The IV to use (should match the file's IV)
1685
+
1686
+ **Returns:** Promise resolving to base64url encoded encrypted filename
1687
+
1688
+ **Example:**
1689
+
1690
+ ```typescript
1691
+ const iv = libraryApi.getRandomIV();
1692
+ const encryptedFilename = await libraryApi.encryptFilename('password', 'photo.jpg', iv);
1693
+ ```
1694
+
1695
+ ### `getRandomIV(): Uint8Array`
1696
+
1697
+ Generates a random 16-byte IV (Initialization Vector).
1698
+
1699
+ **Returns:** `Uint8Array` of 16 random bytes
1700
+
1701
+ **Example:**
1702
+
1703
+ ```typescript
1704
+ const iv = libraryApi.getRandomIV();
1705
+ ```
1706
+
1707
+ ---
1708
+
1709
+ ## Utilities
1710
+
1711
+ ### `getCryptChallenge(): Promise<string>`
1712
+
1713
+ Gets a cryptographic challenge for encryption verification.
1714
+
1715
+ **Returns:** Promise resolving to challenge string
1716
+
1717
+ **Example:**
1718
+
1719
+ ```typescript
1720
+ const challenge = await libraryApi.getCryptChallenge();
1721
+ ```
1722
+
1723
+ ### `getChannels(): Promise<any[]>`
1724
+
1725
+ Gets all channels (for IPTV libraries).
1726
+
1727
+ **Returns:** Promise resolving to an array of channel objects
1728
+
1729
+ **Example:**
1730
+
1731
+ ```typescript
1732
+ const channels = await libraryApi.getChannels();
1733
+ ```
1734
+
1735
+ ### `getWatermarks(): Promise<string[]>`
1736
+
1737
+ Gets list of available watermark names.
1738
+
1739
+ **Returns:** Promise resolving to an array of watermark names
1740
+
1741
+ **Example:**
1742
+
1743
+ ```typescript
1744
+ const watermarks = await libraryApi.getWatermarks();
1745
+ ```
1746
+
1747
+ ### `getWatermark(watermark: string, options?: { type?: 'blob' | 'arraybuffer' }): Promise<Blob | ArrayBuffer>`
1748
+
1749
+ Gets a watermark image.
1750
+
1751
+ **Parameters:**
1752
+
1753
+ - `watermark`: Watermark name (or 'default')
1754
+ - `options`: Optional object with `type` property
1755
+
1756
+ **Returns:** Promise resolving to watermark data
1757
+
1758
+ **Example:**
1759
+
1760
+ ```typescript
1761
+ const watermark = await libraryApi.getWatermark('default', { type: 'blob' });
1762
+ ```
1763
+
1764
+ ### `expandUrl(parsedUrl: any): Promise<string | undefined>`
1765
+
1766
+ Expands a parsed URL using plugins.
1767
+
1768
+ **Parameters:**
1769
+
1770
+ - `parsedUrl`: Parsed URL object
1771
+
1772
+ **Returns:** Promise resolving to expanded URL or undefined
1773
+
1774
+ **Example:**
1775
+
1776
+ ```typescript
1777
+ const expanded = await libraryApi.expandUrl(parsedUrl);
1778
+ ```
1779
+
1780
+ ### `parseUrl(url: string): Promise<any>`
1781
+
1782
+ Parses a URL using plugins.
1783
+
1784
+ **Parameters:**
1785
+
1786
+ - `url`: URL string to parse
1787
+
1788
+ **Returns:** Promise resolving to parsed URL object
1789
+
1790
+ **Example:**
1791
+
1792
+ ```typescript
1793
+ const parsed = await libraryApi.parseUrl('https://example.com/video');
1794
+ ```
1795
+
1796
+ ### `listVideoConvertPlugins(): Promise<any[]>`
1797
+
1798
+ Lists available video conversion plugins.
1799
+
1800
+ **Returns:** Promise resolving to an array of plugin objects
1801
+
1802
+ **Example:**
1803
+
1804
+ ```typescript
1805
+ const plugins = await libraryApi.listVideoConvertPlugins();
1806
+ ```
1807
+
1808
+ ### `clean(): Promise<string>`
1809
+
1810
+ Triggers library cleanup operation.
1811
+
1812
+ **Returns:** Promise resolving to cleanup result message
1813
+
1814
+ **Example:**
1815
+
1816
+ ```typescript
1817
+ const result = await libraryApi.clean();
1818
+ ```
1819
+
1820
+ ### `locs(): Promise<any>`
1821
+
1822
+ Gets location data.
1823
+
1824
+ **Returns:** Promise resolving to location data
1825
+
1826
+ **Example:**
1827
+
1828
+ ```typescript
1829
+ const locations = await libraryApi.locs();
1830
+ ```
1831
+
1832
+ ### `mergeMedias(request: any): Promise<IFile>`
1833
+
1834
+ Merges multiple media files into one.
1835
+
1836
+ **Parameters:**
1837
+
1838
+ - `request`: Merge request object with media IDs
1839
+
1840
+ **Returns:** Promise resolving to merged `IFile` object
1841
+
1842
+ **Example:**
1843
+
1844
+ ```typescript
1845
+ const merged = await libraryApi.mergeMedias({
1846
+ ids: ['media-1', 'media-2']
1847
+ });
1848
+ ```
1849
+
1850
+ ---
1851
+
1852
+ ## Common Workflows
1853
+
1854
+ ### Uploading Media to Encrypted Library
1855
+
1856
+ ```typescript
1857
+ // 1. Set encryption key
1858
+ await libraryApi.setKey('my-password');
1859
+
1860
+ // 2. Prepare file and thumbnail
1861
+ const fileData = await file.arrayBuffer();
1862
+ const thumbData = await thumbnail.arrayBuffer();
1863
+
1864
+ // 3. Upload with progress tracking
1865
+ const uploaded = await libraryApi.uploadMedia(fileData, {
1866
+ thumb: thumbData,
1867
+ metadata: {
1868
+ name: 'photo.jpg',
1869
+ description: 'My encrypted photo'
1870
+ },
1871
+ fileMime: 'image/jpeg',
1872
+ thumbMime: 'image/jpeg',
1873
+ progressCallback: (loaded, total) => {
1874
+ console.log(`Upload: ${((loaded / total) * 100).toFixed(1)}%`);
1875
+ }
1876
+ });
1877
+
1878
+ console.log(`Uploaded with IV: ${uploaded.iv}`);
1879
+ ```
1880
+
1881
+ ### Downloading and Decrypting Media
1882
+
1883
+ ```typescript
1884
+ // 1. Set encryption key
1885
+ await libraryApi.setKey('my-password');
1886
+
1887
+ // 2. Get media metadata
1888
+ const metadata = await libraryApi.getMediaMetadata('media-id');
1889
+
1890
+ // 3. Download encrypted file
1891
+ const encryptedBlob = await libraryApi.getMedia('media-id', { type: 'arraybuffer' });
1892
+
1893
+ // 4. Decrypt file
1894
+ const decrypted = await libraryApi.decryptFile('my-password', encryptedBlob);
1895
+
1896
+ // 5. Use decrypted data
1897
+ const blob = new Blob([decrypted], { type: metadata.mimetype });
1898
+ const url = URL.createObjectURL(blob);
1899
+ ```
1900
+
1901
+ ### Tagging Media
1902
+
1903
+ ```typescript
1904
+ // 1. Get or create tags
1905
+ const tags = await libraryApi.getTags();
1906
+ let vacationTag = tags.find((t) => t.name === 'Vacation');
1907
+ if (!vacationTag) {
1908
+ vacationTag = await libraryApi.createTag({ name: 'Vacation' });
1909
+ }
1910
+
1911
+ // 2. Add tag to media
1912
+ await libraryApi.addTagToMedia('media-id', vacationTag.id!);
1913
+ ```
1914
+
1915
+ ### Managing People and Faces
1916
+
1917
+ ```typescript
1918
+ // 1. Create person
1919
+ const person = await libraryApi.createPerson({ name: 'John Doe' });
1920
+
1921
+ // 2. Get unassigned faces
1922
+ const faces = await libraryApi.getUnassignedFaces();
1923
+
1924
+ // 3. Assign faces to person
1925
+ await libraryApi.assignFaces({
1926
+ faceIds: ['face-1', 'face-2'],
1927
+ personId: person.id!
1928
+ });
1929
+
1930
+ // 4. Cluster faces for better organization
1931
+ await libraryApi.faceClusterPerson(person.id!);
1932
+ ```
1933
+
1934
+ ## Related Documentation
1935
+
1936
+ - [RedseatClient Documentation](client.md) - HTTP client used by LibraryApi
1937
+ - [ServerApi Documentation](server.md) - Server-level operations
1938
+ - [Encryption Documentation](encryption.md) - Detailed encryption module documentation
1939
+ - [README](README.md) - Package overview