Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/frontend/src/app/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ export class ApiService {
);
}

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(
public searchTorrents(query: string, mediaType: string, useCategories: boolean): Observable<any> {
return this.http.get(`${this.API_URL_SEARCH_TORRENTS}?q=${query}&media_type=${mediaType}&use_categories=${useCategories}`, {headers: this._requestHeaders()}).pipe(
map((data: any) => {
return data;
}),
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/app/search/search-manual.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<span class="oi oi-magnifying-glass"></span> Search
</button>
</div>
<span><input [(ngModel)]="useCategories" name="useCategories" required type="checkbox" value="use_categories" checked="true" />Search by category</span>
</form>
</div>

Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/app/search/search-manual.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class SearchManualComponent implements OnInit {
@Input('mediaType') mediaType: string;
@Output() downloaded = new EventEmitter<any>();
public searchInput: string;
public useCategories: boolean = true;
public orderByOptions = ['Name', 'Seeders', 'Size'];
public results: any[] = [];
public isSearching = false;
Expand Down Expand Up @@ -43,7 +44,7 @@ export class SearchManualComponent implements OnInit {
public search() {
this.results = [];
this.isSearching = true;
this.apiService.searchTorrents(this.searchInput, this.mediaType).subscribe(
this.apiService.searchTorrents(this.searchInput, this.mediaType, this.useCategories ?? false).subscribe(
(results) => {
this.results = results;
this.filterChange();
Expand Down
3 changes: 2 additions & 1 deletion src/nefarious/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ class SearchTorrentsView(views.APIView):
def get(self, request):
query = request.query_params.get('q')
media_type = request.query_params.get('media_type', SEARCH_MEDIA_TYPE_MOVIE)
search = SearchTorrents(media_type, query)
use_category = request.query_params.get('use_categories', True)
search = SearchTorrents(media_type, query, use_category)
if not search.ok:
return Response({'error': search.error_content}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response(search.results)
Expand Down
6 changes: 4 additions & 2 deletions src/nefarious/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ class SearchTorrents:
error_content = None
nefarious_settings: NefariousSettings

def __init__(self, media_type: str, query: str):
def __init__(self, media_type: str, query: str, include_category = True):
assert media_type in [SEARCH_MEDIA_TYPE_TV, SEARCH_MEDIA_TYPE_MOVIE]
self.nefarious_settings = NefariousSettings.get()

params = {
'apikey': self.nefarious_settings.jackett_token,
'Query': query,
'Category[]': self._categories(media_type),
}

if include_category:
params['Category[]'] = self._categories(media_type),

res = requests.get(get_jackett_search_url(self.nefarious_settings), params, timeout=90)
logger_background.info(f'jackett search: query={query}, url={res.url}')

Expand Down