@@ -39,7 +39,8 @@ export class ApiService {
39
39
API_URL_GENRES_MOVIE = '/api/genres/movie/' ;
40
40
API_URL_GENRES_TV = '/api/genres/tv/' ;
41
41
API_URL_MEDIA_CATEGORIES = '/api/media-categories/' ;
42
- API_URL_QUALITY_PROFILES = '/api/quality-profiles/' ;
42
+ API_URL_QUALITIES = '/api/qualities/' ;
43
+ API_URL_QUALITY_PROFILES = '/api/quality-profile/' ;
43
44
API_URL_GIT_COMMIT = '/api/git-commit/' ;
44
45
API_URL_IMPORT_MEDIA_TV = '/api/import/media/tv/' ;
45
46
API_URL_IMPORT_MEDIA_MOVIE = '/api/import/media/movie/' ;
@@ -55,7 +56,8 @@ export class ApiService {
55
56
public userToken : string ;
56
57
public users : any ; // staff-only list of all users
57
58
public settings : any ;
58
- public qualityProfiles : string [ ] ;
59
+ public qualities : string [ ] = [ ] ;
60
+ public qualityProfiles : any [ ] = [ ] ;
59
61
public mediaCategories : string [ ] ;
60
62
public watchTVSeasons : any [ ] = [ ] ;
61
63
public watchTVSeasonRequests : any [ ] = [ ] ;
@@ -180,6 +182,7 @@ export class ApiService {
180
182
}
181
183
} )
182
184
) ,
185
+ this . fetchQualities ( ) ,
183
186
this . fetchQualityProfiles ( ) ,
184
187
this . fetchMediaCategories ( ) ,
185
188
] ) . pipe (
@@ -211,7 +214,7 @@ export class ApiService {
211
214
) ;
212
215
}
213
216
214
- public fetchSettings ( ) {
217
+ public fetchSettings ( ) : Observable < any > {
215
218
return this . http . get ( this . API_URL_SETTINGS , { headers : this . _requestHeaders ( ) } ) . pipe (
216
219
map ( ( data : any ) => {
217
220
if ( data . length ) {
@@ -224,7 +227,7 @@ export class ApiService {
224
227
) ;
225
228
}
226
229
227
- public fetchMediaCategories ( ) {
230
+ public fetchMediaCategories ( ) : Observable < string [ ] > {
228
231
return this . http . get ( this . API_URL_MEDIA_CATEGORIES , { headers : this . _requestHeaders ( ) } ) . pipe (
229
232
map ( ( data : any ) => {
230
233
if ( data . mediaCategories ) {
@@ -237,11 +240,24 @@ export class ApiService {
237
240
) ;
238
241
}
239
242
240
- public fetchQualityProfiles ( ) {
243
+ public fetchQualities ( ) : Observable < string [ ] > {
244
+ return this . http . get ( this . API_URL_QUALITIES , { headers : this . _requestHeaders ( ) } ) . pipe (
245
+ map ( ( data : any ) => {
246
+ if ( data . length ) {
247
+ this . qualities = data ;
248
+ } else {
249
+ console . error ( 'no qualities' ) ;
250
+ }
251
+ return this . qualities ;
252
+ } ) ,
253
+ ) ;
254
+ }
255
+
256
+ public fetchQualityProfiles ( ) : Observable < any [ ] > {
241
257
return this . http . get ( this . API_URL_QUALITY_PROFILES , { headers : this . _requestHeaders ( ) } ) . pipe (
242
258
map ( ( data : any ) => {
243
- if ( data . profiles ) {
244
- this . qualityProfiles = data . profiles ;
259
+ if ( data . length ) {
260
+ this . qualityProfiles = data ;
245
261
} else {
246
262
console . error ( 'no quality profiles' ) ;
247
263
}
@@ -303,7 +319,7 @@ export class ApiService {
303
319
) ;
304
320
}
305
321
306
- public login ( user : string , pass : string ) {
322
+ public login ( user : string , pass : string ) : Observable < any > {
307
323
const params = {
308
324
username : user ,
309
325
password : pass ,
@@ -313,8 +329,8 @@ export class ApiService {
313
329
console . log ( 'token auth' , data ) ;
314
330
this . userToken = data . token ;
315
331
this . localStorage . set ( this . STORAGE_KEY_API_TOKEN , this . userToken ) . subscribe (
316
- ( wasSet ) => {
317
- console . log ( 'local storage set' , wasSet ) ;
332
+ ( ) => {
333
+ console . log ( 'local storage set' ) ;
318
334
} ,
319
335
( error ) => {
320
336
console . error ( 'local storage error' , error ) ;
@@ -334,15 +350,53 @@ export class ApiService {
334
350
) ;
335
351
}
336
352
337
- public searchTorrents ( query : string , mediaType : string ) {
353
+ public updateQualityProfile ( id : number , params : any ) : Observable < any > {
354
+ return this . http . patch ( `${ this . API_URL_QUALITY_PROFILES } ${ id } /` , params , { headers : this . _requestHeaders ( ) } ) . pipe (
355
+ map ( ( data : any ) => {
356
+ this . qualityProfiles . forEach ( ( profile , index ) => {
357
+ if ( profile . id === id ) {
358
+ this . qualityProfiles [ index ] = params ;
359
+ }
360
+ } )
361
+ } ) ,
362
+ ) ;
363
+ }
364
+
365
+ public deleteQualityProfile ( id : number ) : Observable < any > {
366
+ return this . http . delete ( `${ this . API_URL_QUALITY_PROFILES } ${ id } /` , { headers : this . _requestHeaders ( ) } ) . pipe (
367
+ map ( ( data : any ) => {
368
+ // remove this quality profile
369
+ this . qualityProfiles = this . qualityProfiles . filter ( profile => profile . id !== id ) ;
370
+ // unset quality profile from Movie/TVShow/TVSeasonRequest media records
371
+ [ this . watchMovies , this . watchTVShows , this . watchTVSeasonRequests ] . forEach ( ( watchMediaList ) => {
372
+ watchMediaList . forEach ( ( watchMedia ) => {
373
+ if ( watchMedia . quality_profile === id ) {
374
+ watchMedia . quality_profile = null ;
375
+ }
376
+ } )
377
+ } )
378
+ } ) ,
379
+ ) ;
380
+ }
381
+
382
+ public createQualityProfile ( data : any ) : Observable < any > {
383
+ return this . http . post ( this . API_URL_QUALITY_PROFILES , data , { headers : this . _requestHeaders ( ) } ) . pipe (
384
+ map ( ( data : any ) => {
385
+ // append this new quality profile
386
+ this . qualityProfiles . push ( data ) ;
387
+ } ) ,
388
+ ) ;
389
+ }
390
+
391
+ public searchTorrents ( query : string , mediaType : string ) : Observable < any > {
338
392
return this . http . get ( `${ this . API_URL_SEARCH_TORRENTS } ?q=${ query } &media_type=${ mediaType } ` , { headers : this . _requestHeaders ( ) } ) . pipe (
339
393
map ( ( data : any ) => {
340
394
return data ;
341
395
} ) ,
342
396
) ;
343
397
}
344
398
345
- public download ( torrentResult : any , mediaType : string , tmdbMedia : any , params ?: any ) {
399
+ public download ( torrentResult : any , mediaType : string , tmdbMedia : any , params ?: any ) : Observable < any > {
346
400
// add extra params
347
401
Object . assign ( params || { } , {
348
402
torrent : torrentResult ,
@@ -377,7 +431,7 @@ export class ApiService {
377
431
) ;
378
432
}
379
433
380
- public searchMedia ( query : string , mediaType : string , page = 1 ) {
434
+ public searchMedia ( query : string , mediaType : string , page = 1 ) : Observable < any > {
381
435
let params = {
382
436
q : query ,
383
437
media_type : mediaType ,
@@ -392,7 +446,7 @@ export class ApiService {
392
446
) ;
393
447
}
394
448
395
- public searchSimilarMedia ( tmdbMediaId : string , mediaType : string ) {
449
+ public searchSimilarMedia ( tmdbMediaId : string , mediaType : string ) : Observable < any > {
396
450
let params = {
397
451
tmdb_media_id : tmdbMediaId ,
398
452
media_type : mediaType ,
@@ -407,7 +461,7 @@ export class ApiService {
407
461
) ;
408
462
}
409
463
410
- public searchRecommendedMedia ( tmdbMediaId : string , mediaType : string ) {
464
+ public searchRecommendedMedia ( tmdbMediaId : string , mediaType : string ) : Observable < any > {
411
465
let params = {
412
466
tmdb_media_id : tmdbMediaId ,
413
467
media_type : mediaType ,
@@ -422,7 +476,7 @@ export class ApiService {
422
476
) ;
423
477
}
424
478
425
- public searchMediaDetail ( mediaType : string , id : string ) {
479
+ public searchMediaDetail ( mediaType : string , id : string ) : Observable < any > {
426
480
const options = { headers : this . _requestHeaders ( ) , params : this . _defaultParams ( ) } ;
427
481
return this . http . get ( `${ this . API_URL_SEARCH_MEDIA } ${ mediaType } /${ id } /` , options ) . pipe (
428
482
map ( ( data : any ) => {
@@ -431,7 +485,7 @@ export class ApiService {
431
485
) ;
432
486
}
433
487
434
- public fetchMediaVideos ( mediaType : string , id : string ) {
488
+ public fetchMediaVideos ( mediaType : string , id : string ) : Observable < any > {
435
489
const options = { headers : this . _requestHeaders ( ) } ;
436
490
return this . http . get ( `${ this . API_URL_SEARCH_MEDIA } ${ mediaType } /${ id } /videos/` , options ) . pipe (
437
491
map ( ( data : any ) => {
@@ -440,7 +494,7 @@ export class ApiService {
440
494
) ;
441
495
}
442
496
443
- public fetchWatchTVShows ( params ?: any ) {
497
+ public fetchWatchTVShows ( params ?: any ) : Observable < any [ ] > {
444
498
params = params || { } ;
445
499
const httpParams = new HttpParams ( { fromObject : params } ) ;
446
500
return this . http . get ( this . API_URL_WATCH_TV_SHOW , { params : httpParams , headers : this . _requestHeaders ( ) } ) . pipe (
@@ -451,7 +505,7 @@ export class ApiService {
451
505
) ;
452
506
}
453
507
454
- public fetchWatchTVSeasons ( params ?: any ) {
508
+ public fetchWatchTVSeasons ( params ?: any ) : Observable < any [ ] > {
455
509
params = params || { } ;
456
510
const httpParams = new HttpParams ( { fromObject : params } ) ;
457
511
return this . http . get ( this . API_URL_WATCH_TV_SEASON , { params : httpParams , headers : this . _requestHeaders ( ) } ) . pipe (
@@ -467,7 +521,7 @@ export class ApiService {
467
521
) ;
468
522
}
469
523
470
- public fetchWatchTVSeasonRequests ( params ?: any ) {
524
+ public fetchWatchTVSeasonRequests ( params ?: any ) : Observable < any [ ] > {
471
525
params = params || { } ;
472
526
const httpParams = new HttpParams ( { fromObject : params } ) ;
473
527
return this . http . get ( this . API_URL_WATCH_TV_SEASON_REQUEST , { params : httpParams , headers : this . _requestHeaders ( ) } ) . pipe (
@@ -483,7 +537,7 @@ export class ApiService {
483
537
) ;
484
538
}
485
539
486
- public fetchWatchMovies ( params ?: any ) {
540
+ public fetchWatchMovies ( params ?: any ) : Observable < any [ ] > {
487
541
params = params || { } ;
488
542
const httpParams = new HttpParams ( { fromObject : params } ) ;
489
543
@@ -500,7 +554,7 @@ export class ApiService {
500
554
) ;
501
555
}
502
556
503
- public fetchWatchTVEpisodes ( params : any ) {
557
+ public fetchWatchTVEpisodes ( params : any ) : Observable < any [ ] > {
504
558
const httpParams = new HttpParams ( { fromObject : params } ) ;
505
559
return this . http . get ( this . API_URL_WATCH_TV_EPISODE , { headers : this . _requestHeaders ( ) , params : httpParams } ) . pipe (
506
560
map ( ( records : any ) => {
@@ -515,7 +569,7 @@ export class ApiService {
515
569
) ;
516
570
}
517
571
518
- public fetchCurrentTorrents ( params : any ) {
572
+ public fetchCurrentTorrents ( params : any ) : Observable < any [ ] > {
519
573
const httpParams = new HttpParams ( { fromObject : params } ) ;
520
574
return this . http . get ( this . API_URL_CURRENT_TORRENTS , { headers : this . _requestHeaders ( ) , params : httpParams } ) . pipe (
521
575
map ( ( data : any ) => {
@@ -526,14 +580,14 @@ export class ApiService {
526
580
527
581
public watchTVShow (
528
582
showId : number , name : string , posterImageUrl : string ,
529
- releaseDate : string , autoWatchNewSeasons ?: boolean , qualityProfile ?: string ) {
583
+ releaseDate : string , autoWatchNewSeasons ?: boolean , qualityProfile ?: number ) {
530
584
const params = {
531
585
tmdb_show_id : showId ,
532
586
name : name ,
533
587
poster_image_url : posterImageUrl ,
534
588
release_date : releaseDate || null ,
535
589
auto_watch : ! ! autoWatchNewSeasons ,
536
- quality_profile_custom : qualityProfile ,
590
+ quality_profile : qualityProfile ,
537
591
} ;
538
592
return this . http . post ( this . API_URL_WATCH_TV_SHOW , params , { headers : this . _requestHeaders ( ) } ) . pipe (
539
593
map ( ( data : any ) => {
@@ -653,12 +707,12 @@ export class ApiService {
653
707
) ;
654
708
}
655
709
656
- public watchMovie ( movieId : number , name : string , posterImageUrl : string , releaseDate : string , qualityProfileCustom ?: string ) {
710
+ public watchMovie ( movieId : number , name : string , posterImageUrl : string , releaseDate : string , qualityProfile ?: number ) {
657
711
const params = {
658
712
tmdb_movie_id : movieId ,
659
713
name : name ,
660
714
poster_image_url : posterImageUrl ,
661
- quality_profile_custom : qualityProfileCustom ,
715
+ quality_profile : qualityProfile ,
662
716
release_date : releaseDate || null ,
663
717
} ;
664
718
@@ -734,7 +788,7 @@ export class ApiService {
734
788
) ;
735
789
}
736
790
737
- public verifySettings ( ) {
791
+ public verifySettings ( ) : Observable < any > {
738
792
return this . http . get ( `${ this . API_URL_SETTINGS } ${ this . settings . id } /verify/` , { headers : this . _requestHeaders ( ) } ) . pipe (
739
793
map ( ( data : any ) => {
740
794
return data ;
@@ -801,15 +855,15 @@ export class ApiService {
801
855
return this . _discoverMedia ( this . SEARCH_MEDIA_TYPE_TV , params ) ;
802
856
}
803
857
804
- public fetchMovieGenres ( ) {
858
+ public fetchMovieGenres ( ) : Observable < any > {
805
859
return this . _fetchGenres ( this . SEARCH_MEDIA_TYPE_MOVIE ) ;
806
860
}
807
861
808
- public fetchTVGenres ( ) {
862
+ public fetchTVGenres ( ) : Observable < any > {
809
863
return this . _fetchGenres ( this . SEARCH_MEDIA_TYPE_TV ) ;
810
864
}
811
865
812
- public verifyJackettIndexers ( ) {
866
+ public verifyJackettIndexers ( ) : Observable < any > {
813
867
return this . http . get ( `${ this . API_URL_SETTINGS } ${ this . settings . id } /verify-jackett-indexers/` , { headers : this . _requestHeaders ( ) } ) ;
814
868
}
815
869
@@ -837,7 +891,7 @@ export class ApiService {
837
891
return this . http . get ( url , { params : httpParams , headers : this . _requestHeaders ( ) } ) ;
838
892
}
839
893
840
- public openSubtitlesAuth ( ) {
894
+ public openSubtitlesAuth ( ) : Observable < any > {
841
895
const url = this . API_URL_OPEN_SUBTITLES_AUTH ;
842
896
return this . http . post ( url , null , { headers : this . _requestHeaders ( ) } ) ;
843
897
}
@@ -961,13 +1015,13 @@ export class ApiService {
961
1015
this . _updateStorage ( ) . subscribe ( ) ;
962
1016
}
963
1017
964
- protected _fetchGenres ( mediaType : string ) {
1018
+ protected _fetchGenres ( mediaType : string ) : Observable < any > {
965
1019
const url = mediaType === this . SEARCH_MEDIA_TYPE_MOVIE ? this . API_URL_GENRES_MOVIE : this . API_URL_GENRES_TV ;
966
1020
const params = this . _defaultParams ( ) ;
967
1021
return this . http . get ( url , { headers : this . _requestHeaders ( ) , params : params } ) ;
968
1022
}
969
1023
970
- protected _discoverMedia ( mediaType : string , params : any ) {
1024
+ protected _discoverMedia ( mediaType : string , params : any ) : Observable < any > {
971
1025
params = Object . assign ( params , this . _defaultParams ( ) ) ;
972
1026
const httpParams = new HttpParams ( { fromObject : params } ) ;
973
1027
const url = mediaType === this . SEARCH_MEDIA_TYPE_MOVIE ? this . API_URL_DISCOVER_MOVIES : this . API_URL_DISCOVER_TV ;
0 commit comments