Skip to content

Commit 25ca2d5

Browse files
authored
Merge pull request #212 from lardbit/quality-profiles
Dynamic Quality Profiles
2 parents 9c7954a + 1c5c3ce commit 25ca2d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1165
-258
lines changed

docs/CHANGELOG.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/frontend/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ testem.log
3838
# System Files
3939
.DS_Store
4040
Thumbs.db
41+
42+
.angular

src/frontend/src/app/api.service.ts

Lines changed: 88 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export class ApiService {
3939
API_URL_GENRES_MOVIE = '/api/genres/movie/';
4040
API_URL_GENRES_TV = '/api/genres/tv/';
4141
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/';
4344
API_URL_GIT_COMMIT = '/api/git-commit/';
4445
API_URL_IMPORT_MEDIA_TV = '/api/import/media/tv/';
4546
API_URL_IMPORT_MEDIA_MOVIE = '/api/import/media/movie/';
@@ -55,7 +56,8 @@ export class ApiService {
5556
public userToken: string;
5657
public users: any; // staff-only list of all users
5758
public settings: any;
58-
public qualityProfiles: string[];
59+
public qualities: string[] = [];
60+
public qualityProfiles: any[] = [];
5961
public mediaCategories: string[];
6062
public watchTVSeasons: any[] = [];
6163
public watchTVSeasonRequests: any[] = [];
@@ -180,6 +182,7 @@ export class ApiService {
180182
}
181183
})
182184
),
185+
this.fetchQualities(),
183186
this.fetchQualityProfiles(),
184187
this.fetchMediaCategories(),
185188
]).pipe(
@@ -211,7 +214,7 @@ export class ApiService {
211214
);
212215
}
213216

214-
public fetchSettings() {
217+
public fetchSettings(): Observable<any> {
215218
return this.http.get(this.API_URL_SETTINGS, {headers: this._requestHeaders()}).pipe(
216219
map((data: any) => {
217220
if (data.length) {
@@ -224,7 +227,7 @@ export class ApiService {
224227
);
225228
}
226229

227-
public fetchMediaCategories() {
230+
public fetchMediaCategories(): Observable<string[]> {
228231
return this.http.get(this.API_URL_MEDIA_CATEGORIES, {headers: this._requestHeaders()}).pipe(
229232
map((data: any) => {
230233
if (data.mediaCategories) {
@@ -237,11 +240,24 @@ export class ApiService {
237240
);
238241
}
239242

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[]> {
241257
return this.http.get(this.API_URL_QUALITY_PROFILES, {headers: this._requestHeaders()}).pipe(
242258
map((data: any) => {
243-
if (data.profiles) {
244-
this.qualityProfiles = data.profiles;
259+
if (data.length) {
260+
this.qualityProfiles = data;
245261
} else {
246262
console.error('no quality profiles');
247263
}
@@ -303,7 +319,7 @@ export class ApiService {
303319
);
304320
}
305321

306-
public login(user: string, pass: string) {
322+
public login(user: string, pass: string): Observable<any> {
307323
const params = {
308324
username: user,
309325
password: pass,
@@ -313,8 +329,8 @@ export class ApiService {
313329
console.log('token auth', data);
314330
this.userToken = data.token;
315331
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');
318334
},
319335
(error) => {
320336
console.error('local storage error', error);
@@ -334,15 +350,53 @@ export class ApiService {
334350
);
335351
}
336352

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> {
338392
return this.http.get(`${this.API_URL_SEARCH_TORRENTS}?q=${query}&media_type=${mediaType}`, {headers: this._requestHeaders()}).pipe(
339393
map((data: any) => {
340394
return data;
341395
}),
342396
);
343397
}
344398

345-
public download(torrentResult: any, mediaType: string, tmdbMedia: any, params?: any) {
399+
public download(torrentResult: any, mediaType: string, tmdbMedia: any, params?: any): Observable<any> {
346400
// add extra params
347401
Object.assign(params || {}, {
348402
torrent: torrentResult,
@@ -377,7 +431,7 @@ export class ApiService {
377431
);
378432
}
379433

380-
public searchMedia(query: string, mediaType: string, page = 1) {
434+
public searchMedia(query: string, mediaType: string, page = 1): Observable<any> {
381435
let params = {
382436
q: query,
383437
media_type: mediaType,
@@ -392,7 +446,7 @@ export class ApiService {
392446
);
393447
}
394448

395-
public searchSimilarMedia(tmdbMediaId: string, mediaType: string) {
449+
public searchSimilarMedia(tmdbMediaId: string, mediaType: string): Observable<any> {
396450
let params = {
397451
tmdb_media_id: tmdbMediaId,
398452
media_type: mediaType,
@@ -407,7 +461,7 @@ export class ApiService {
407461
);
408462
}
409463

410-
public searchRecommendedMedia(tmdbMediaId: string, mediaType: string) {
464+
public searchRecommendedMedia(tmdbMediaId: string, mediaType: string): Observable<any> {
411465
let params = {
412466
tmdb_media_id: tmdbMediaId,
413467
media_type: mediaType,
@@ -422,7 +476,7 @@ export class ApiService {
422476
);
423477
}
424478

425-
public searchMediaDetail(mediaType: string, id: string) {
479+
public searchMediaDetail(mediaType: string, id: string): Observable<any> {
426480
const options = {headers: this._requestHeaders(), params: this._defaultParams()};
427481
return this.http.get(`${this.API_URL_SEARCH_MEDIA}${mediaType}/${id}/`, options).pipe(
428482
map((data: any) => {
@@ -431,7 +485,7 @@ export class ApiService {
431485
);
432486
}
433487

434-
public fetchMediaVideos(mediaType: string, id: string) {
488+
public fetchMediaVideos(mediaType: string, id: string): Observable<any> {
435489
const options = {headers: this._requestHeaders()};
436490
return this.http.get(`${this.API_URL_SEARCH_MEDIA}${mediaType}/${id}/videos/`, options).pipe(
437491
map((data: any) => {
@@ -440,7 +494,7 @@ export class ApiService {
440494
);
441495
}
442496

443-
public fetchWatchTVShows(params?: any) {
497+
public fetchWatchTVShows(params?: any): Observable<any[]> {
444498
params = params || {};
445499
const httpParams = new HttpParams({fromObject: params});
446500
return this.http.get(this.API_URL_WATCH_TV_SHOW, {params: httpParams, headers: this._requestHeaders()}).pipe(
@@ -451,7 +505,7 @@ export class ApiService {
451505
);
452506
}
453507

454-
public fetchWatchTVSeasons(params?: any) {
508+
public fetchWatchTVSeasons(params?: any): Observable<any[]> {
455509
params = params || {};
456510
const httpParams = new HttpParams({fromObject: params});
457511
return this.http.get(this.API_URL_WATCH_TV_SEASON, {params: httpParams, headers: this._requestHeaders()}).pipe(
@@ -467,7 +521,7 @@ export class ApiService {
467521
);
468522
}
469523

470-
public fetchWatchTVSeasonRequests(params?: any) {
524+
public fetchWatchTVSeasonRequests(params?: any): Observable<any[]> {
471525
params = params || {};
472526
const httpParams = new HttpParams({fromObject: params});
473527
return this.http.get(this.API_URL_WATCH_TV_SEASON_REQUEST, {params: httpParams, headers: this._requestHeaders()}).pipe(
@@ -483,7 +537,7 @@ export class ApiService {
483537
);
484538
}
485539

486-
public fetchWatchMovies(params?: any) {
540+
public fetchWatchMovies(params?: any): Observable<any[]> {
487541
params = params || {};
488542
const httpParams = new HttpParams({fromObject: params});
489543

@@ -500,7 +554,7 @@ export class ApiService {
500554
);
501555
}
502556

503-
public fetchWatchTVEpisodes(params: any) {
557+
public fetchWatchTVEpisodes(params: any): Observable<any[]> {
504558
const httpParams = new HttpParams({fromObject: params});
505559
return this.http.get(this.API_URL_WATCH_TV_EPISODE, {headers: this._requestHeaders(), params: httpParams}).pipe(
506560
map((records: any) => {
@@ -515,7 +569,7 @@ export class ApiService {
515569
);
516570
}
517571

518-
public fetchCurrentTorrents(params: any) {
572+
public fetchCurrentTorrents(params: any): Observable<any[]> {
519573
const httpParams = new HttpParams({fromObject: params});
520574
return this.http.get(this.API_URL_CURRENT_TORRENTS, {headers: this._requestHeaders(), params: httpParams}).pipe(
521575
map((data: any) => {
@@ -526,14 +580,14 @@ export class ApiService {
526580

527581
public watchTVShow(
528582
showId: number, name: string, posterImageUrl: string,
529-
releaseDate: string, autoWatchNewSeasons?: boolean, qualityProfile?: string) {
583+
releaseDate: string, autoWatchNewSeasons?: boolean, qualityProfile?: number) {
530584
const params = {
531585
tmdb_show_id: showId,
532586
name: name,
533587
poster_image_url: posterImageUrl,
534588
release_date: releaseDate || null,
535589
auto_watch: !!autoWatchNewSeasons,
536-
quality_profile_custom: qualityProfile,
590+
quality_profile: qualityProfile,
537591
};
538592
return this.http.post(this.API_URL_WATCH_TV_SHOW, params, {headers: this._requestHeaders()}).pipe(
539593
map((data: any) => {
@@ -653,12 +707,12 @@ export class ApiService {
653707
);
654708
}
655709

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) {
657711
const params = {
658712
tmdb_movie_id: movieId,
659713
name: name,
660714
poster_image_url: posterImageUrl,
661-
quality_profile_custom: qualityProfileCustom,
715+
quality_profile: qualityProfile,
662716
release_date: releaseDate || null,
663717
};
664718

@@ -734,7 +788,7 @@ export class ApiService {
734788
);
735789
}
736790

737-
public verifySettings() {
791+
public verifySettings(): Observable<any> {
738792
return this.http.get(`${this.API_URL_SETTINGS}${this.settings.id}/verify/`, {headers: this._requestHeaders()}).pipe(
739793
map((data: any) => {
740794
return data;
@@ -801,15 +855,15 @@ export class ApiService {
801855
return this._discoverMedia(this.SEARCH_MEDIA_TYPE_TV, params);
802856
}
803857

804-
public fetchMovieGenres() {
858+
public fetchMovieGenres(): Observable<any> {
805859
return this._fetchGenres(this.SEARCH_MEDIA_TYPE_MOVIE);
806860
}
807861

808-
public fetchTVGenres() {
862+
public fetchTVGenres(): Observable<any> {
809863
return this._fetchGenres(this.SEARCH_MEDIA_TYPE_TV);
810864
}
811865

812-
public verifyJackettIndexers() {
866+
public verifyJackettIndexers(): Observable<any> {
813867
return this.http.get(`${this.API_URL_SETTINGS}${this.settings.id}/verify-jackett-indexers/`, {headers: this._requestHeaders()});
814868
}
815869

@@ -837,7 +891,7 @@ export class ApiService {
837891
return this.http.get(url, {params: httpParams, headers: this._requestHeaders()});
838892
}
839893

840-
public openSubtitlesAuth() {
894+
public openSubtitlesAuth(): Observable<any> {
841895
const url = this.API_URL_OPEN_SUBTITLES_AUTH;
842896
return this.http.post(url, null, {headers: this._requestHeaders()});
843897
}
@@ -961,13 +1015,13 @@ export class ApiService {
9611015
this._updateStorage().subscribe();
9621016
}
9631017

964-
protected _fetchGenres(mediaType: string) {
1018+
protected _fetchGenres(mediaType: string): Observable<any> {
9651019
const url = mediaType === this.SEARCH_MEDIA_TYPE_MOVIE ? this.API_URL_GENRES_MOVIE : this.API_URL_GENRES_TV;
9661020
const params = this._defaultParams();
9671021
return this.http.get(url, {headers: this._requestHeaders(), params: params});
9681022
}
9691023

970-
protected _discoverMedia(mediaType: string, params: any) {
1024+
protected _discoverMedia(mediaType: string, params: any): Observable<any> {
9711025
params = Object.assign(params, this._defaultParams());
9721026
const httpParams = new HttpParams({fromObject: params});
9731027
const url = mediaType === this.SEARCH_MEDIA_TYPE_MOVIE ? this.API_URL_DISCOVER_MOVIES : this.API_URL_DISCOVER_TV;

0 commit comments

Comments
 (0)