Skip to content

Commit

Permalink
create quality profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
lardbit committed Aug 16, 2024
1 parent 9f4beb4 commit dc5f964
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 16 deletions.
9 changes: 9 additions & 0 deletions src/frontend/src/app/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,15 @@ export class ApiService {
);
}

public createQualityProfile(data: any): Observable<any> {
return this.http.post(this.API_URL_QUALITY_PROFILES, data, {headers: this._requestHeaders()}).pipe(
map((data: any) => {
// append this new quality profile
this.qualityProfiles.push(data);
}),
);
}

public searchTorrents(query: string, mediaType: string): Observable<any> {
return this.http.get(`${this.API_URL_SEARCH_TORRENTS}?q=${query}&media_type=${mediaType}`, {headers: this._requestHeaders()}).pipe(
map((data: any) => {
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/src/app/settings/quality-profiles.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ <h4 class="modal-title">Quality Profiles</h4>
</div>
<div class="modal-body" [formGroup]="form">
<ngx-loading [show]="isLoading" [config]="{fullScreenBackdrop: true}"></ngx-loading>
<div class="text-end">
<button type="button" class="btn btn-sm btn-outline-success" (click)="add()"><span class="oi oi-plus"></span></button>
</div>
<form class="was-validated" [formArrayName]="'profiles'">
<div class="card my-2" *ngFor="let profile of form.controls.profiles.controls; let i = index" [formGroupName]="i">
<div class="card-body">
Expand Down
46 changes: 33 additions & 13 deletions src/frontend/src/app/settings/quality-profiles.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Component, OnInit} from '@angular/core';
import {NgbActiveModal} from "@ng-bootstrap/ng-bootstrap";
import {ApiService} from "../api.service";
import {FormArray, FormBuilder, FormControl, FormGroup, Validators} from "@angular/forms";
import {FormArray, FormBuilder, FormGroup, Validators} from "@angular/forms";
import {ToastrService} from 'ngx-toastr';
import {Observable} from "rxjs";

// TODO - add/remove profiles

@Component({
selector: 'app-quality-profiles',
Expand All @@ -25,24 +25,32 @@ export class QualityProfilesComponent implements OnInit {

ngOnInit() {
this.form = this.fb.group({
profiles: this.fb.array(this.apiService.qualityProfiles.map(p => this.fb.group({
id: p.id,
name: this.fb.control(p.name, [Validators.required, Validators.minLength(2)]),
quality: this.fb.control(p.quality, [Validators.required]),
min_size_gb: this.fb.control(p.min_size_gb, [Validators.min(0)]),
max_size_gb: this.fb.control(p.max_size_gb, [Validators.min(0)]),
require_hdr: p.require_hdr,
require_five_point_one: p.require_five_point_one,
}))),
profiles: this.fb.array(this.apiService.qualityProfiles.map(p => this._getNewFormGroup(p))),
});
}

public add() {
this.form.controls.profiles.insert(0, this._getNewFormGroup());
}

public save(profileFormGroup: FormGroup) {
this.isLoading = true;
let update$: Observable<any>;
let updateVerb: string;
const data = profileFormGroup.value;
this.apiService.updateQualityProfile(data.id, data).subscribe({
// update
if (data.id) {
update$ = this.apiService.updateQualityProfile(data.id, data);
updateVerb = 'updated';
}
// create
else {
update$ = this.apiService.createQualityProfile(data);
updateVerb = 'created';
}
update$.subscribe({
next: () => {
this.toastr.success('Successfully updated quality profile');
this.toastr.success(`Successfully ${updateVerb} quality profile`);
this.isLoading = false;
},
error: (error) => {
Expand Down Expand Up @@ -76,4 +84,16 @@ export class QualityProfilesComponent implements OnInit {
}
})
}

protected _getNewFormGroup(data?: any): FormGroup {
return this.fb.group({
id: data?.id,
name: this.fb.control(data?.name, [Validators.required, Validators.minLength(2)]),
quality: this.fb.control(data?.quality, [Validators.required]),
min_size_gb: this.fb.control(data?.min_size_gb, [Validators.min(0)]),
max_size_gb: this.fb.control(data?.max_size_gb, [Validators.min(0)]),
require_hdr: data?.require_hdr,
require_five_point_one: data?.require_five_point_one,
})
}
}
23 changes: 23 additions & 0 deletions src/nefarious/migrations/0096_auto_20240816_1352.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.0.2 on 2024-08-16 13:52

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('nefarious', '0095_auto_20240816_1302'),
]

operations = [
migrations.AlterField(
model_name='qualityprofile',
name='require_five_point_one',
field=models.BooleanField(blank=True, default=False, help_text='media must be in 5.1 surround sound (e.g. Dolby 5.1)'),
),
migrations.AlterField(
model_name='qualityprofile',
name='require_hdr',
field=models.BooleanField(blank=True, default=False, help_text='media must be in HDR (High Dynamic Range)'),
),
]
23 changes: 23 additions & 0 deletions src/nefarious/migrations/0097_auto_20240816_1353.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.0.2 on 2024-08-16 13:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('nefarious', '0096_auto_20240816_1352'),
]

operations = [
migrations.AlterField(
model_name='qualityprofile',
name='require_five_point_one',
field=models.BooleanField(default=False, help_text='media must be in 5.1 surround sound (e.g. Dolby 5.1)', null=True),
),
migrations.AlterField(
model_name='qualityprofile',
name='require_hdr',
field=models.BooleanField(default=False, help_text='media must be in HDR (High Dynamic Range)', null=True),
),
]
7 changes: 4 additions & 3 deletions src/nefarious/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class QualityProfile(models.Model):
null=True, blank=True, max_digits=10, decimal_places=2, validators=[MinValueValidator(0)], help_text='minimum size (gb) to download')
max_size_gb = models.DecimalField(
null=True, blank=True, max_digits=10, decimal_places=2, validators=[MinValueValidator(0)], help_text='maximum size (gb) to download')
require_hdr = models.BooleanField(default=False, help_text='media must be in HDR (High Dynamic Range)')
require_five_point_one = models.BooleanField(default=False, help_text='media must be in 5.1 surround sound (e.g. Dolby 5.1)')
require_hdr = models.BooleanField(default=False, null=True, help_text='media must be in HDR (High Dynamic Range)')
require_five_point_one = models.BooleanField(default=False, null=True, help_text='media must be in 5.1 surround sound (e.g. Dolby 5.1)')

def __str__(self):
if self.name == self.quality:
Expand Down Expand Up @@ -62,7 +62,7 @@ class NefariousSettings(models.Model):
transmission_tv_download_dir = models.CharField(max_length=500, default='tv/', help_text='Relative to download path')
transmission_movie_download_dir = models.CharField(max_length=500, default='movies/', help_text='Relative to download path')

# tmbd - the movie database
# tmdb - the movie database
tmdb_token = models.CharField(max_length=500, default=settings.TMDB_API_TOKEN)
tmdb_configuration = JSONField(blank=True, null=True)
tmdb_languages = JSONField(blank=True, null=True) # type: list
Expand All @@ -81,6 +81,7 @@ class NefariousSettings(models.Model):
# whether to allow hardcoded subtitles
allow_hardcoded_subs = models.BooleanField(default=False)

# TODO - move to quality profile
# whether to enable video detection features (e.g. fake/spam)
enable_video_detection = models.BooleanField(default=False)

Expand Down

0 comments on commit dc5f964

Please sign in to comment.