1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Fixed: Fetch blacklist by Movie instead of all

Fixes #5066
This commit is contained in:
Qstick 2020-09-27 23:08:20 -04:00
parent a1e69c3c2b
commit aef8a8fd04
9 changed files with 132 additions and 21 deletions

View File

@ -8,8 +8,8 @@ function createMapStateToProps() {
return createSelector( return createSelector(
(state, { guid }) => guid, (state, { guid }) => guid,
(state) => state.movieHistory.items, (state) => state.movieHistory.items,
(state) => state.blacklist.items, (state) => state.movieBlacklist.items,
(guid, movieHistory, blacklist) => { (guid, movieHistory, movieBlacklist) => {
let blacklistData = {}; let blacklistData = {};
let historyFailedData = {}; let historyFailedData = {};
@ -17,7 +17,7 @@ function createMapStateToProps() {
const historyGrabbedData = movieHistory.find((movie) => movie.eventType === 'grabbed' && movie.data.guid === guid); const historyGrabbedData = movieHistory.find((movie) => movie.eventType === 'grabbed' && movie.data.guid === guid);
if (historyGrabbedData) { if (historyGrabbedData) {
historyFailedData = movieHistory.find((movie) => movie.eventType === 'downloadFailed' && movie.sourceTitle === historyGrabbedData.sourceTitle); historyFailedData = movieHistory.find((movie) => movie.eventType === 'downloadFailed' && movie.sourceTitle === historyGrabbedData.sourceTitle);
blacklistData = blacklist.find((item) => item.sourceTitle === historyGrabbedData.sourceTitle); blacklistData = movieBlacklist.find((item) => item.sourceTitle === historyGrabbedData.sourceTitle);
} }
return { return {

View File

@ -5,10 +5,10 @@ import React, { Component } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import * as commandNames from 'Commands/commandNames'; import * as commandNames from 'Commands/commandNames';
import { fetchBlacklist } from 'Store/Actions/blacklistActions';
import { executeCommand } from 'Store/Actions/commandActions'; import { executeCommand } from 'Store/Actions/commandActions';
import { clearExtraFiles, fetchExtraFiles } from 'Store/Actions/extraFileActions'; import { clearExtraFiles, fetchExtraFiles } from 'Store/Actions/extraFileActions';
import { toggleMovieMonitored } from 'Store/Actions/movieActions'; import { toggleMovieMonitored } from 'Store/Actions/movieActions';
import { clearMovieBlacklist, fetchMovieBlacklist } from 'Store/Actions/movieBlacklistActions';
import { clearMovieCredits, fetchMovieCredits } from 'Store/Actions/movieCreditsActions'; import { clearMovieCredits, fetchMovieCredits } from 'Store/Actions/movieCreditsActions';
import { clearMovieFiles, fetchMovieFiles } from 'Store/Actions/movieFileActions'; import { clearMovieFiles, fetchMovieFiles } from 'Store/Actions/movieFileActions';
import { clearMovieHistory, fetchMovieHistory } from 'Store/Actions/movieHistoryActions'; import { clearMovieHistory, fetchMovieHistory } from 'Store/Actions/movieHistoryActions';
@ -222,9 +222,11 @@ function createMapDispatchToProps(dispatch, props) {
onGoToMovie(titleSlug) { onGoToMovie(titleSlug) {
dispatch(push(`${window.Radarr.urlBase}/movie/${titleSlug}`)); dispatch(push(`${window.Radarr.urlBase}/movie/${titleSlug}`));
}, },
dispatchFetchBlacklist() { dispatchFetchMovieBlacklist({ movieId }) {
// TODO: Allow for passing a movie id to fetch a single movie's blacklist data dispatch(fetchMovieBlacklist({ movieId }));
dispatch(fetchBlacklist()); },
dispatchClearMovieBlacklist() {
dispatch(clearMovieBlacklist());
} }
}; };
} }
@ -278,20 +280,17 @@ class MovieDetailsConnector extends Component {
const movieId = this.props.id; const movieId = this.props.id;
this.props.dispatchFetchMovieFiles({ movieId }); this.props.dispatchFetchMovieFiles({ movieId });
this.props.dispatchFetchMovieBlacklist({ movieId });
this.props.dispatchFetchMovieHistory({ movieId }); this.props.dispatchFetchMovieHistory({ movieId });
this.props.dispatchFetchExtraFiles({ movieId }); this.props.dispatchFetchExtraFiles({ movieId });
this.props.dispatchFetchMovieCredits({ movieId }); this.props.dispatchFetchMovieCredits({ movieId });
this.props.dispatchFetchQueueDetails({ movieId }); this.props.dispatchFetchQueueDetails({ movieId });
this.props.dispatchFetchImportListSchema(); this.props.dispatchFetchImportListSchema();
this.props.dispatchFetchBlacklist();
}
repopulate = () => {
this.props.dispatchFetchBlacklist();
} }
unpopulate = () => { unpopulate = () => {
this.props.dispatchCancelFetchReleases(); this.props.dispatchCancelFetchReleases();
this.props.dispatchClearMovieBlacklist();
this.props.dispatchClearMovieFiles(); this.props.dispatchClearMovieFiles();
this.props.dispatchClearMovieHistory(); this.props.dispatchClearMovieHistory();
this.props.dispatchClearExtraFiles(); this.props.dispatchClearExtraFiles();
@ -363,7 +362,8 @@ MovieDetailsConnector.propTypes = {
dispatchClearQueueDetails: PropTypes.func.isRequired, dispatchClearQueueDetails: PropTypes.func.isRequired,
dispatchFetchImportListSchema: PropTypes.func.isRequired, dispatchFetchImportListSchema: PropTypes.func.isRequired,
dispatchExecuteCommand: PropTypes.func.isRequired, dispatchExecuteCommand: PropTypes.func.isRequired,
dispatchFetchBlacklist: PropTypes.func.isRequired, dispatchFetchMovieBlacklist: PropTypes.func.isRequired,
dispatchClearMovieBlacklist: PropTypes.func.isRequired,
onGoToMovie: PropTypes.func.isRequired onGoToMovie: PropTypes.func.isRequired
}; };

View File

@ -11,6 +11,7 @@ import * as history from './historyActions';
import * as importMovie from './importMovieActions'; import * as importMovie from './importMovieActions';
import * as interactiveImportActions from './interactiveImportActions'; import * as interactiveImportActions from './interactiveImportActions';
import * as movies from './movieActions'; import * as movies from './movieActions';
import * as movieBlacklist from './movieBlacklistActions';
import * as movieCredits from './movieCreditsActions'; import * as movieCredits from './movieCreditsActions';
import * as movieFiles from './movieFileActions'; import * as movieFiles from './movieFileActions';
import * as movieHistory from './movieHistoryActions'; import * as movieHistory from './movieHistoryActions';
@ -48,6 +49,7 @@ export default [
releases, releases,
rootFolders, rootFolders,
movies, movies,
movieBlacklist,
movieHistory, movieHistory,
movieIndex, movieIndex,
movieCredits, movieCredits,

View File

@ -0,0 +1,82 @@
import { createAction } from 'redux-actions';
import { batchActions } from 'redux-batched-actions';
import { createThunk, handleThunks } from 'Store/thunks';
import createAjaxRequest from 'Utilities/createAjaxRequest';
import { set, update } from './baseActions';
import createHandleActions from './Creators/createHandleActions';
//
// Variables
export const section = 'movieBlacklist';
//
// State
export const defaultState = {
isFetching: false,
isPopulated: false,
error: null,
items: []
};
//
// Actions Types
export const FETCH_MOVIE_BLACKLIST = 'movieBlacklist/fetchMovieBlacklist';
export const CLEAR_MOVIE_BLACKLIST = 'movieBlacklist/clearMovieBlacklist';
//
// Action Creators
export const fetchMovieBlacklist = createThunk(FETCH_MOVIE_BLACKLIST);
export const clearMovieBlacklist = createAction(CLEAR_MOVIE_BLACKLIST);
//
// Action Handlers
export const actionHandlers = handleThunks({
[FETCH_MOVIE_BLACKLIST]: function(getState, payload, dispatch) {
dispatch(set({ section, isFetching: true }));
const promise = createAjaxRequest({
url: '/blacklist/movie',
data: payload
}).request;
promise.done((data) => {
dispatch(batchActions([
update({ section, data }),
set({
section,
isFetching: false,
isPopulated: true,
error: null
})
]));
});
promise.fail((xhr) => {
dispatch(set({
section,
isFetching: false,
isPopulated: false,
error: xhr
}));
});
}
});
//
// Reducers
export const reducers = createHandleActions({
[CLEAR_MOVIE_BLACKLIST]: (state) => {
return Object.assign({}, state, defaultState);
}
}, defaultState, section);

View File

@ -81,8 +81,8 @@ public void should_delete_blacklists_by_movieId()
Subject.DeleteForMovies(new List<int> { _movie1.Id }); Subject.DeleteForMovies(new List<int> { _movie1.Id });
var removedMovieBlacklists = Subject.BlacklistedByMovies(new List<int> { _movie1.Id }); var removedMovieBlacklists = Subject.BlacklistedByMovie(_movie1.Id);
var nonRemovedMovieBlacklists = Subject.BlacklistedByMovies(new List<int> { _movie2.Id }); var nonRemovedMovieBlacklists = Subject.BlacklistedByMovie(_movie2.Id);
removedMovieBlacklists.Should().HaveCount(0); removedMovieBlacklists.Should().HaveCount(0);
nonRemovedMovieBlacklists.Should().HaveCount(1); nonRemovedMovieBlacklists.Should().HaveCount(1);

View File

@ -9,7 +9,7 @@ public interface IBlacklistRepository : IBasicRepository<Blacklist>
{ {
List<Blacklist> BlacklistedByTitle(int movieId, string sourceTitle); List<Blacklist> BlacklistedByTitle(int movieId, string sourceTitle);
List<Blacklist> BlacklistedByTorrentInfoHash(int movieId, string torrentInfoHash); List<Blacklist> BlacklistedByTorrentInfoHash(int movieId, string torrentInfoHash);
List<Blacklist> BlacklistedByMovies(List<int> movieIds); List<Blacklist> BlacklistedByMovie(int movieId);
void DeleteForMovies(List<int> movieIds); void DeleteForMovies(List<int> movieIds);
} }
@ -30,9 +30,9 @@ public List<Blacklist> BlacklistedByTorrentInfoHash(int movieId, string torrentI
return Query(x => x.MovieId == movieId && x.TorrentInfoHash.Contains(torrentInfoHash)); return Query(x => x.MovieId == movieId && x.TorrentInfoHash.Contains(torrentInfoHash));
} }
public List<Blacklist> BlacklistedByMovies(List<int> movieIds) public List<Blacklist> BlacklistedByMovie(int movieId)
{ {
return Query(x => movieIds.Contains(x.MovieId)); return Query(x => x.MovieId == movieId);
} }
public void DeleteForMovies(List<int> movieIds) public void DeleteForMovies(List<int> movieIds)

View File

@ -16,6 +16,7 @@ public interface IBlacklistService
{ {
bool Blacklisted(int movieId, ReleaseInfo release); bool Blacklisted(int movieId, ReleaseInfo release);
PagingSpec<Blacklist> Paged(PagingSpec<Blacklist> pagingSpec); PagingSpec<Blacklist> Paged(PagingSpec<Blacklist> pagingSpec);
List<Blacklist> GetByMovieId(int movieId);
void Delete(int id); void Delete(int id);
} }
@ -65,6 +66,11 @@ public PagingSpec<Blacklist> Paged(PagingSpec<Blacklist> pagingSpec)
return _blacklistRepository.GetPaged(pagingSpec); return _blacklistRepository.GetPaged(pagingSpec);
} }
public List<Blacklist> GetByMovieId(int movieId)
{
return _blacklistRepository.BlacklistedByMovie(movieId);
}
public void Delete(int id) public void Delete(int id)
{ {
_blacklistRepository.Delete(id); _blacklistRepository.Delete(id);

View File

@ -107,18 +107,19 @@ public List<CustomFormat> ParseCustomFormat(MovieFile movieFile)
public List<CustomFormat> ParseCustomFormat(Blacklist blacklist) public List<CustomFormat> ParseCustomFormat(Blacklist blacklist)
{ {
var movie = _movieService.GetMovie(blacklist.MovieId);
var parsed = _parsingService.ParseMovieInfo(blacklist.SourceTitle, null); var parsed = _parsingService.ParseMovieInfo(blacklist.SourceTitle, null);
var info = new ParsedMovieInfo var info = new ParsedMovieInfo
{ {
MovieTitle = blacklist.Movie.Title, MovieTitle = movie.Title,
SimpleReleaseTitle = parsed?.SimpleReleaseTitle ?? blacklist.SourceTitle.SimplifyReleaseTitle(), SimpleReleaseTitle = parsed?.SimpleReleaseTitle ?? blacklist.SourceTitle.SimplifyReleaseTitle(),
Quality = blacklist.Quality, Quality = blacklist.Quality,
Languages = blacklist.Languages, Languages = blacklist.Languages,
ReleaseGroup = parsed?.ReleaseGroup, ReleaseGroup = parsed?.ReleaseGroup,
Edition = parsed?.Edition, Edition = parsed?.Edition,
Year = blacklist.Movie.Year, Year = movie.Year,
ImdbId = blacklist.Movie.ImdbId, ImdbId = movie.ImdbId,
ExtraInfo = new Dictionary<string, object> ExtraInfo = new Dictionary<string, object>
{ {
{ "IndexerFlags", blacklist.IndexerFlags }, { "IndexerFlags", blacklist.IndexerFlags },

View File

@ -1,7 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Core.Blacklisting; using NzbDrone.Core.Blacklisting;
using NzbDrone.Core.CustomFormats; using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using Radarr.Http; using Radarr.Http;
using Radarr.Http.REST;
namespace Radarr.Api.V3.Blacklist namespace Radarr.Api.V3.Blacklist
{ {
@ -18,6 +22,8 @@ public BlacklistModule(IBlacklistService blacklistService,
GetResourcePaged = GetBlacklist; GetResourcePaged = GetBlacklist;
DeleteResource = DeleteBlacklist; DeleteResource = DeleteBlacklist;
Get("/movie", x => GetMovieBlacklist());
} }
private PagingResource<BlacklistResource> GetBlacklist(PagingResource<BlacklistResource> pagingResource) private PagingResource<BlacklistResource> GetBlacklist(PagingResource<BlacklistResource> pagingResource)
@ -27,6 +33,20 @@ private PagingResource<BlacklistResource> GetBlacklist(PagingResource<BlacklistR
return ApplyToPage(_blacklistService.Paged, pagingSpec, (blacklist) => BlacklistResourceMapper.MapToResource(blacklist, _formatCalculator)); return ApplyToPage(_blacklistService.Paged, pagingSpec, (blacklist) => BlacklistResourceMapper.MapToResource(blacklist, _formatCalculator));
} }
private List<BlacklistResource> GetMovieBlacklist()
{
var queryMovieId = Request.Query.MovieId;
if (!queryMovieId.HasValue)
{
throw new BadRequestException("movieId is missing");
}
int movieId = Convert.ToInt32(queryMovieId.Value);
return _blacklistService.GetByMovieId(movieId).Select(h => BlacklistResourceMapper.MapToResource(h, _formatCalculator)).ToList();
}
private void DeleteBlacklist(int id) private void DeleteBlacklist(int id)
{ {
_blacklistService.Delete(id); _blacklistService.Delete(id);