New: Manage episodes through Manual Import modal

pull/4764/head
Mark McDowall 3 years ago
parent b184e62fa7
commit 2bf1ce1763

@ -1,34 +0,0 @@
import PropTypes from 'prop-types';
import React from 'react';
import Modal from 'Components/Modal/Modal';
import EpisodeFileEditorModalContentConnector from './EpisodeFileEditorModalContentConnector';
function EpisodeFileEditorModal(props) {
const {
isOpen,
onModalClose,
...otherProps
} = props;
return (
<Modal
isOpen={isOpen}
onModalClose={onModalClose}
>
{
isOpen &&
<EpisodeFileEditorModalContentConnector
{...otherProps}
onModalClose={onModalClose}
/>
}
</Modal>
);
}
EpisodeFileEditorModal.propTypes = {
isOpen: PropTypes.bool.isRequired,
onModalClose: PropTypes.func.isRequired
};
export default EpisodeFileEditorModal;

@ -1,8 +0,0 @@
.actions {
display: flex;
margin-right: auto;
}
.selectInput {
margin-left: 10px;
}

@ -1,310 +0,0 @@
import _ from 'lodash';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import hasDifferentItems from 'Utilities/Object/hasDifferentItems';
import getSelectedIds from 'Utilities/Table/getSelectedIds';
import removeOldSelectedState from 'Utilities/Table/removeOldSelectedState';
import selectAll from 'Utilities/Table/selectAll';
import toggleSelected from 'Utilities/Table/toggleSelected';
import { kinds } from 'Helpers/Props';
import SelectInput from 'Components/Form/SelectInput';
import Button from 'Components/Link/Button';
import SpinnerButton from 'Components/Link/SpinnerButton';
import LoadingIndicator from 'Components/Loading/LoadingIndicator';
import ConfirmModal from 'Components/Modal/ConfirmModal';
import ModalContent from 'Components/Modal/ModalContent';
import ModalHeader from 'Components/Modal/ModalHeader';
import ModalBody from 'Components/Modal/ModalBody';
import ModalFooter from 'Components/Modal/ModalFooter';
import Table from 'Components/Table/Table';
import TableBody from 'Components/Table/TableBody';
import SeasonNumber from 'Season/SeasonNumber';
import EpisodeFileEditorRow from './EpisodeFileEditorRow';
import styles from './EpisodeFileEditorModalContent.css';
const columns = [
{
name: 'episodeNumber',
label: 'Episode',
isVisible: true
},
{
name: 'relativePath',
label: 'Relative Path',
isVisible: true
},
{
name: 'airDateUtc',
label: 'Air Date',
isVisible: true
},
{
name: 'language',
label: 'Language',
isVisible: true
},
{
name: 'quality',
label: 'Quality',
isVisible: true
}
];
class EpisodeFileEditorModalContent extends Component {
//
// Lifecycle
constructor(props, context) {
super(props, context);
this.state = {
allSelected: false,
allUnselected: false,
lastToggled: null,
selectedState: {},
isConfirmDeleteModalOpen: false
};
}
componentDidUpdate(prevProps) {
if (hasDifferentItems(prevProps.items, this.props.items)) {
this.setState((state) => {
return removeOldSelectedState(state, prevProps.items);
});
}
}
//
// Control
getSelectedIds = () => {
const selectedIds = getSelectedIds(this.state.selectedState);
return selectedIds.reduce((acc, id) => {
const matchingItem = this.props.items.find((item) => item.id === id);
if (matchingItem && !acc.includes(matchingItem.episodeFileId)) {
acc.push(matchingItem.episodeFileId);
}
return acc;
}, []);
}
//
// Listeners
onSelectAllChange = ({ value }) => {
this.setState(selectAll(this.state.selectedState, value));
}
onSelectedChange = ({ id, value, shiftKey = false }) => {
this.setState((state) => {
return toggleSelected(state, this.props.items, id, value, shiftKey);
});
}
onDeletePress = () => {
this.setState({ isConfirmDeleteModalOpen: true });
}
onConfirmDelete = () => {
this.setState({ isConfirmDeleteModalOpen: false });
this.props.onDeletePress(this.getSelectedIds());
}
onConfirmDeleteModalClose = () => {
this.setState({ isConfirmDeleteModalOpen: false });
}
onLanguageChange = ({ value }) => {
const selectedIds = this.getSelectedIds();
if (!selectedIds.length) {
return;
}
this.props.onLanguageChange(selectedIds, parseInt(value));
}
onQualityChange = ({ value }) => {
const selectedIds = this.getSelectedIds();
if (!selectedIds.length) {
return;
}
this.props.onQualityChange(selectedIds, parseInt(value));
}
//
// Render
render() {
const {
seasonNumber,
isDeleting,
isFetching,
isPopulated,
error,
items,
languages,
qualities,
seriesType,
onModalClose
} = this.props;
const {
allSelected,
allUnselected,
selectedState,
isConfirmDeleteModalOpen
} = this.state;
const languageOptions = _.reduceRight(languages, (acc, language) => {
acc.push({
key: language.id,
value: language.name
});
return acc;
}, [{ key: 'selectLanguage', value: 'Select Language', disabled: true }]);
const qualityOptions = _.reduceRight(qualities, (acc, quality) => {
acc.push({
key: quality.id,
value: quality.name
});
return acc;
}, [{ key: 'selectQuality', value: 'Select Quality', disabled: true }]);
const hasSelectedFiles = this.getSelectedIds().length > 0;
return (
<ModalContent onModalClose={onModalClose}>
<ModalHeader>
Manage Episodes {seasonNumber != null && <SeasonNumber seasonNumber={seasonNumber} />}
</ModalHeader>
<ModalBody>
{
isFetching && !isPopulated ?
<LoadingIndicator /> :
null
}
{
!isFetching && error ?
<div>{error}</div> :
null
}
{
isPopulated && !items.length ?
<div>
No episode files to manage.
</div>:
null
}
{
isPopulated && items.length ?
<Table
columns={columns}
selectAll={true}
allSelected={allSelected}
allUnselected={allUnselected}
onSelectAllChange={this.onSelectAllChange}
>
<TableBody>
{
items.map((item) => {
return (
<EpisodeFileEditorRow
key={item.id}
seriesType={seriesType}
isSelected={selectedState[item.id]}
{...item}
onSelectedChange={this.onSelectedChange}
/>
);
})
}
</TableBody>
</Table> :
null
}
</ModalBody>
<ModalFooter>
<div className={styles.actions}>
<SpinnerButton
kind={kinds.DANGER}
isSpinning={isDeleting}
isDisabled={!hasSelectedFiles}
onPress={this.onDeletePress}
>
Delete
</SpinnerButton>
<div className={styles.selectInput}>
<SelectInput
name="language"
value="selectLanguage"
values={languageOptions}
isDisabled={!hasSelectedFiles}
onChange={this.onLanguageChange}
/>
</div>
<div className={styles.selectInput}>
<SelectInput
name="quality"
value="selectQuality"
values={qualityOptions}
isDisabled={!hasSelectedFiles}
onChange={this.onQualityChange}
/>
</div>
</div>
<Button
onPress={onModalClose}
>
Close
</Button>
</ModalFooter>
<ConfirmModal
isOpen={isConfirmDeleteModalOpen}
kind={kinds.DANGER}
title="Delete Selected Episode Files"
message={'Are you sure you want to delete the selected episode files?'}
confirmLabel="Delete"
onConfirm={this.onConfirmDelete}
onCancel={this.onConfirmDeleteModalClose}
/>
</ModalContent>
);
}
}
EpisodeFileEditorModalContent.propTypes = {
seasonNumber: PropTypes.number,
isDeleting: PropTypes.bool.isRequired,
isFetching: PropTypes.bool.isRequired,
isPopulated: PropTypes.bool.isRequired,
error: PropTypes.object,
items: PropTypes.arrayOf(PropTypes.object).isRequired,
languages: PropTypes.arrayOf(PropTypes.object).isRequired,
qualities: PropTypes.arrayOf(PropTypes.object).isRequired,
seriesType: PropTypes.string.isRequired,
onDeletePress: PropTypes.func.isRequired,
onLanguageChange: PropTypes.func.isRequired,
onQualityChange: PropTypes.func.isRequired,
onModalClose: PropTypes.func.isRequired
};
export default EpisodeFileEditorModalContent;

@ -1,174 +0,0 @@
/* eslint max-params: 0 */
import _ from 'lodash';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import getQualities from 'Utilities/Quality/getQualities';
import createSeriesSelector from 'Store/Selectors/createSeriesSelector';
import { deleteEpisodeFiles, updateEpisodeFiles } from 'Store/Actions/episodeFileActions';
import { fetchLanguageProfileSchema, fetchQualityProfileSchema } from 'Store/Actions/settingsActions';
import EpisodeFileEditorModalContent from './EpisodeFileEditorModalContent';
function createSchemaSelector() {
return createSelector(
(state) => state.settings.languageProfiles,
(state) => state.settings.qualityProfiles,
(languageProfiles, qualityProfiles) => {
const languages = _.map(languageProfiles.schema.languages, 'language');
const qualities = getQualities(qualityProfiles.schema.items);
let error = null;
if (languageProfiles.schemaError) {
error = 'Unable to load languages';
} else if (qualityProfiles.schemaError) {
error = 'Unable to load qualities';
}
return {
isFetching: languageProfiles.isSchemaFetching || qualityProfiles.isSchemaFetching,
isPopulated: languageProfiles.isSchemaPopulated && qualityProfiles.isSchemaPopulated,
error,
languages,
qualities
};
}
);
}
function createMapStateToProps() {
return createSelector(
(state, { seasonNumber }) => seasonNumber,
(state) => state.episodes,
(state) => state.episodeFiles,
createSchemaSelector(),
createSeriesSelector(),
(
seasonNumber,
episodes,
episodeFiles,
schema,
series
) => {
const filtered = _.filter(episodes.items, (episode) => {
if (seasonNumber >= 0 && episode.seasonNumber !== seasonNumber) {
return false;
}
if (!episode.episodeFileId) {
return false;
}
return _.some(episodeFiles.items, { id: episode.episodeFileId });
});
const sorted = _.orderBy(filtered, ['seasonNumber', 'episodeNumber'], ['desc', 'desc']);
const items = _.map(sorted, (episode) => {
const episodeFile = _.find(episodeFiles.items, { id: episode.episodeFileId });
return {
relativePath: episodeFile.relativePath,
language: episodeFile.language,
quality: episodeFile.quality,
languageCutoffNotMet: episodeFile.languageCutoffNotMet,
qualityCutoffNotMet: episodeFile.qualityCutoffNotMet,
...episode
};
});
return {
...schema,
items,
seriesType: series.seriesType,
isDeleting: episodeFiles.isDeleting,
isSaving: episodeFiles.isSaving
};
}
);
}
function createMapDispatchToProps(dispatch, props) {
return {
dispatchFetchLanguageProfileSchema(name, path) {
dispatch(fetchLanguageProfileSchema());
},
dispatchFetchQualityProfileSchema(name, path) {
dispatch(fetchQualityProfileSchema());
},
dispatchUpdateEpisodeFiles(updateProps) {
dispatch(updateEpisodeFiles(updateProps));
},
onDeletePress(episodeFileIds) {
dispatch(deleteEpisodeFiles({ episodeFileIds }));
}
};
}
class EpisodeFileEditorModalContentConnector extends Component {
//
// Lifecycle
componentDidMount() {
this.props.dispatchFetchLanguageProfileSchema();
this.props.dispatchFetchQualityProfileSchema();
}
//
// Listeners
onLanguageChange = (episodeFileIds, languageId) => {
const language = _.find(this.props.languages, { id: languageId });
this.props.dispatchUpdateEpisodeFiles({ episodeFileIds, language });
}
onQualityChange = (episodeFileIds, qualityId) => {
const quality = {
quality: _.find(this.props.qualities, { id: qualityId }),
revision: {
version: 1,
real: 0
}
};
this.props.dispatchUpdateEpisodeFiles({ episodeFileIds, quality });
}
//
// Render
render() {
const {
dispatchFetchLanguageProfileSchema,
dispatchFetchQualityProfileSchema,
dispatchUpdateEpisodeFiles,
...otherProps
} = this.props;
return (
<EpisodeFileEditorModalContent
{...otherProps}
onLanguageChange={this.onLanguageChange}
onQualityChange={this.onQualityChange}
/>
);
}
}
EpisodeFileEditorModalContentConnector.propTypes = {
seriesId: PropTypes.number.isRequired,
seasonNumber: PropTypes.number,
languages: PropTypes.arrayOf(PropTypes.object).isRequired,
qualities: PropTypes.arrayOf(PropTypes.object).isRequired,
dispatchFetchLanguageProfileSchema: PropTypes.func.isRequired,
dispatchFetchQualityProfileSchema: PropTypes.func.isRequired,
dispatchUpdateEpisodeFiles: PropTypes.func.isRequired
};
export default connect(createMapStateToProps, createMapDispatchToProps)(EpisodeFileEditorModalContentConnector);

@ -1,3 +0,0 @@
.absoluteEpisodeNumber {
margin-left: 5px;
}

@ -1,89 +0,0 @@
import PropTypes from 'prop-types';
import React from 'react';
import padNumber from 'Utilities/Number/padNumber';
import RelativeDateCellConnector from 'Components/Table/Cells/RelativeDateCellConnector';
import TableRow from 'Components/Table/TableRow';
import TableRowCell from 'Components/Table/Cells/TableRowCell';
import TableSelectCell from 'Components/Table/Cells/TableSelectCell';
import EpisodeLanguage from 'Episode/EpisodeLanguage';
import EpisodeQuality from 'Episode/EpisodeQuality';
import styles from './EpisodeFileEditorRow';
function EpisodeFileEditorRow(props) {
const {
id,
seriesType,
seasonNumber,
episodeNumber,
absoluteEpisodeNumber,
relativePath,
airDateUtc,
language,
quality,
qualityCutoffNotMet,
languageCutoffNotMet,
isSelected,
onSelectedChange
} = props;
return (
<TableRow>
<TableSelectCell
id={id}
isSelected={isSelected}
onSelectedChange={onSelectedChange}
/>
<TableRowCell>
{seasonNumber}x{padNumber(episodeNumber, 2)}
{
seriesType === 'anime' && !!absoluteEpisodeNumber &&
<span className={styles.absoluteEpisodeNumber}>
({absoluteEpisodeNumber})
</span>
}
</TableRowCell>
<TableRowCell>
{relativePath}
</TableRowCell>
<RelativeDateCellConnector
date={airDateUtc}
/>
<TableRowCell>
<EpisodeLanguage
language={language}
isCutoffNotMet={languageCutoffNotMet}
/>
</TableRowCell>
<TableRowCell>
<EpisodeQuality
quality={quality}
isCutoffNotMet={qualityCutoffNotMet}
/>
</TableRowCell>
</TableRow>
);
}
EpisodeFileEditorRow.propTypes = {
id: PropTypes.number.isRequired,
seriesType: PropTypes.string.isRequired,
seasonNumber: PropTypes.number.isRequired,
episodeNumber: PropTypes.number.isRequired,
absoluteEpisodeNumber: PropTypes.number,
relativePath: PropTypes.string.isRequired,
airDateUtc: PropTypes.string.isRequired,
language: PropTypes.object.isRequired,
quality: PropTypes.object.isRequired,
qualityCutoffNotMet: PropTypes.bool.isRequired,
languageCutoffNotMet: PropTypes.bool.isRequired,
isSelected: PropTypes.bool,
onSelectedChange: PropTypes.func.isRequired
};
export default EpisodeFileEditorRow;

@ -26,6 +26,12 @@
justify-content: flex-end; justify-content: flex-end;
} }
.deleteButton {
composes: button from '~Components/Link/Button.css';
margin-right: 10px;
}
.importMode, .importMode,
.bulkSelect { .bulkSelect {
composes: select from '~Components/Form/SelectInput.css'; composes: select from '~Components/Form/SelectInput.css';

@ -112,13 +112,21 @@ class InteractiveImportModalContent extends Component {
constructor(props, context) { constructor(props, context) {
super(props, context); super(props, context);
const instanceColumns = _.cloneDeep(columns);
if (!props.showSeries) {
instanceColumns.find((c) => c.name === 'series').isVisible = false;
}
this.state = { this.state = {
allSelected: false, allSelected: false,
allUnselected: false, allUnselected: false,
lastToggled: null, lastToggled: null,
selectedState: {}, selectedState: {},
invalidRowsSelected: [], invalidRowsSelected: [],
selectModalOpen: null withoutEpisodeFileIdRowsSelected: [],
selectModalOpen: null,
columns: instanceColumns
}; };
} }
@ -136,9 +144,14 @@ class InteractiveImportModalContent extends Component {
this.setState(selectAll(this.state.selectedState, value)); this.setState(selectAll(this.state.selectedState, value));
} }
onSelectedChange = ({ id, value, shiftKey = false }) => { onSelectedChange = ({ id, value, hasEpisodeFileId, shiftKey = false }) => {
this.setState((state) => { this.setState((state) => {
return toggleSelected(state, this.props.items, id, value, shiftKey); return {
...toggleSelected(state, this.props.items, id, value, shiftKey),
withoutEpisodeFileIdRowsSelected: hasEpisodeFileId || !value ?
_.without(state.withoutEpisodeFileIdRowsSelected, id) :
[...state.withoutEpisodeFileIdRowsSelected, id]
};
}); });
} }
@ -156,6 +169,16 @@ class InteractiveImportModalContent extends Component {
}); });
} }
onDeleteSelectedPress = () => {
const {
onDeleteSelectedPress
} = this.props;
const selected = this.getSelectedIds();
onDeleteSelectedPress(selected);
}
onImportSelectedPress = () => { onImportSelectedPress = () => {
const { const {
downloadId, downloadId,
@ -193,7 +216,9 @@ class InteractiveImportModalContent extends Component {
const { const {
downloadId, downloadId,
allowSeriesChange, allowSeriesChange,
autoSelectRow,
showFilterExistingFiles, showFilterExistingFiles,
showDelete,
showImportMode, showImportMode,
filterExistingFiles, filterExistingFiles,
title, title,
@ -215,6 +240,7 @@ class InteractiveImportModalContent extends Component {
allUnselected, allUnselected,
selectedState, selectedState,
invalidRowsSelected, invalidRowsSelected,
withoutEpisodeFileIdRowsSelected,
selectModalOpen selectModalOpen
} = this.state; } = this.state;
@ -308,7 +334,7 @@ class InteractiveImportModalContent extends Component {
{ {
isPopulated && !!items.length && !isFetching && !isFetching && isPopulated && !!items.length && !isFetching && !isFetching &&
<Table <Table
columns={columns} columns={this.state.columns}
horizontalScroll={true} horizontalScroll={true}
selectAll={true} selectAll={true}
allSelected={allSelected} allSelected={allSelected}
@ -327,6 +353,8 @@ class InteractiveImportModalContent extends Component {
isSelected={selectedState[item.id]} isSelected={selectedState[item.id]}
{...item} {...item}
allowSeriesChange={allowSeriesChange} allowSeriesChange={allowSeriesChange}
autoSelectRow={autoSelectRow}
columns={this.state.columns}
onSelectedChange={this.onSelectedChange} onSelectedChange={this.onSelectedChange}
onValidRowChange={this.onValidRowChange} onValidRowChange={this.onValidRowChange}
/> />
@ -345,6 +373,19 @@ class InteractiveImportModalContent extends Component {
<ModalFooter className={styles.footer}> <ModalFooter className={styles.footer}>
<div className={styles.leftButtons}> <div className={styles.leftButtons}>
{
showDelete ?
<Button
className={styles.deleteButton}
kind={kinds.DANGER}
isDisabled={!selectedIds.length || !!withoutEpisodeFileIdRowsSelected.length}
onPress={onModalClose}
>
Delete
</Button> :
null
}
{ {
!downloadId && showImportMode ? !downloadId && showImportMode ?
<SelectInput <SelectInput
@ -437,7 +478,10 @@ class InteractiveImportModalContent extends Component {
InteractiveImportModalContent.propTypes = { InteractiveImportModalContent.propTypes = {
downloadId: PropTypes.string, downloadId: PropTypes.string,
showSeries: PropTypes.bool.isRequired,
allowSeriesChange: PropTypes.bool.isRequired, allowSeriesChange: PropTypes.bool.isRequired,
autoSelectRow: PropTypes.bool.isRequired,
showDelete: PropTypes.bool.isRequired,
showImportMode: PropTypes.bool.isRequired, showImportMode: PropTypes.bool.isRequired,
showFilterExistingFiles: PropTypes.bool.isRequired, showFilterExistingFiles: PropTypes.bool.isRequired,
filterExistingFiles: PropTypes.bool.isRequired, filterExistingFiles: PropTypes.bool.isRequired,
@ -454,13 +498,17 @@ InteractiveImportModalContent.propTypes = {
onSortPress: PropTypes.func.isRequired, onSortPress: PropTypes.func.isRequired,
onFilterExistingFilesChange: PropTypes.func.isRequired, onFilterExistingFilesChange: PropTypes.func.isRequired,
onImportModeChange: PropTypes.func.isRequired, onImportModeChange: PropTypes.func.isRequired,
onDeleteSelectedPress: PropTypes.func.isRequired,
onImportSelectedPress: PropTypes.func.isRequired, onImportSelectedPress: PropTypes.func.isRequired,
onModalClose: PropTypes.func.isRequired onModalClose: PropTypes.func.isRequired
}; };
InteractiveImportModalContent.defaultProps = { InteractiveImportModalContent.defaultProps = {
showSeries: true,
allowSeriesChange: true, allowSeriesChange: true,
autoSelectRow: true,
showFilterExistingFiles: false, showFilterExistingFiles: false,
showDelete: false,
showImportMode: true, showImportMode: true,
importMode: 'move' importMode: 'move'
}; };

@ -1,14 +1,42 @@
import _ from 'lodash';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import React, { Component } from 'react'; import React, { Component } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { sortDirections } from 'Helpers/Props';
import { fetchInteractiveImportItems, setInteractiveImportSort, clearInteractiveImport, setInteractiveImportMode } from 'Store/Actions/interactiveImportActions'; import { fetchInteractiveImportItems, setInteractiveImportSort, clearInteractiveImport, setInteractiveImportMode } from 'Store/Actions/interactiveImportActions';
import createClientSideCollectionSelector from 'Store/Selectors/createClientSideCollectionSelector'; import createClientSideCollectionSelector from 'Store/Selectors/createClientSideCollectionSelector';
import { executeCommand } from 'Store/Actions/commandActions'; import { executeCommand } from 'Store/Actions/commandActions';
import { updateEpisodeFiles, deleteEpisodeFiles } from 'Store/Actions/episodeFileActions';
import * as commandNames from 'Commands/commandNames'; import * as commandNames from 'Commands/commandNames';
import InteractiveImportModalContent from './InteractiveImportModalContent'; import InteractiveImportModalContent from './InteractiveImportModalContent';
function isSameEpisodeFile(file, originalFile) {
const {
series,
seasonNumber,
episodes
} = file;
if (!originalFile) {
return false;
}
if (!originalFile.series || series.id !== originalFile.series.id) {
return false;
}
if (seasonNumber !== originalFile.seasonNumber) {
return false;
}
const episodeIds = episodes.map((e) => e.id);
const originalEpisodeIds = originalFile.episodes ? originalFile.episodes.map((e) => e.id) : [];
return episodeIds.every((episodeId) => {
return originalEpisodeIds.indexOf(episodeId) >= 0;
});
}
function createMapStateToProps() { function createMapStateToProps() {
return createSelector( return createSelector(
createClientSideCollectionSelector('interactiveImport'), createClientSideCollectionSelector('interactiveImport'),
@ -23,6 +51,8 @@ const mapDispatchToProps = {
dispatchSetInteractiveImportSort: setInteractiveImportSort, dispatchSetInteractiveImportSort: setInteractiveImportSort,
dispatchSetInteractiveImportMode: setInteractiveImportMode, dispatchSetInteractiveImportMode: setInteractiveImportMode,
dispatchClearInteractiveImport: clearInteractiveImport, dispatchClearInteractiveImport: clearInteractiveImport,
dispatchUpdateEpisodeFiles: updateEpisodeFiles,
dispatchDeleteEpisodeFiles: deleteEpisodeFiles,
dispatchExecuteCommand: executeCommand dispatchExecuteCommand: executeCommand
}; };
@ -44,16 +74,34 @@ class InteractiveImportModalContentConnector extends Component {
const { const {
downloadId, downloadId,
seriesId, seriesId,
folder seasonNumber,
folder,
initialSortKey,
initialSortDirection,
dispatchSetInteractiveImportSort,
dispatchFetchInteractiveImportItems
} = this.props; } = this.props;
const { const {
filterExistingFiles filterExistingFiles
} = this.state; } = this.state;
this.props.dispatchFetchInteractiveImportItems({ if (initialSortKey) {
const sortProps = {
sortKey: initialSortKey
};
if (initialSortDirection) {
sortProps.sortDirection = initialSortDirection;
}
dispatchSetInteractiveImportSort(sortProps);
}
dispatchFetchInteractiveImportItems({
downloadId, downloadId,
seriesId, seriesId,
seasonNumber,
folder, folder,
filterExistingFiles filterExistingFiles
}); });
@ -99,10 +147,23 @@ class InteractiveImportModalContentConnector extends Component {
this.props.dispatchSetInteractiveImportMode({ importMode }); this.props.dispatchSetInteractiveImportMode({ importMode });
} }
onDeleteSelectedPress = (selected) => {
// TODO: Delete selected (if they have episode IDs)
}
onImportSelectedPress = (selected, importMode) => { onImportSelectedPress = (selected, importMode) => {
const {
items,
originalItems,
dispatchUpdateEpisodeFiles,
dispatchExecuteCommand,
onModalClose
} = this.props;
const existingFiles = [];
const files = []; const files = [];
_.forEach(this.props.items, (item) => { items.forEach((item) => {
const isSelected = selected.indexOf(item.id) > -1; const isSelected = selected.indexOf(item.id) > -1;
if (isSelected) { if (isSelected) {
@ -112,32 +173,48 @@ class InteractiveImportModalContentConnector extends Component {
episodes, episodes,
releaseGroup, releaseGroup,
quality, quality,
language language,
episodeFileId
} = item; } = item;
if (!series) { if (!series) {
this.setState({ interactiveImportErrorMessage: 'Series must be chosen for each selected file' }); this.setState({ interactiveImportErrorMessage: 'Series must be chosen for each selected file' });
return false; return;
} }
if (isNaN(seasonNumber)) { if (isNaN(seasonNumber)) {
this.setState({ interactiveImportErrorMessage: 'Season must be chosen for each selected file' }); this.setState({ interactiveImportErrorMessage: 'Season must be chosen for each selected file' });
return false; return;
} }
if (!episodes || !episodes.length) { if (!episodes || !episodes.length) {
this.setState({ interactiveImportErrorMessage: 'One or more episodes must be chosen for each selected file' }); this.setState({ interactiveImportErrorMessage: 'One or more episodes must be chosen for each selected file' });
return false; return;
} }
if (!quality) { if (!quality) {
this.setState({ interactiveImportErrorMessage: 'Quality must be chosen for each selected file' }); this.setState({ interactiveImportErrorMessage: 'Quality must be chosen for each selected file' });
return false; return;
} }
if (!language) { if (!language) {
this.setState({ interactiveImportErrorMessage: 'Language must be chosen for each selected file' }); this.setState({ interactiveImportErrorMessage: 'Language must be chosen for each selected file' });
return false; return;
}
if (episodeFileId) {
const originalItem = originalItems.find((i) => i.id === item.id);
if (isSameEpisodeFile(item, originalItem)) {
existingFiles.push({
id: episodeFileId,
releaseGroup,
quality,
language
});
return;
}
} }
files.push({ files.push({
@ -148,22 +225,35 @@ class InteractiveImportModalContentConnector extends Component {
releaseGroup, releaseGroup,
quality, quality,
language, language,
downloadId: this.props.downloadId downloadId: this.props.downloadId,
episodeFileId
}); });
} }
}); });
if (!files.length) { let shouldClose = false;
return;
if (existingFiles.length) {
dispatchUpdateEpisodeFiles({
files: existingFiles
});
shouldClose = true;
} }
this.props.dispatchExecuteCommand({ if (files.length) {
name: commandNames.INTERACTIVE_IMPORT, dispatchExecuteCommand({
files, name: commandNames.INTERACTIVE_IMPORT,
importMode files,
}); importMode
});
shouldClose = true;
}
this.props.onModalClose(); if (shouldClose) {
onModalClose();
}
} }
// //
@ -183,6 +273,7 @@ class InteractiveImportModalContentConnector extends Component {
onSortPress={this.onSortPress} onSortPress={this.onSortPress}
onFilterExistingFilesChange={this.onFilterExistingFilesChange} onFilterExistingFilesChange={this.onFilterExistingFilesChange}
onImportModeChange={this.onImportModeChange} onImportModeChange={this.onImportModeChange}
onDeleteSelectedPress={this.onDeleteSelectedPress}
onImportSelectedPress={this.onImportSelectedPress} onImportSelectedPress={this.onImportSelectedPress}
/> />
); );
@ -192,13 +283,19 @@ class InteractiveImportModalContentConnector extends Component {
InteractiveImportModalContentConnector.propTypes = { InteractiveImportModalContentConnector.propTypes = {
downloadId: PropTypes.string, downloadId: PropTypes.string,
seriesId: PropTypes.number, seriesId: PropTypes.number,
seasonNumber: PropTypes.number,
folder: PropTypes.string, folder: PropTypes.string,
filterExistingFiles: PropTypes.bool.isRequired, filterExistingFiles: PropTypes.bool.isRequired,
items: PropTypes.arrayOf(PropTypes.object).isRequired, items: PropTypes.arrayOf(PropTypes.object).isRequired,
initialSortKey: PropTypes.string,
initialSortDirection: PropTypes.oneOf(sortDirections.all),
originalItems: PropTypes.arrayOf(PropTypes.object).isRequired,
dispatchFetchInteractiveImportItems: PropTypes.func.isRequired, dispatchFetchInteractiveImportItems: PropTypes.func.isRequired,
dispatchSetInteractiveImportSort: PropTypes.func.isRequired, dispatchSetInteractiveImportSort: PropTypes.func.isRequired,
dispatchSetInteractiveImportMode: PropTypes.func.isRequired, dispatchSetInteractiveImportMode: PropTypes.func.isRequired,
dispatchClearInteractiveImport: PropTypes.func.isRequired, dispatchClearInteractiveImport: PropTypes.func.isRequired,
dispatchUpdateEpisodeFiles: PropTypes.func.isRequired,
dispatchDeleteEpisodeFiles: PropTypes.func.isRequired,
dispatchExecuteCommand: PropTypes.func.isRequired, dispatchExecuteCommand: PropTypes.func.isRequired,
onModalClose: PropTypes.func.isRequired onModalClose: PropTypes.func.isRequired
}; };

@ -41,23 +41,35 @@ class InteractiveImportRow extends Component {
componentDidMount() { componentDidMount() {
const { const {
allowSeriesChange,
id, id,
series, series,
seasonNumber, seasonNumber,
episodes, episodes,
quality, quality,
language language,
episodeFileId,
columns
} = this.props; } = this.props;
if ( if (
allowSeriesChange &&
series && series &&
seasonNumber != null && seasonNumber != null &&
episodes.length && episodes.length &&
quality && quality &&
language language
) { ) {
this.props.onSelectedChange({ id, value: true }); this.props.onSelectedChange({
id,
hasEpisodeFileId: !!episodeFileId,
value: true
});
} }
this.setState({
isSeriesColumnVisible: columns.find((c) => c.name === 'series').isVisible
});
} }
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
@ -104,17 +116,34 @@ class InteractiveImportRow extends Component {
selectRowAfterChange = (value) => { selectRowAfterChange = (value) => {
const { const {
id, id,
episodeFileId,
isSelected isSelected
} = this.props; } = this.props;
if (!isSelected && value === true) { if (!isSelected && value === true) {
this.props.onSelectedChange({ id, value }); this.props.onSelectedChange({
id,
hasEpisodeFileId: !!episodeFileId,
value
});
} }
} }
// //
// Listeners // Listeners
onSelectedChange = (result) => {
const {
episodeFileId,
onSelectedChange
} = this.props;
onSelectedChange({
...result,
hasEpisodeFileId: !!episodeFileId
});
}
onSelectSeriesPress = () => { onSelectSeriesPress = () => {
this.setState({ isSelectSeriesModalOpen: true }); this.setState({ isSelectSeriesModalOpen: true });
} }
@ -186,8 +215,7 @@ class InteractiveImportRow extends Component {
size, size,
rejections, rejections,
isReprocessing, isReprocessing,
isSelected, isSelected
onSelectedChange
} = this.props; } = this.props;
const { const {
@ -224,7 +252,7 @@ class InteractiveImportRow extends Component {
<TableSelectCell <TableSelectCell
id={id} id={id}
isSelected={isSelected} isSelected={isSelected}
onSelectedChange={onSelectedChange} onSelectedChange={this.onSelectedChange}
/> />
<TableRowCell <TableRowCell
@ -234,15 +262,19 @@ class InteractiveImportRow extends Component {
{relativePath} {relativePath}
</TableRowCell> </TableRowCell>
<TableRowCellButton {
isDisabled={!allowSeriesChange} this.state.isSeriesColumnVisible ?
title={allowSeriesChange ? 'Click to change series' : undefined} <TableRowCellButton
onPress={this.onSelectSeriesPress} isDisabled={!allowSeriesChange}
> title={allowSeriesChange ? 'Click to change series' : undefined}
{ onPress={this.onSelectSeriesPress}
showSeriesPlaceholder ? <InteractiveImportRowCellPlaceholder /> : seriesTitle >
} {
</TableRowCellButton> showSeriesPlaceholder ? <InteractiveImportRowCellPlaceholder /> : seriesTitle
}
</TableRowCellButton> :
null
}
<TableRowCellButton <TableRowCellButton
isDisabled={!series} isDisabled={!series}
@ -418,6 +450,8 @@ InteractiveImportRow.propTypes = {
language: PropTypes.object, language: PropTypes.object,
size: PropTypes.number.isRequired, size: PropTypes.number.isRequired,
rejections: PropTypes.arrayOf(PropTypes.object).isRequired, rejections: PropTypes.arrayOf(PropTypes.object).isRequired,
columns: PropTypes.arrayOf(PropTypes.object).isRequired,
episodeFileId: PropTypes.number,
isReprocessing: PropTypes.bool, isReprocessing: PropTypes.bool,
isSelected: PropTypes.bool, isSelected: PropTypes.bool,
onSelectedChange: PropTypes.func.isRequired, onSelectedChange: PropTypes.func.isRequired,

@ -192,7 +192,7 @@ OrganizePreviewModalContent.propTypes = {
isPopulated: PropTypes.bool.isRequired, isPopulated: PropTypes.bool.isRequired,
error: PropTypes.object, error: PropTypes.object,
items: PropTypes.arrayOf(PropTypes.object).isRequired, items: PropTypes.arrayOf(PropTypes.object).isRequired,
seasonNumber: PropTypes.string.isRequired, seasonNumber: PropTypes.number,
path: PropTypes.string.isRequired, path: PropTypes.string.isRequired,
renameEpisodes: PropTypes.bool, renameEpisodes: PropTypes.bool,
episodeFormat: PropTypes.string, episodeFormat: PropTypes.string,

@ -5,7 +5,7 @@ import TextTruncate from 'react-text-truncate';
import formatBytes from 'Utilities/Number/formatBytes'; import formatBytes from 'Utilities/Number/formatBytes';
import selectAll from 'Utilities/Table/selectAll'; import selectAll from 'Utilities/Table/selectAll';
import toggleSelected from 'Utilities/Table/toggleSelected'; import toggleSelected from 'Utilities/Table/toggleSelected';
import { align, icons, kinds, sizes, tooltipPositions } from 'Helpers/Props'; import { align, icons, kinds, sizes, sortDirections, tooltipPositions } from 'Helpers/Props';
import fonts from 'Styles/Variables/fonts'; import fonts from 'Styles/Variables/fonts';
import HeartRating from 'Components/HeartRating'; import HeartRating from 'Components/HeartRating';
import Icon from 'Components/Icon'; import Icon from 'Components/Icon';
@ -22,7 +22,6 @@ import PageToolbarSeparator from 'Components/Page/Toolbar/PageToolbarSeparator';
import PageToolbarButton from 'Components/Page/Toolbar/PageToolbarButton'; import PageToolbarButton from 'Components/Page/Toolbar/PageToolbarButton';
import Popover from 'Components/Tooltip/Popover'; import Popover from 'Components/Tooltip/Popover';
import Tooltip from 'Components/Tooltip/Tooltip'; import Tooltip from 'Components/Tooltip/Tooltip';
import EpisodeFileEditorModal from 'EpisodeFile/Editor/EpisodeFileEditorModal';
import InteractiveImportModal from 'InteractiveImport/InteractiveImportModal'; import InteractiveImportModal from 'InteractiveImport/InteractiveImportModal';
import OrganizePreviewModalConnector from 'Organize/OrganizePreviewModalConnector'; import OrganizePreviewModalConnector from 'Organize/OrganizePreviewModalConnector';
import QualityProfileNameConnector from 'Settings/Profiles/Quality/QualityProfileNameConnector'; import QualityProfileNameConnector from 'Settings/Profiles/Quality/QualityProfileNameConnector';
@ -76,7 +75,6 @@ class SeriesDetails extends Component {
isEditSeriesModalOpen: false, isEditSeriesModalOpen: false,
isDeleteSeriesModalOpen: false, isDeleteSeriesModalOpen: false,
isSeriesHistoryModalOpen: false, isSeriesHistoryModalOpen: false,
isInteractiveImportModalOpen: false,
isMonitorOptionsModalOpen: false, isMonitorOptionsModalOpen: false,
allExpanded: false, allExpanded: false,
allCollapsed: false, allCollapsed: false,
@ -104,14 +102,6 @@ class SeriesDetails extends Component {
this.setState({ isManageEpisodesOpen: false }); this.setState({ isManageEpisodesOpen: false });
} }
onInteractiveImportPress = () => {
this.setState({ isInteractiveImportModalOpen: true });
}
onInteractiveImportModalClose = () => {
this.setState({ isInteractiveImportModalOpen: false });
}
onEditSeriesPress = () => { onEditSeriesPress = () => {
this.setState({ isEditSeriesModalOpen: true }); this.setState({ isEditSeriesModalOpen: true });
} }
@ -227,7 +217,6 @@ class SeriesDetails extends Component {
isEditSeriesModalOpen, isEditSeriesModalOpen,
isDeleteSeriesModalOpen, isDeleteSeriesModalOpen,
isSeriesHistoryModalOpen, isSeriesHistoryModalOpen,
isInteractiveImportModalOpen,
isMonitorOptionsModalOpen, isMonitorOptionsModalOpen,
allExpanded, allExpanded,
allCollapsed, allCollapsed,
@ -299,12 +288,6 @@ class SeriesDetails extends Component {
onPress={this.onSeriesHistoryPress} onPress={this.onSeriesHistoryPress}
/> />
<PageToolbarButton
label="Manual File Import"
iconName={icons.INTERACTIVE}
onPress={this.onInteractiveImportPress}
/>
<PageToolbarSeparator /> <PageToolbarSeparator />
<PageToolbarButton <PageToolbarButton
@ -652,9 +635,18 @@ class SeriesDetails extends Component {
onModalClose={this.onOrganizeModalClose} onModalClose={this.onOrganizeModalClose}
/> />
<EpisodeFileEditorModal <InteractiveImportModal
isOpen={isManageEpisodesOpen} isOpen={isManageEpisodesOpen}
seriesId={id} seriesId={id}
title={title}
folder={path}
initialSortKey="relativePath"
initialSortDirection={sortDirections.DESCENDING}
showSeries={false}
allowSeriesChange={false}
autoSelectRow={false}
showDelete={true}
showImportMode={false}
onModalClose={this.onManageEpisodesModalClose} onModalClose={this.onManageEpisodesModalClose}
/> />
@ -677,16 +669,6 @@ class SeriesDetails extends Component {
onModalClose={this.onDeleteSeriesModalClose} onModalClose={this.onDeleteSeriesModalClose}
/> />
<InteractiveImportModal
isOpen={isInteractiveImportModalOpen}
seriesId={id}
folder={path}
allowSeriesChange={false}
showFilterExistingFiles={true}
showImportMode={false}
onModalClose={this.onInteractiveImportModalClose}
/>
<MonitoringOptionsModal <MonitoringOptionsModal
isOpen={isMonitorOptionsModalOpen} isOpen={isMonitorOptionsModalOpen}
seriesId={id} seriesId={id}

@ -5,7 +5,7 @@ import isAfter from 'Utilities/Date/isAfter';
import isBefore from 'Utilities/Date/isBefore'; import isBefore from 'Utilities/Date/isBefore';
import formatBytes from 'Utilities/Number/formatBytes'; import formatBytes from 'Utilities/Number/formatBytes';
import getToggledRange from 'Utilities/Table/getToggledRange'; import getToggledRange from 'Utilities/Table/getToggledRange';
import { align, icons, kinds, sizes, tooltipPositions } from 'Helpers/Props'; import { align, icons, kinds, sizes, sortDirections, tooltipPositions } from 'Helpers/Props';
import Icon from 'Components/Icon'; import Icon from 'Components/Icon';
import IconButton from 'Components/Link/IconButton'; import IconButton from 'Components/Link/IconButton';
import Label from 'Components/Label'; import Label from 'Components/Label';
@ -20,7 +20,7 @@ import MenuItem from 'Components/Menu/MenuItem';
import Table from 'Components/Table/Table'; import Table from 'Components/Table/Table';
import TableBody from 'Components/Table/TableBody'; import TableBody from 'Components/Table/TableBody';
import Popover from 'Components/Tooltip/Popover'; import Popover from 'Components/Tooltip/Popover';
import EpisodeFileEditorModal from 'EpisodeFile/Editor/EpisodeFileEditorModal'; import InteractiveImportModal from 'InteractiveImport/InteractiveImportModal';
import OrganizePreviewModalConnector from 'Organize/OrganizePreviewModalConnector'; import OrganizePreviewModalConnector from 'Organize/OrganizePreviewModalConnector';
import SeriesHistoryModal from 'Series/History/SeriesHistoryModal'; import SeriesHistoryModal from 'Series/History/SeriesHistoryModal';
import SeasonInteractiveSearchModalConnector from 'Series/Search/SeasonInteractiveSearchModalConnector'; import SeasonInteractiveSearchModalConnector from 'Series/Search/SeasonInteractiveSearchModalConnector';
@ -204,6 +204,7 @@ class SeriesDetailsSeason extends Component {
render() { render() {
const { const {
seriesId, seriesId,
path,
monitored, monitored,
seasonNumber, seasonNumber,
items, items,
@ -234,6 +235,8 @@ class SeriesDetailsSeason extends Component {
isInteractiveSearchModalOpen isInteractiveSearchModalOpen
} = this.state; } = this.state;
const title = seasonNumber === 0 ? 'Specials' : `Season ${seasonNumber}`;
return ( return (
<div <div
className={styles.season} className={styles.season}
@ -248,15 +251,9 @@ class SeriesDetailsSeason extends Component {
onPress={onMonitorSeasonPress} onPress={onMonitorSeasonPress}
/> />
{ <span className={styles.seasonNumber}>
seasonNumber === 0 ? {title}
<span className={styles.seasonNumber}> </span>
Specials
</span> :
<span className={styles.seasonNumber}>
Season {seasonNumber}
</span>
}
<Popover <Popover
className={styles.episodeCountTooltip} className={styles.episodeCountTooltip}
@ -486,10 +483,19 @@ class SeriesDetailsSeason extends Component {
onModalClose={this.onOrganizeModalClose} onModalClose={this.onOrganizeModalClose}
/> />
<EpisodeFileEditorModal <InteractiveImportModal
isOpen={isManageEpisodesOpen} isOpen={isManageEpisodesOpen}
seriesId={seriesId} seriesId={seriesId}
seasonNumber={seasonNumber} seasonNumber={seasonNumber}
title={title}
folder={path}
initialSortKey="relativePath"
initialSortDirection={sortDirections.DESCENDING}
showSeries={false}
allowSeriesChange={false}
autoSelectRow={false}
showDelete={true}
showImportMode={false}
onModalClose={this.onManageEpisodesModalClose} onModalClose={this.onManageEpisodesModalClose}
/> />
@ -513,6 +519,7 @@ class SeriesDetailsSeason extends Component {
SeriesDetailsSeason.propTypes = { SeriesDetailsSeason.propTypes = {
seriesId: PropTypes.number.isRequired, seriesId: PropTypes.number.isRequired,
path: PropTypes.string.isRequired,
monitored: PropTypes.bool.isRequired, monitored: PropTypes.bool.isRequired,
seasonNumber: PropTypes.number.isRequired, seasonNumber: PropTypes.number.isRequired,
items: PropTypes.arrayOf(PropTypes.object).isRequired, items: PropTypes.arrayOf(PropTypes.object).isRequired,

@ -34,6 +34,7 @@ function createMapStateToProps() {
columns: episodes.columns, columns: episodes.columns,
isSearching, isSearching,
seriesMonitored: series.monitored, seriesMonitored: series.monitored,
path: series.path,
isSmallScreen: dimensions.isSmallScreen isSmallScreen: dimensions.isSmallScreen
}; };
} }

@ -140,28 +140,14 @@ export const actionHandlers = handleThunks({
}, },
[UPDATE_EPISODE_FILES]: function(getState, payload, dispatch) { [UPDATE_EPISODE_FILES]: function(getState, payload, dispatch) {
const { const { files } = payload;
episodeFileIds,
language,
quality
} = payload;
dispatch(set({ section, isSaving: true })); dispatch(set({ section, isSaving: true }));
const requestData = { const requestData = files;
episodeFileIds
};
if (language) {
requestData.language = language;
}
if (quality) {
requestData.quality = quality;
}
const promise = createAjaxRequest({ const promise = createAjaxRequest({
url: '/episodeFile/editor', url: '/episodeFile/bulk',
method: 'PUT', method: 'PUT',
dataType: 'json', dataType: 'json',
data: JSON.stringify(requestData) data: JSON.stringify(requestData)
@ -169,23 +155,22 @@ export const actionHandlers = handleThunks({
promise.done((data) => { promise.done((data) => {
dispatch(batchActions([ dispatch(batchActions([
...episodeFileIds.map((id) => { ...files.map((file) => {
const id = file.id;
const props = {}; const props = {};
const episodeFile = data.find((f) => f.id === id);
const episodeFile = data.find((file) => file.id === id);
props.qualityCutoffNotMet = episodeFile.qualityCutoffNotMet; props.qualityCutoffNotMet = episodeFile.qualityCutoffNotMet;
props.languageCutoffNotMet = episodeFile.languageCutoffNotMet; props.languageCutoffNotMet = episodeFile.languageCutoffNotMet;
props.language = file.language;
props.quality = file.quality;
props.releaseGroup = file.releaseGroup;
if (language) { return updateItem({
props.language = language; section,
} id,
...props
if (quality) { });
props.quality = quality;
}
return updateItem({ section, id, ...props });
}), }),
set({ set({

@ -29,6 +29,7 @@ export const defaultState = {
isPopulated: false, isPopulated: false,
error: null, error: null,
items: [], items: [],
originalItems: [],
sortKey: 'quality', sortKey: 'quality',
sortDirection: sortDirections.DESCENDING, sortDirection: sortDirections.DESCENDING,
recentFolders: [], recentFolders: [],
@ -127,7 +128,8 @@ export const actionHandlers = handleThunks({
section, section,
isFetching: false, isFetching: false,
isPopulated: true, isPopulated: true,
error: null error: null,
originalItems: data
}) })
])); ]));
}); });

@ -12,6 +12,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
public string FolderName { get; set; } public string FolderName { get; set; }
public int SeriesId { get; set; } public int SeriesId { get; set; }
public List<int> EpisodeIds { get; set; } public List<int> EpisodeIds { get; set; }
public int? EpisodeFileId { get; set; }
public QualityModel Quality { get; set; } public QualityModel Quality { get; set; }
public Language Language { get; set; } public Language Language { get; set; }
public string ReleaseGroup { get; set; } public string ReleaseGroup { get; set; }

@ -16,6 +16,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
public Series Series { get; set; } public Series Series { get; set; }
public int? SeasonNumber { get; set; } public int? SeasonNumber { get; set; }
public List<Episode> Episodes { get; set; } public List<Episode> Episodes { get; set; }
public int? EpisodeFileId { get; set; }
public QualityModel Quality { get; set; } public QualityModel Quality { get; set; }
public Language Language { get; set; } public Language Language { get; set; }
public string ReleaseGroup { get; set; } public string ReleaseGroup { get; set; }

@ -22,6 +22,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
{ {
public interface IManualImportService public interface IManualImportService
{ {
List<ManualImportItem> GetMediaFiles(int seriesId, int? seasonNumber);
List<ManualImportItem> GetMediaFiles(string path, string downloadId, int? seriesId, bool filterExistingFiles); List<ManualImportItem> GetMediaFiles(string path, string downloadId, int? seriesId, bool filterExistingFiles);
ManualImportItem ReprocessItem(string path, string downloadId, int seriesId, int? seasonNumber, List<int> episodeIds, string releaseGroup, QualityModel quality, Language language); ManualImportItem ReprocessItem(string path, string downloadId, int seriesId, int? seasonNumber, List<int> episodeIds, string releaseGroup, QualityModel quality, Language language);
} }
@ -38,6 +39,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
private readonly IAggregationService _aggregationService; private readonly IAggregationService _aggregationService;
private readonly ITrackedDownloadService _trackedDownloadService; private readonly ITrackedDownloadService _trackedDownloadService;
private readonly IDownloadedEpisodesImportService _downloadedEpisodesImportService; private readonly IDownloadedEpisodesImportService _downloadedEpisodesImportService;
private readonly IMediaFileService _mediaFileService;
private readonly IEventAggregator _eventAggregator; private readonly IEventAggregator _eventAggregator;
private readonly Logger _logger; private readonly Logger _logger;
@ -51,6 +53,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
IImportApprovedEpisodes importApprovedEpisodes, IImportApprovedEpisodes importApprovedEpisodes,
ITrackedDownloadService trackedDownloadService, ITrackedDownloadService trackedDownloadService,
IDownloadedEpisodesImportService downloadedEpisodesImportService, IDownloadedEpisodesImportService downloadedEpisodesImportService,
IMediaFileService mediaFileService,
IEventAggregator eventAggregator, IEventAggregator eventAggregator,
Logger logger) Logger logger)
{ {
@ -64,10 +67,46 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
_importApprovedEpisodes = importApprovedEpisodes; _importApprovedEpisodes = importApprovedEpisodes;
_trackedDownloadService = trackedDownloadService; _trackedDownloadService = trackedDownloadService;
_downloadedEpisodesImportService = downloadedEpisodesImportService; _downloadedEpisodesImportService = downloadedEpisodesImportService;
_mediaFileService = mediaFileService;
_eventAggregator = eventAggregator; _eventAggregator = eventAggregator;
_logger = logger; _logger = logger;
} }
public List<ManualImportItem> GetMediaFiles(int seriesId, int? seasonNumber)
{
var series = _seriesService.GetSeries(seriesId);
var directoryInfo = new DirectoryInfo(series.Path);
var seriesFiles = seasonNumber.HasValue ? _mediaFileService.GetFilesBySeason(seriesId, seasonNumber.Value) : _mediaFileService.GetFilesBySeries(seriesId);
var items = seriesFiles.Select(episodeFile => MapItem(episodeFile, series, directoryInfo.Name)).ToList();
if (!seasonNumber.HasValue)
{
var mediaFiles = _diskScanService.FilterPaths(series.Path, _diskScanService.GetVideoFiles(series.Path)).ToList();
var unmappedFiles = MediaFileService.FilterExistingFiles(mediaFiles, seriesFiles, series);
items.AddRange(unmappedFiles.Select(file =>
new ManualImportItem
{
Path = Path.Combine(series.Path, file),
FolderName = directoryInfo.Name,
RelativePath = series.Path.GetRelativePath(file),
Name = Path.GetFileNameWithoutExtension(file),
Series = series,
SeasonNumber = null,
Episodes = new List<Episode>(),
ReleaseGroup = string.Empty,
Quality = new QualityModel(Quality.Unknown),
Language = Language.Unknown,
Size = _diskProvider.GetFileSize(file),
Rejections = Enumerable.Empty<Rejection>()
}
));
}
return items;
}
public List<ManualImportItem> GetMediaFiles(string path, string downloadId, int? seriesId, bool filterExistingFiles) public List<ManualImportItem> GetMediaFiles(string path, string downloadId, int? seriesId, bool filterExistingFiles)
{ {
if (downloadId.IsNotNullOrWhiteSpace()) if (downloadId.IsNotNullOrWhiteSpace())
@ -363,6 +402,27 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
return item; return item;
} }
private ManualImportItem MapItem(EpisodeFile episodeFile, Series series, string folderName)
{
var item = new ManualImportItem();
item.Path = Path.Combine(series.Path, episodeFile.RelativePath);
item.FolderName = folderName;
item.RelativePath = episodeFile.RelativePath;
item.Name = Path.GetFileNameWithoutExtension(episodeFile.Path);
item.Series = series;
item.SeasonNumber = episodeFile.SeasonNumber;
item.Episodes = episodeFile.Episodes.Value;
item.ReleaseGroup = episodeFile.ReleaseGroup;
item.Quality = episodeFile.Quality;
item.Language = episodeFile.Language;
item.Size = _diskProvider.GetFileSize(item.Path);
item.Rejections = Enumerable.Empty<Rejection>();
item.EpisodeFileId = episodeFile.Id;
return item;
}
public void Execute(ManualImportCommand message) public void Execute(ManualImportCommand message)
{ {
_logger.ProgressTrace("Manually importing {0} files using mode {1}", message.Files.Count, message.ImportMode); _logger.ProgressTrace("Manually importing {0} files using mode {1}", message.Files.Count, message.ImportMode);
@ -379,6 +439,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
var episodes = _episodeService.GetEpisodes(file.EpisodeIds); var episodes = _episodeService.GetEpisodes(file.EpisodeIds);
var fileEpisodeInfo = Parser.Parser.ParsePath(file.Path) ?? new ParsedEpisodeInfo(); var fileEpisodeInfo = Parser.Parser.ParsePath(file.Path) ?? new ParsedEpisodeInfo();
var existingFile = series.Path.IsParentPath(file.Path); var existingFile = series.Path.IsParentPath(file.Path);
TrackedDownload trackedDownload = null; TrackedDownload trackedDownload = null;
var localEpisode = new LocalEpisode var localEpisode = new LocalEpisode
@ -437,7 +498,10 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
} }
} }
_logger.ProgressTrace("Manually imported {0} files", imported.Count); if (imported.Any())
{
_logger.ProgressTrace("Manually imported {0} files", imported.Count);
}
foreach (var groupedTrackedDownload in importedTrackedDownload.GroupBy(i => i.TrackedDownload.DownloadItem.DownloadId).ToList()) foreach (var groupedTrackedDownload in importedTrackedDownload.GroupBy(i => i.TrackedDownload.DownloadItem.DownloadId).ToList())
{ {

@ -88,11 +88,9 @@ namespace NzbDrone.Core.MediaFiles
public List<string> FilterExistingFiles(List<string> files, Series series) public List<string> FilterExistingFiles(List<string> files, Series series)
{ {
var seriesFiles = GetFilesBySeries(series.Id).Select(f => Path.Combine(series.Path, f.RelativePath)).ToList(); var seriesFiles = GetFilesBySeries(series.Id);
if (!seriesFiles.Any()) return files; return FilterExistingFiles(files, seriesFiles, series);
return files.Except(seriesFiles, PathEqualityComparer.Instance).ToList();
} }
public EpisodeFile Get(int id) public EpisodeFile Get(int id)
@ -115,5 +113,15 @@ namespace NzbDrone.Core.MediaFiles
var files = GetFilesBySeries(message.Series.Id); var files = GetFilesBySeries(message.Series.Id);
_mediaFileRepository.DeleteMany(files); _mediaFileRepository.DeleteMany(files);
} }
public static List<string> FilterExistingFiles(List<string> files, List<EpisodeFile> seriesFiles, Series series)
{
var seriesFilePaths = seriesFiles.Select(f => Path.Combine(series.Path, f.RelativePath)).ToList();
if (!seriesFilePaths.Any()) return files;
return files.Except(seriesFilePaths, PathEqualityComparer.Instance).ToList();
}
} }
} }

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Nancy; using Nancy;
using NzbDrone.Core.Datastore.Events; using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.DecisionEngine.Specifications; using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.Exceptions; using NzbDrone.Core.Exceptions;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
@ -44,7 +43,8 @@ namespace Sonarr.Api.V3.EpisodeFiles
UpdateResource = SetQuality; UpdateResource = SetQuality;
DeleteResource = DeleteEpisodeFile; DeleteResource = DeleteEpisodeFile;
Put("/editor", episodeFiles => SetQuality()); Put("/editor", episodeFiles => SetPropertiesEditor());
Put("/bulk", episodeFiles => SetPropertiesBulk());
Delete("/bulk", episodeFiles => DeleteEpisodeFiles()); Delete("/bulk", episodeFiles => DeleteEpisodeFiles());
} }
@ -109,7 +109,8 @@ namespace Sonarr.Api.V3.EpisodeFiles
_mediaFileService.Update(episodeFile); _mediaFileService.Update(episodeFile);
} }
private object SetQuality() // Deprecated: Use SetPropertiesBulk instead
private object SetPropertiesEditor()
{ {
var resource = Request.Body.FromJson<EpisodeFileListResource>(); var resource = Request.Body.FromJson<EpisodeFileListResource>();
var episodeFiles = _mediaFileService.GetFiles(resource.EpisodeFileIds); var episodeFiles = _mediaFileService.GetFiles(resource.EpisodeFileIds);
@ -141,8 +142,44 @@ namespace Sonarr.Api.V3.EpisodeFiles
var series = _seriesService.GetSeries(episodeFiles.First().SeriesId); var series = _seriesService.GetSeries(episodeFiles.First().SeriesId);
return ResponseWithCode(episodeFiles.ConvertAll(f => f.ToResource(series, _upgradableSpecification)) return ResponseWithCode(episodeFiles.ConvertAll(f => f.ToResource(series, _upgradableSpecification)), HttpStatusCode.Accepted);
, HttpStatusCode.Accepted); }
private object SetPropertiesBulk()
{
var resource = Request.Body.FromJson<List<EpisodeFileResource>>();
var episodeFiles = _mediaFileService.GetFiles(resource.Select(r => r.Id));
foreach (var episodeFile in episodeFiles)
{
var resourceEpisodeFile = resource.Single(r => r.Id == episodeFile.Id);
if (resourceEpisodeFile.Language != null)
{
episodeFile.Language = resourceEpisodeFile.Language;
}
if (resourceEpisodeFile.Quality != null)
{
episodeFile.Quality = resourceEpisodeFile.Quality;
}
if (resourceEpisodeFile.SceneName != null && SceneChecker.IsSceneTitle(resourceEpisodeFile.SceneName))
{
episodeFile.SceneName = resourceEpisodeFile.SceneName;
}
if (resourceEpisodeFile.ReleaseGroup != null)
{
episodeFile.ReleaseGroup = resourceEpisodeFile.ReleaseGroup;
}
}
_mediaFileService.Update(episodeFiles);
var series = _seriesService.GetSeries(episodeFiles.First().SeriesId);
return ResponseWithCode(episodeFiles.ConvertAll(f => f.ToResource(series, _upgradableSpecification)), HttpStatusCode.Accepted);
} }
private void DeleteEpisodeFile(int id) private void DeleteEpisodeFile(int id)

@ -1,6 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Nancy;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Languages; using NzbDrone.Core.Languages;
using NzbDrone.Core.MediaFiles.EpisodeImport.Manual; using NzbDrone.Core.MediaFiles.EpisodeImport.Manual;
@ -30,6 +29,12 @@ namespace Sonarr.Api.V3.ManualImport
var downloadId = (string)Request.Query.downloadId; var downloadId = (string)Request.Query.downloadId;
var filterExistingFiles = Request.GetBooleanQueryParameter("filterExistingFiles", true); var filterExistingFiles = Request.GetBooleanQueryParameter("filterExistingFiles", true);
var seriesId = Request.GetNullableIntegerQueryParameter("seriesId", null); var seriesId = Request.GetNullableIntegerQueryParameter("seriesId", null);
var seasonNumber = Request.GetNullableIntegerQueryParameter("seasonNumber", null);
if (seriesId.HasValue)
{
return _manualImportService.GetMediaFiles(seriesId.Value, seasonNumber).ToResource().Select(AddQualityWeight).ToList();
}
return _manualImportService.GetMediaFiles(folder, downloadId, seriesId, filterExistingFiles).ToResource().Select(AddQualityWeight).ToList(); return _manualImportService.GetMediaFiles(folder, downloadId, seriesId, filterExistingFiles).ToResource().Select(AddQualityWeight).ToList();
} }

@ -21,6 +21,7 @@ namespace Sonarr.Api.V3.ManualImport
public SeriesResource Series { get; set; } public SeriesResource Series { get; set; }
public int? SeasonNumber { get; set; } public int? SeasonNumber { get; set; }
public List<EpisodeResource> Episodes { get; set; } public List<EpisodeResource> Episodes { get; set; }
public int? EpisodeFileId { get; set; }
public string ReleaseGroup { get; set; } public string ReleaseGroup { get; set; }
public QualityModel Quality { get; set; } public QualityModel Quality { get; set; }
public Language Language { get; set; } public Language Language { get; set; }
@ -46,6 +47,7 @@ namespace Sonarr.Api.V3.ManualImport
Series = model.Series.ToResource(), Series = model.Series.ToResource(),
SeasonNumber = model.SeasonNumber, SeasonNumber = model.SeasonNumber,
Episodes = model.Episodes.ToResource(), Episodes = model.Episodes.ToResource(),
EpisodeFileId = model.EpisodeFileId,
ReleaseGroup = model.ReleaseGroup, ReleaseGroup = model.ReleaseGroup,
Quality = model.Quality, Quality = model.Quality,
Language = model.Language, Language = model.Language,

Loading…
Cancel
Save