Skip to content

Commit

Permalink
Merge pull request #262 from lardbit/feature/searching-default-settings
Browse files Browse the repository at this point in the history
Feature/searching default settings
  • Loading branch information
lardbit authored Dec 1, 2023
2 parents 2e326c8 + ae0e6e1 commit d60ebbb
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/frontend/src/app/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class ApiService {
API_URL_DISCOVER_RT_MOVIES = '/api/discover/rotten-tomatoes/media/movie/';
API_URL_GENRES_MOVIE = '/api/genres/movie/';
API_URL_GENRES_TV = '/api/genres/tv/';
API_URL_MEDIA_CATEGORIES = '/api/media-categories/';
API_URL_QUALITY_PROFILES = '/api/quality-profiles/';
API_URL_GIT_COMMIT = '/api/git-commit/';
API_URL_IMPORT_MEDIA_TV = '/api/import/media/tv/';
Expand All @@ -55,6 +56,7 @@ export class ApiService {
public users: any; // staff-only list of all users
public settings: any;
public qualityProfiles: string[];
public mediaCategories: string[];
public watchTVSeasons: any[] = [];
public watchTVSeasonRequests: any[] = [];
public watchTVEpisodes: any[] = [];
Expand Down Expand Up @@ -179,6 +181,7 @@ export class ApiService {
})
),
this.fetchQualityProfiles(),
this.fetchMediaCategories(),
]).pipe(
catchError((error) => {
console.error(error);
Expand Down Expand Up @@ -214,6 +217,19 @@ export class ApiService {
);
}

public fetchMediaCategories() {
return this.http.get(this.API_URL_MEDIA_CATEGORIES, {headers: this._requestHeaders()}).pipe(
map((data: any) => {
if (data.mediaCategories) {
this.mediaCategories = data.mediaCategories;
} else {
console.error('no media categories');
}
return this.mediaCategories;
}),
);
}

public fetchQualityProfiles() {
return this.http.get(this.API_URL_QUALITY_PROFILES, {headers: this._requestHeaders()}).pipe(
map((data: any) => {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/app/search/search-input.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class SearchInputComponent implements OnInit {
}

ngOnInit() {
this.type = this.apiService.SEARCH_MEDIA_TYPE_MOVIE;
this.type = this.apiService.settings.preferred_media_category;

const queryParams = this.route.snapshot.queryParams;

Expand Down
12 changes: 12 additions & 0 deletions src/frontend/src/app/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,18 @@
</div>
</div>
</div>
<!-- preferences -->
<div class="card">
<div class="card-header">Preferences</div>
<div class="card-body">
<div class="form-group">
<label>Preferred media category</label>
<select type="text" class="form-control" formControlName="preferred_media_category" required>
<option *ngFor="let mediaCategory of mediaCategories()" [value]="mediaCategory">{{ mediaCategory }}</option>
</select>
</div>
</div>
</div>
<!-- logs -->
<div class="card">
<div class="card-header">Logs</div>
Expand Down
5 changes: 5 additions & 0 deletions src/frontend/src/app/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class SettingsComponent implements OnInit, AfterContentChecked {
'language': [settings['language'], Validators.required],
'users': new FormArray([]),
'apprise_notification_url': [settings['apprise_notification_url']],
'preferred_media_category': [settings['preferred_media_category'], Validators.required],
});

this.isLoadingUsers = true;
Expand Down Expand Up @@ -113,6 +114,10 @@ export class SettingsComponent implements OnInit, AfterContentChecked {
return this.apiService.qualityProfiles;
}

public mediaCategories(): string[] {
return this.apiService.mediaCategories;
}

public addUser() {
this.form.get('users').push(this.fb.group({
username: ['', Validators.required],
Expand Down
1 change: 1 addition & 0 deletions src/nefarious/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
path('discover/rotten-tomatoes/media/<str:media_type>/', views.DiscoverRottenTomatoesMediaView.as_view()),
path('import/media/<str:media_type>/', views.ImportMediaLibraryView.as_view()),
path('genres/<str:media_type>/', views.GenresView.as_view()),
path('media-categories/', views.MediaCategoriesView.as_view()),
path('quality-profiles/', views.QualityProfilesView.as_view()),
path('auth/', views.ObtainAuthTokenView.as_view()), # authenticates user and returns token
path('git-commit/', views.GitCommitView.as_view()), # returns this app's git commit
Expand Down
9 changes: 9 additions & 0 deletions src/nefarious/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from nefarious.api.serializers import (
WatchMovieSerializer, WatchTVShowSerializer, WatchTVEpisodeSerializer, WatchTVSeasonRequestSerializer, WatchTVSeasonSerializer,
TransmissionTorrentSerializer, RottenTomatoesSearchResultsSerializer, )
from nefarious.media_category import MEDIA_CATEGORIES
from nefarious.models import NefariousSettings, WatchMovie, WatchTVShow, WatchTVEpisode, WatchTVSeasonRequest, WatchTVSeason
from nefarious.notification import send_message
from nefarious.opensubtitles import OpenSubtitles
Expand Down Expand Up @@ -507,6 +508,14 @@ def get(self, request):
return Response({'profiles': [p.name for p in PROFILES]})


@method_decorator(gzip_page, name='dispatch')
class MediaCategoriesView(views.APIView):

def get(self, request):
media_category_keys = [category[0] for category in MEDIA_CATEGORIES]
return Response({'mediaCategories': media_category_keys})


class ImportMediaLibraryView(views.APIView):

def post(self, request, media_type):
Expand Down
7 changes: 7 additions & 0 deletions src/nefarious/media_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

MEDIA_MOVIE_CATEGORY = "movie"
MEDIA_TV_CATEGORY = "tv"
MEDIA_CATEGORIES = (
(MEDIA_MOVIE_CATEGORY, "Movie"),
(MEDIA_TV_CATEGORY, "TV"),
)
18 changes: 18 additions & 0 deletions src/nefarious/migrations/0074_add_preferred_media_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.0.2 on 2023-11-29 21:40

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('nefarious', '0073_disable_video_detection'),
]

operations = [
migrations.AddField(
model_name='nefarioussettings',
name='preferred_media_category',
field=models.CharField(choices=[('movie', 'Movie'), ('tv', 'TV')], default='movie', max_length=10),
),
]
8 changes: 8 additions & 0 deletions src/nefarious/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.conf import settings
from jsonfield import JSONField
from django.db import models
from nefarious import media_category
from nefarious import quality

PERM_CAN_WATCH_IMMEDIATELY_TV = 'can_immediately_watch_tv'
Expand Down Expand Up @@ -60,6 +61,13 @@ class NefariousSettings(models.Model):
# apprise notifications - https://github.com/caronc/apprise
apprise_notification_url = models.CharField(max_length=1000, blank=True)

# category of media the user prefers: movie or tv...
preferred_media_category = models.CharField(
max_length=10,
default=media_category.MEDIA_MOVIE_CATEGORY,
choices=media_category.MEDIA_CATEGORIES,
)

@classmethod
def get(cls):
if cls.objects.all().count() > 1:
Expand Down

0 comments on commit d60ebbb

Please sign in to comment.