parent
a5bac30ef3
commit
241bf85f15
@ -0,0 +1,44 @@
|
||||
.specification {
|
||||
composes: card from '~Components/Card.css';
|
||||
|
||||
position: relative;
|
||||
width: 300px;
|
||||
height: 100px;
|
||||
}
|
||||
|
||||
.underlay {
|
||||
@add-mixin cover;
|
||||
}
|
||||
|
||||
.overlay {
|
||||
@add-mixin linkOverlay;
|
||||
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.name {
|
||||
text-align: center;
|
||||
font-weight: lighter;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.actions {
|
||||
margin-top: 20px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.presetsMenu {
|
||||
composes: menu from '~Components/Menu/Menu.css';
|
||||
|
||||
display: inline-block;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.presetsMenuButton {
|
||||
composes: button from '~Components/Link/Button.css';
|
||||
|
||||
&::after {
|
||||
margin-left: 5px;
|
||||
content: '\25BE';
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import { sizes } from 'Helpers/Props';
|
||||
import Button from 'Components/Link/Button';
|
||||
import Link from 'Components/Link/Link';
|
||||
import Menu from 'Components/Menu/Menu';
|
||||
import MenuContent from 'Components/Menu/MenuContent';
|
||||
import AddSpecificationPresetMenuItem from './AddSpecificationPresetMenuItem';
|
||||
import styles from './AddSpecificationItem.css';
|
||||
|
||||
class AddSpecificationItem extends Component {
|
||||
|
||||
//
|
||||
// Listeners
|
||||
|
||||
onSpecificationSelect = () => {
|
||||
const {
|
||||
implementation
|
||||
} = this.props;
|
||||
|
||||
this.props.onSpecificationSelect({ implementation });
|
||||
}
|
||||
|
||||
//
|
||||
// Render
|
||||
|
||||
render() {
|
||||
const {
|
||||
implementation,
|
||||
implementationName,
|
||||
infoLink,
|
||||
presets,
|
||||
onSpecificationSelect
|
||||
} = this.props;
|
||||
|
||||
const hasPresets = !!presets && !!presets.length;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={styles.specification}
|
||||
>
|
||||
<Link
|
||||
className={styles.underlay}
|
||||
onPress={this.onSpecificationSelect}
|
||||
/>
|
||||
|
||||
<div className={styles.overlay}>
|
||||
<div className={styles.name}>
|
||||
{implementationName}
|
||||
</div>
|
||||
|
||||
<div className={styles.actions}>
|
||||
{
|
||||
hasPresets &&
|
||||
<span>
|
||||
<Button
|
||||
size={sizes.SMALL}
|
||||
onPress={this.onSpecificationSelect}
|
||||
>
|
||||
Custom
|
||||
</Button>
|
||||
|
||||
<Menu className={styles.presetsMenu}>
|
||||
<Button
|
||||
className={styles.presetsMenuButton}
|
||||
size={sizes.SMALL}
|
||||
>
|
||||
Presets
|
||||
</Button>
|
||||
|
||||
<MenuContent>
|
||||
{
|
||||
presets.map((preset, index) => {
|
||||
return (
|
||||
<AddSpecificationPresetMenuItem
|
||||
key={index}
|
||||
name={preset.name}
|
||||
implementation={implementation}
|
||||
onPress={onSpecificationSelect}
|
||||
/>
|
||||
);
|
||||
})
|
||||
}
|
||||
</MenuContent>
|
||||
</Menu>
|
||||
</span>
|
||||
}
|
||||
|
||||
<Button
|
||||
to={infoLink}
|
||||
size={sizes.SMALL}
|
||||
>
|
||||
More info
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
AddSpecificationItem.propTypes = {
|
||||
implementation: PropTypes.string.isRequired,
|
||||
implementationName: PropTypes.string.isRequired,
|
||||
infoLink: PropTypes.string.isRequired,
|
||||
presets: PropTypes.arrayOf(PropTypes.object),
|
||||
onSpecificationSelect: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default AddSpecificationItem;
|
@ -0,0 +1,25 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React from 'react';
|
||||
import Modal from 'Components/Modal/Modal';
|
||||
import AddSpecificationModalContentConnector from './AddSpecificationModalContentConnector';
|
||||
|
||||
function AddSpecificationModal({ isOpen, onModalClose, ...otherProps }) {
|
||||
return (
|
||||
<Modal
|
||||
isOpen={isOpen}
|
||||
onModalClose={onModalClose}
|
||||
>
|
||||
<AddSpecificationModalContentConnector
|
||||
{...otherProps}
|
||||
onModalClose={onModalClose}
|
||||
/>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
AddSpecificationModal.propTypes = {
|
||||
isOpen: PropTypes.bool.isRequired,
|
||||
onModalClose: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default AddSpecificationModal;
|
@ -0,0 +1,5 @@
|
||||
.specifications {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import { kinds } from 'Helpers/Props';
|
||||
import Alert from 'Components/Alert';
|
||||
import Button from 'Components/Link/Button';
|
||||
import LoadingIndicator from 'Components/Loading/LoadingIndicator';
|
||||
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 AddSpecificationItem from './AddSpecificationItem';
|
||||
import styles from './AddSpecificationModalContent.css';
|
||||
|
||||
class AddSpecificationModalContent extends Component {
|
||||
|
||||
//
|
||||
// Render
|
||||
|
||||
render() {
|
||||
const {
|
||||
isSchemaFetching,
|
||||
isSchemaPopulated,
|
||||
schemaError,
|
||||
schema,
|
||||
onSpecificationSelect,
|
||||
onModalClose
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<ModalContent onModalClose={onModalClose}>
|
||||
<ModalHeader>
|
||||
Add Condition
|
||||
</ModalHeader>
|
||||
|
||||
<ModalBody>
|
||||
{
|
||||
isSchemaFetching &&
|
||||
<LoadingIndicator />
|
||||
}
|
||||
|
||||
{
|
||||
!isSchemaFetching && !!schemaError &&
|
||||
<div>Unable to add a new condition, please try again.</div>
|
||||
}
|
||||
|
||||
{
|
||||
isSchemaPopulated && !schemaError &&
|
||||
<div>
|
||||
|
||||
<Alert kind={kinds.INFO}>
|
||||
<div>Radarr supports custom conditions against the following release properties</div>
|
||||
<div>Visit github for more details</div>
|
||||
</Alert>
|
||||
|
||||
<div className={styles.specifications}>
|
||||
{
|
||||
schema.map((specification) => {
|
||||
return (
|
||||
<AddSpecificationItem
|
||||
key={specification.implementation}
|
||||
{...specification}
|
||||
onSpecificationSelect={onSpecificationSelect}
|
||||
/>
|
||||
);
|
||||
})
|
||||
}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button
|
||||
onPress={onModalClose}
|
||||
>
|
||||
Close
|
||||
</Button>
|
||||
</ModalFooter>
|
||||
</ModalContent>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
AddSpecificationModalContent.propTypes = {
|
||||
isSchemaFetching: PropTypes.bool.isRequired,
|
||||
isSchemaPopulated: PropTypes.bool.isRequired,
|
||||
schemaError: PropTypes.object,
|
||||
schema: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
onSpecificationSelect: PropTypes.func.isRequired,
|
||||
onModalClose: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default AddSpecificationModalContent;
|
@ -0,0 +1,70 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { createSelector } from 'reselect';
|
||||
import { fetchCustomFormatSpecificationSchema, selectCustomFormatSpecificationSchema } from 'Store/Actions/settingsActions';
|
||||
import AddSpecificationModalContent from './AddSpecificationModalContent';
|
||||
|
||||
function createMapStateToProps() {
|
||||
return createSelector(
|
||||
(state) => state.settings.customFormatSpecifications,
|
||||
(specifications) => {
|
||||
const {
|
||||
isSchemaFetching,
|
||||
isSchemaPopulated,
|
||||
schemaError,
|
||||
schema
|
||||
} = specifications;
|
||||
|
||||
return {
|
||||
isSchemaFetching,
|
||||
isSchemaPopulated,
|
||||
schemaError,
|
||||
schema
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const mapDispatchToProps = {
|
||||
fetchCustomFormatSpecificationSchema,
|
||||
selectCustomFormatSpecificationSchema
|
||||
};
|
||||
|
||||
class AddSpecificationModalContentConnector extends Component {
|
||||
|
||||
//
|
||||
// Lifecycle
|
||||
|
||||
componentDidMount() {
|
||||
this.props.fetchCustomFormatSpecificationSchema();
|
||||
}
|
||||
|
||||
//
|
||||
// Listeners
|
||||
|
||||
onSpecificationSelect = ({ implementation, name }) => {
|
||||
this.props.selectCustomFormatSpecificationSchema({ implementation, presetName: name });
|
||||
this.props.onModalClose({ specificationSelected: true });
|
||||
}
|
||||
|
||||
//
|
||||
// Render
|
||||
|
||||
render() {
|
||||
return (
|
||||
<AddSpecificationModalContent
|
||||
{...this.props}
|
||||
onSpecificationSelect={this.onSpecificationSelect}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
AddSpecificationModalContentConnector.propTypes = {
|
||||
fetchCustomFormatSpecificationSchema: PropTypes.func.isRequired,
|
||||
selectCustomFormatSpecificationSchema: PropTypes.func.isRequired,
|
||||
onModalClose: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default connect(createMapStateToProps, mapDispatchToProps)(AddSpecificationModalContentConnector);
|
@ -0,0 +1,49 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import MenuItem from 'Components/Menu/MenuItem';
|
||||
|
||||
class AddSpecificationPresetMenuItem extends Component {
|
||||
|
||||
//
|
||||
// Listeners
|
||||
|
||||
onPress = () => {
|
||||
const {
|
||||
name,
|
||||
implementation
|
||||
} = this.props;
|
||||
|
||||
this.props.onPress({
|
||||
name,
|
||||
implementation
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
// Render
|
||||
|
||||
render() {
|
||||
const {
|
||||
name,
|
||||
implementation,
|
||||
...otherProps
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<MenuItem
|
||||
{...otherProps}
|
||||
onPress={this.onPress}
|
||||
>
|
||||
{name}
|
||||
</MenuItem>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
AddSpecificationPresetMenuItem.propTypes = {
|
||||
name: PropTypes.string.isRequired,
|
||||
implementation: PropTypes.string.isRequired,
|
||||
onPress: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default AddSpecificationPresetMenuItem;
|
@ -0,0 +1,27 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React from 'react';
|
||||
import { sizes } from 'Helpers/Props';
|
||||
import Modal from 'Components/Modal/Modal';
|
||||
import EditSpecificationModalContentConnector from './EditSpecificationModalContentConnector';
|
||||
|
||||
function EditSpecificationModal({ isOpen, onModalClose, ...otherProps }) {
|
||||
return (
|
||||
<Modal
|
||||
size={sizes.MEDIUM}
|
||||
isOpen={isOpen}
|
||||
onModalClose={onModalClose}
|
||||
>
|
||||
<EditSpecificationModalContentConnector
|
||||
{...otherProps}
|
||||
onModalClose={onModalClose}
|
||||
/>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
EditSpecificationModal.propTypes = {
|
||||
isOpen: PropTypes.bool.isRequired,
|
||||
onModalClose: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default EditSpecificationModal;
|
@ -0,0 +1,50 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { clearPendingChanges } from 'Store/Actions/baseActions';
|
||||
import EditSpecificationModal from './EditSpecificationModal';
|
||||
|
||||
function createMapDispatchToProps(dispatch, props) {
|
||||
const section = 'settings.customFormatSpecifications';
|
||||
|
||||
return {
|
||||
dispatchClearPendingChanges() {
|
||||
dispatch(clearPendingChanges({ section }));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
class EditSpecificationModalConnector extends Component {
|
||||
|
||||
//
|
||||
// Listeners
|
||||
|
||||
onModalClose = () => {
|
||||
this.props.dispatchClearPendingChanges();
|
||||
this.props.onModalClose();
|
||||
}
|
||||
|
||||
//
|
||||
// Render
|
||||
|
||||
render() {
|
||||
const {
|
||||
dispatchClearPendingChanges,
|
||||
...otherProps
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<EditSpecificationModal
|
||||
{...otherProps}
|
||||
onModalClose={this.onModalClose}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
EditSpecificationModalConnector.propTypes = {
|
||||
onModalClose: PropTypes.func.isRequired,
|
||||
dispatchClearPendingChanges: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default connect(null, createMapDispatchToProps)(EditSpecificationModalConnector);
|
@ -0,0 +1,5 @@
|
||||
.deleteButton {
|
||||
composes: button from '~Components/Link/Button.css';
|
||||
|
||||
margin-right: auto;
|
||||
}
|
@ -0,0 +1,154 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React from 'react';
|
||||
import { inputTypes, kinds } from 'Helpers/Props';
|
||||
import Alert from 'Components/Alert';
|
||||
import Link from 'Components/Link/Link';
|
||||
import Button from 'Components/Link/Button';
|
||||
import SpinnerErrorButton from 'Components/Link/SpinnerErrorButton';
|
||||
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 Form from 'Components/Form/Form';
|
||||
import FormGroup from 'Components/Form/FormGroup';
|
||||
import FormLabel from 'Components/Form/FormLabel';
|
||||
import FormInputGroup from 'Components/Form/FormInputGroup';
|
||||
import ProviderFieldFormGroup from 'Components/Form/ProviderFieldFormGroup';
|
||||
import styles from './EditSpecificationModalContent.css';
|
||||
|
||||
function EditSpecificationModalContent(props) {
|
||||
const {
|
||||
advancedSettings,
|
||||
item,
|
||||
onInputChange,
|
||||
onFieldChange,
|
||||
onCancelPress,
|
||||
onSavePress,
|
||||
onDeleteSpecificationPress,
|
||||
...otherProps
|
||||
} = props;
|
||||
|
||||
const {
|
||||
id,
|
||||
implementationName,
|
||||
name,
|
||||
negate,
|
||||
required,
|
||||
fields
|
||||
} = item;
|
||||
|
||||
return (
|
||||
<ModalContent onModalClose={onCancelPress}>
|
||||
<ModalHeader>
|
||||
{`${id ? 'Edit' : 'Add'} Condition - ${implementationName}`}
|
||||
</ModalHeader>
|
||||
|
||||
<ModalBody>
|
||||
<Form
|
||||
{...otherProps}
|
||||
>
|
||||
{
|
||||
fields && fields.some((x) => x.label === 'Regular Expression') &&
|
||||
<Alert kind={kinds.INFO}>
|
||||
<div>This condition matches using Regular Expressions. See <Link to="https://www.regular-expressions.info/tutorial.html">here</Link> for details. Note that the characters <code>{'\\^$.|?*+()[{'}</code> have special meanings and need escaping with a <code>\</code></div>
|
||||
<div>Regular expressions can be tested <Link to="http://regexstorm.net/tester">here</Link>.</div>
|
||||
</Alert>
|
||||
}
|
||||
|
||||
<FormGroup>
|
||||
<FormLabel>
|
||||
Name
|
||||
</FormLabel>
|
||||
|
||||
<FormInputGroup
|
||||
type={inputTypes.TEXT}
|
||||
name="name"
|
||||
{...name}
|
||||
onChange={onInputChange}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
{
|
||||
fields && fields.map((field) => {
|
||||
return (
|
||||
<ProviderFieldFormGroup
|
||||
key={field.name}
|
||||
advancedSettings={advancedSettings}
|
||||
provider="specifications"
|
||||
providerData={item}
|
||||
{...field}
|
||||
onChange={onFieldChange}
|
||||
/>
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
<FormGroup>
|
||||
<FormLabel>
|
||||
Negate
|
||||
</FormLabel>
|
||||
|
||||
<FormInputGroup
|
||||
type={inputTypes.CHECK}
|
||||
name="negate"
|
||||
{...negate}
|
||||
helpText={`If checked, the custom format will not apply if this ${implementationName} condition matches.`}
|
||||
onChange={onInputChange}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup>
|
||||
<FormLabel>
|
||||
Required
|
||||
</FormLabel>
|
||||
|
||||
<FormInputGroup
|
||||
type={inputTypes.CHECK}
|
||||
name="required"
|
||||
{...required}
|
||||
helpText={`This ${implementationName} condition must match for the custom format to apply. Otherwise a single ${implementationName} match is sufficient.`}
|
||||
onChange={onInputChange}
|
||||
/>
|
||||
</FormGroup>
|
||||
</Form>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
{
|
||||
id &&
|
||||
<Button
|
||||
className={styles.deleteButton}
|
||||
kind={kinds.DANGER}
|
||||
onPress={onDeleteSpecificationPress}
|
||||
>
|
||||
Delete
|
||||
</Button>
|
||||
}
|
||||
|
||||
<Button
|
||||
onPress={onCancelPress}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
|
||||
<SpinnerErrorButton
|
||||
isSpinning={false}
|
||||
onPress={onSavePress}
|
||||
>
|
||||
Save
|
||||
</SpinnerErrorButton>
|
||||
</ModalFooter>
|
||||
</ModalContent>
|
||||
);
|
||||
}
|
||||
|
||||
EditSpecificationModalContent.propTypes = {
|
||||
advancedSettings: PropTypes.bool.isRequired,
|
||||
item: PropTypes.object.isRequired,
|
||||
onInputChange: PropTypes.func.isRequired,
|
||||
onFieldChange: PropTypes.func.isRequired,
|
||||
onCancelPress: PropTypes.func.isRequired,
|
||||
onSavePress: PropTypes.func.isRequired,
|
||||
onDeleteSpecificationPress: PropTypes.func
|
||||
};
|
||||
|
||||
export default EditSpecificationModalContent;
|
@ -0,0 +1,78 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { createSelector } from 'reselect';
|
||||
import createProviderSettingsSelector from 'Store/Selectors/createProviderSettingsSelector';
|
||||
import { setCustomFormatSpecificationValue, setCustomFormatSpecificationFieldValue, saveCustomFormatSpecification, clearCustomFormatSpecificationPending } from 'Store/Actions/settingsActions';
|
||||
import EditSpecificationModalContent from './EditSpecificationModalContent';
|
||||
|
||||
function createMapStateToProps() {
|
||||
return createSelector(
|
||||
(state) => state.settings.advancedSettings,
|
||||
createProviderSettingsSelector('customFormatSpecifications'),
|
||||
(advancedSettings, specification) => {
|
||||
return {
|
||||
advancedSettings,
|
||||
...specification
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const mapDispatchToProps = {
|
||||
setCustomFormatSpecificationValue,
|
||||
setCustomFormatSpecificationFieldValue,
|
||||
saveCustomFormatSpecification,
|
||||
clearCustomFormatSpecificationPending
|
||||
};
|
||||
|
||||
class EditSpecificationModalContentConnector extends Component {
|
||||
|
||||
//
|
||||
// Listeners
|
||||
|
||||
onInputChange = ({ name, value }) => {
|
||||
this.props.setCustomFormatSpecificationValue({ name, value });
|
||||
}
|
||||
|
||||
onFieldChange = ({ name, value }) => {
|
||||
this.props.setCustomFormatSpecificationFieldValue({ name, value });
|
||||
}
|
||||
|
||||
onCancelPress = () => {
|
||||
this.props.clearCustomFormatSpecificationPending();
|
||||
this.props.onModalClose();
|
||||
}
|
||||
|
||||
onSavePress = () => {
|
||||
this.props.saveCustomFormatSpecification({ id: this.props.id });
|
||||
this.props.onModalClose();
|
||||
}
|
||||
|
||||
//
|
||||
// Render
|
||||
|
||||
render() {
|
||||
return (
|
||||
<EditSpecificationModalContent
|
||||
{...this.props}
|
||||
onCancelPress={this.onCancelPress}
|
||||
onSavePress={this.onSavePress}
|
||||
onInputChange={this.onInputChange}
|
||||
onFieldChange={this.onFieldChange}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
EditSpecificationModalContentConnector.propTypes = {
|
||||
id: PropTypes.number,
|
||||
item: PropTypes.object.isRequired,
|
||||
setCustomFormatSpecificationValue: PropTypes.func.isRequired,
|
||||
setCustomFormatSpecificationFieldValue: PropTypes.func.isRequired,
|
||||
clearCustomFormatSpecificationPending: PropTypes.func.isRequired,
|
||||
saveCustomFormatSpecification: PropTypes.func.isRequired,
|
||||
onModalClose: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default connect(createMapStateToProps, mapDispatchToProps)(EditSpecificationModalContentConnector);
|
@ -0,0 +1,38 @@
|
||||
.customFormat {
|
||||
composes: card from '~Components/Card.css';
|
||||
|
||||
width: 300px;
|
||||
}
|
||||
|
||||
.nameContainer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.name {
|
||||
@add-mixin truncate;
|
||||
|
||||
margin-bottom: 20px;
|
||||
font-weight: 300;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.cloneButton {
|
||||
composes: button from '~Components/Link/IconButton.css';
|
||||
|
||||
height: 36px;
|
||||
}
|
||||
|
||||
.labels {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
margin-top: 5px;
|
||||
pointer-events: all;
|
||||
}
|
||||
|
||||
.tooltipLabel {
|
||||
composes: label from '~Components/Label.css';
|
||||
|
||||
margin: 0;
|
||||
border: none;
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import { icons, kinds } from 'Helpers/Props';
|
||||
import Card from 'Components/Card';
|
||||
import Label from 'Components/Label';
|
||||
import IconButton from 'Components/Link/IconButton';
|
||||
import ConfirmModal from 'Components/Modal/ConfirmModal';
|
||||
import EditSpecificationModalConnector from './EditSpecificationModal';
|
||||
import styles from './Specification.css';
|
||||
|
||||
class Specification extends Component {
|
||||
|
||||
//
|
||||
// Lifecycle
|
||||
|
||||
constructor(props, context) {
|
||||
super(props, context);
|
||||
|
||||
this.state = {
|
||||
isEditSpecificationModalOpen: false,
|
||||
isDeleteSpecificationModalOpen: false
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
// Listeners
|
||||
|
||||
onEditSpecificationPress = () => {
|
||||
this.setState({ isEditSpecificationModalOpen: true });
|
||||
}
|
||||
|
||||
onEditSpecificationModalClose = () => {
|
||||
this.setState({ isEditSpecificationModalOpen: false });
|
||||
}
|
||||
|
||||
onDeleteSpecificationPress = () => {
|
||||
this.setState({
|
||||
isEditSpecificationModalOpen: false,
|
||||
isDeleteSpecificationModalOpen: true
|
||||
});
|
||||
}
|
||||
|
||||
onDeleteSpecificationModalClose = () => {
|
||||
this.setState({ isDeleteSpecificationModalOpen: false });
|
||||
}
|
||||
|
||||
onCloneSpecificationPress = () => {
|
||||
this.props.onCloneSpecificationPress(this.props.id);
|
||||
}
|
||||
|
||||
onConfirmDeleteSpecification = () => {
|
||||
this.props.onConfirmDeleteSpecification(this.props.id);
|
||||
}
|
||||
|
||||
//
|
||||
// Lifecycle
|
||||
|
||||
render() {
|
||||
const {
|
||||
id,
|
||||
implementationName,
|
||||
name,
|
||||
required,
|
||||
negate
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<Card
|
||||
className={styles.customFormat}
|
||||
overlayContent={true}
|
||||
onPress={this.onEditSpecificationPress}
|
||||
>
|
||||
<div className={styles.nameContainer}>
|
||||
<div className={styles.name}>
|
||||
{name}
|
||||
</div>
|
||||
|
||||
<IconButton
|
||||
className={styles.cloneButton}
|
||||
title="Clone Format Tag"
|
||||
name={icons.CLONE}
|
||||
onPress={this.onCloneSpecificationPress}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className={styles.labels}>
|
||||
<Label kind={kinds.DEFAULT}>
|
||||
{implementationName}
|
||||
</Label>
|
||||
|
||||
{
|
||||
negate &&
|
||||
<Label kind={kinds.INVERSE}>
|
||||
{'Negated'}
|
||||
</Label>
|
||||
}
|
||||
|
||||
{
|
||||
required &&
|
||||
<Label kind={kinds.DANGER}>
|
||||
{'Required'}
|
||||
</Label>
|
||||
}
|
||||
</div>
|
||||
|
||||
<EditSpecificationModalConnector
|
||||
id={id}
|
||||
isOpen={this.state.isEditSpecificationModalOpen}
|
||||
onModalClose={this.onEditSpecificationModalClose}
|
||||
onDeleteSpecificationPress={this.onDeleteSpecificationPress}
|
||||
/>
|
||||
|
||||
<ConfirmModal
|
||||
isOpen={this.state.isDeleteSpecificationModalOpen}
|
||||
kind={kinds.DANGER}
|
||||
title="Delete Custom Format"
|
||||
message={
|
||||
<div>
|
||||
<div>
|
||||
Are you sure you want to delete format tag '{name}'?
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
confirmLabel="Delete"
|
||||
onConfirm={this.onConfirmDeleteSpecification}
|
||||
onCancel={this.onDeleteSpecificationModalClose}
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Specification.propTypes = {
|
||||
id: PropTypes.number.isRequired,
|
||||
implementation: PropTypes.string.isRequired,
|
||||
implementationName: PropTypes.string.isRequired,
|
||||
name: PropTypes.string.isRequired,
|
||||
negate: PropTypes.bool.isRequired,
|
||||
required: PropTypes.bool.isRequired,
|
||||
fields: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
onConfirmDeleteSpecification: PropTypes.func.isRequired,
|
||||
onCloneSpecificationPress: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default Specification;
|
@ -0,0 +1,184 @@
|
||||
import { createAction } from 'redux-actions';
|
||||
import { batchActions } from 'redux-batched-actions';
|
||||
import { createThunk } from 'Store/thunks';
|
||||
import getSectionState from 'Utilities/State/getSectionState';
|
||||
import updateSectionState from 'Utilities/State/updateSectionState';
|
||||
import getNextId from 'Utilities/State/getNextId';
|
||||
import selectProviderSchema from 'Utilities/State/selectProviderSchema';
|
||||
import getProviderState from 'Utilities/State/getProviderState';
|
||||
import createSetSettingValueReducer from 'Store/Actions/Creators/Reducers/createSetSettingValueReducer';
|
||||
import createSetProviderFieldValueReducer from 'Store/Actions/Creators/Reducers/createSetProviderFieldValueReducer';
|
||||
import createClearReducer from 'Store/Actions/Creators/Reducers/createClearReducer';
|
||||
import createFetchSchemaHandler from 'Store/Actions/Creators/createFetchSchemaHandler';
|
||||
import { set, update, updateItem, removeItem } from '../baseActions';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
const section = 'settings.customFormatSpecifications';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_CUSTOM_FORMAT_SPECIFICATIONS = 'settings/customFormatSpecifications/fetchCustomFormatSpecifications';
|
||||
export const FETCH_CUSTOM_FORMAT_SPECIFICATION_SCHEMA = 'settings/customFormatSpecifications/fetchCustomFormatSpecificationSchema';
|
||||
export const SELECT_CUSTOM_FORMAT_SPECIFICATION_SCHEMA = 'settings/customFormatSpecifications/selectCustomFormatSpecificationSchema';
|
||||
export const SET_CUSTOM_FORMAT_SPECIFICATION_VALUE = 'settings/customFormatSpecifications/setCustomFormatSpecificationValue';
|
||||
export const SET_CUSTOM_FORMAT_SPECIFICATION_FIELD_VALUE = 'settings/customFormatSpecifications/setCustomFormatSpecificationFieldValue';
|
||||
export const SAVE_CUSTOM_FORMAT_SPECIFICATION = 'settings/customFormatSpecifications/saveCustomFormatSpecification';
|
||||
export const DELETE_CUSTOM_FORMAT_SPECIFICATION = 'settings/customFormatSpecifications/deleteCustomFormatSpecification';
|
||||
export const CLONE_CUSTOM_FORMAT_SPECIFICATION = 'settings/customFormatSpecifications/cloneCustomFormatSpecification';
|
||||
export const CLEAR_CUSTOM_FORMAT_SPECIFICATIONS = 'settings/customFormatSpecifications/clearCustomFormatSpecifications';
|
||||
export const CLEAR_CUSTOM_FORMAT_SPECIFICATION_PENDING = 'settings/customFormatSpecifications/clearCustomFormatSpecificationPending';
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchCustomFormatSpecifications = createThunk(FETCH_CUSTOM_FORMAT_SPECIFICATIONS);
|
||||
export const fetchCustomFormatSpecificationSchema = createThunk(FETCH_CUSTOM_FORMAT_SPECIFICATION_SCHEMA);
|
||||
export const selectCustomFormatSpecificationSchema = createAction(SELECT_CUSTOM_FORMAT_SPECIFICATION_SCHEMA);
|
||||
|
||||
export const saveCustomFormatSpecification = createThunk(SAVE_CUSTOM_FORMAT_SPECIFICATION);
|
||||
export const deleteCustomFormatSpecification = createThunk(DELETE_CUSTOM_FORMAT_SPECIFICATION);
|
||||
|
||||
export const setCustomFormatSpecificationValue = createAction(SET_CUSTOM_FORMAT_SPECIFICATION_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
export const setCustomFormatSpecificationFieldValue = createAction(SET_CUSTOM_FORMAT_SPECIFICATION_FIELD_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
export const cloneCustomFormatSpecification = createAction(CLONE_CUSTOM_FORMAT_SPECIFICATION);
|
||||
|
||||
export const clearCustomFormatSpecification = createAction(CLEAR_CUSTOM_FORMAT_SPECIFICATIONS);
|
||||
|
||||
export const clearCustomFormatSpecificationPending = createThunk(CLEAR_CUSTOM_FORMAT_SPECIFICATION_PENDING);
|
||||
|
||||
//
|
||||
// Details
|
||||
|
||||
export default {
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
defaultState: {
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
isSchemaFetching: false,
|
||||
isSchemaPopulated: false,
|
||||
schemaError: null,
|
||||
schema: [],
|
||||
selectedSchema: {},
|
||||
isSaving: false,
|
||||
saveError: null,
|
||||
items: [],
|
||||
pendingChanges: {}
|
||||
},
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
actionHandlers: {
|
||||
[FETCH_CUSTOM_FORMAT_SPECIFICATION_SCHEMA]: createFetchSchemaHandler(section, '/customformat/schema'),
|
||||
|
||||
[FETCH_CUSTOM_FORMAT_SPECIFICATIONS]: (getState, payload, dispatch) => {
|
||||
let tags = [];
|
||||
if (payload.id) {
|
||||
const cfState = getSectionState(getState(), 'settings.customFormats', true);
|
||||
const cf = cfState.items[cfState.itemMap[payload.id]];
|
||||
tags = cf.specifications.map((tag, i) => {
|
||||
return {
|
||||
id: i + 1,
|
||||
...tag
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
dispatch(batchActions([
|
||||
update({ section, data: tags }),
|
||||
set({
|
||||
section,
|
||||
isPopulated: true
|
||||
})
|
||||
]));
|
||||
},
|
||||
|
||||
[SAVE_CUSTOM_FORMAT_SPECIFICATION]: (getState, payload, dispatch) => {
|
||||
const {
|
||||
id,
|
||||
...otherPayload
|
||||
} = payload;
|
||||
|
||||
const saveData = getProviderState({ id, ...otherPayload }, getState, section, false);
|
||||
|
||||
// we have to set id since not actually posting to server yet
|
||||
if (!saveData.id) {
|
||||
saveData.id = getNextId(getState().settings.customFormatSpecifications.items);
|
||||
}
|
||||
|
||||
dispatch(batchActions([
|
||||
updateItem({ section, ...saveData }),
|
||||
set({
|
||||
section,
|
||||
pendingChanges: {}
|
||||
})
|
||||
]));
|
||||
},
|
||||
|
||||
[DELETE_CUSTOM_FORMAT_SPECIFICATION]: (getState, payload, dispatch) => {
|
||||
const id = payload.id;
|
||||
return dispatch(removeItem({ section, id }));
|
||||
},
|
||||
|
||||
[CLEAR_CUSTOM_FORMAT_SPECIFICATION_PENDING]: (getState, payload, dispatch) => {
|
||||
return dispatch(set({
|
||||
section,
|
||||
pendingChanges: {}
|
||||
}));
|
||||
}
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_CUSTOM_FORMAT_SPECIFICATION_VALUE]: createSetSettingValueReducer(section),
|
||||
[SET_CUSTOM_FORMAT_SPECIFICATION_FIELD_VALUE]: createSetProviderFieldValueReducer(section),
|
||||
|
||||
[SELECT_CUSTOM_FORMAT_SPECIFICATION_SCHEMA]: (state, { payload }) => {
|
||||
return selectProviderSchema(state, section, payload, (selectedSchema) => {
|
||||
return selectedSchema;
|
||||
});
|
||||
},
|
||||
|
||||
[CLONE_CUSTOM_FORMAT_SPECIFICATION]: function(state, { payload }) {
|
||||
const id = payload.id;
|
||||
const newState = getSectionState(state, section);
|
||||
const items = newState.items;
|
||||
const item = items.find((i) => i.id === id);
|
||||
const newId = getNextId(newState.items);
|
||||
const newItem = {
|
||||
...item,
|
||||
id: newId,
|
||||
name: `${item.name} - Copy`
|
||||
};
|
||||
newState.items = [...items, newItem];
|
||||
newState.itemMap[newId] = newState.items.length - 1;
|
||||
|
||||
return updateSectionState(state, section, newState);
|
||||
},
|
||||
|
||||
[CLEAR_CUSTOM_FORMAT_SPECIFICATIONS]: createClearReducer(section, {
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
items: []
|
||||
})
|
||||
}
|
||||
};
|
@ -0,0 +1,5 @@
|
||||
function getNextId(items) {
|
||||
return items.reduce((id, x) => Math.max(id, x.id), 1) + 1;
|
||||
}
|
||||
|
||||
export default getNextId;
|
@ -0,0 +1,67 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentValidation;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace NzbDrone.Api.CustomFormats
|
||||
{
|
||||
public class CustomFormatModule : RadarrRestModule<CustomFormatResource>
|
||||
{
|
||||
private readonly ICustomFormatService _formatService;
|
||||
|
||||
public CustomFormatModule(ICustomFormatService formatService)
|
||||
{
|
||||
_formatService = formatService;
|
||||
|
||||
SharedValidator.RuleFor(c => c.Name).NotEmpty();
|
||||
SharedValidator.RuleFor(c => c.Name)
|
||||
.Must((v, c) => !_formatService.All().Any(f => f.Name == c && f.Id != v.Id)).WithMessage("Must be unique.");
|
||||
SharedValidator.RuleFor(c => c.Specifications).NotEmpty();
|
||||
|
||||
GetResourceAll = GetAll;
|
||||
|
||||
GetResourceById = GetById;
|
||||
|
||||
UpdateResource = Update;
|
||||
|
||||
CreateResource = Create;
|
||||
|
||||
DeleteResource = DeleteFormat;
|
||||
|
||||
Get("schema", x => GetTemplates());
|
||||
}
|
||||
|
||||
private int Create(CustomFormatResource customFormatResource)
|
||||
{
|
||||
var model = customFormatResource.ToModel();
|
||||
return _formatService.Insert(model).Id;
|
||||
}
|
||||
|
||||
private void Update(CustomFormatResource resource)
|
||||
{
|
||||
var model = resource.ToModel();
|
||||
_formatService.Update(model);
|
||||
}
|
||||
|
||||
private CustomFormatResource GetById(int id)
|
||||
{
|
||||
return _formatService.GetById(id).ToResource();
|
||||
}
|
||||
|
||||
private List<CustomFormatResource> GetAll()
|
||||
{
|
||||
return _formatService.All().ToResource();
|
||||
}
|
||||
|
||||
private void DeleteFormat(int id)
|
||||
{
|
||||
_formatService.Delete(id);
|
||||
}
|
||||
|
||||
private object GetTemplates()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,137 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentValidation;
|
||||
using Nancy;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.Parser;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace NzbDrone.Api.Qualities
|
||||
{
|
||||
public class CustomFormatModule : RadarrRestModule<CustomFormatResource>
|
||||
{
|
||||
private readonly ICustomFormatService _formatService;
|
||||
private readonly ICustomFormatCalculationService _formatCalculator;
|
||||
private readonly IParsingService _parsingService;
|
||||
|
||||
public CustomFormatModule(ICustomFormatService formatService,
|
||||
ICustomFormatCalculationService formatCalculator,
|
||||
IParsingService parsingService)
|
||||
{
|
||||
_formatService = formatService;
|
||||
_formatCalculator = formatCalculator;
|
||||
_parsingService = parsingService;
|
||||
|
||||
SharedValidator.RuleFor(c => c.Name).NotEmpty();
|
||||
SharedValidator.RuleFor(c => c.Name)
|
||||
.Must((v, c) => !_formatService.All().Any(f => f.Name == c && f.Id != v.Id)).WithMessage("Must be unique.");
|
||||
SharedValidator.RuleFor(c => c.FormatTags).SetValidator(new FormatTagValidator());
|
||||
SharedValidator.RuleFor(c => c.FormatTags).Must((v, c) =>
|
||||
{
|
||||
var allFormats = _formatService.All();
|
||||
return !allFormats.Any(f =>
|
||||
{
|
||||
var allTags = f.FormatTags.Select(t => t.Raw.ToLower());
|
||||
var allNewTags = c.Select(t => t.ToLower());
|
||||
var enumerable = allTags.ToList();
|
||||
var newTags = allNewTags.ToList();
|
||||
return enumerable.All(newTags.Contains) && f.Id != v.Id && enumerable.Count() == newTags.Count();
|
||||
});
|
||||
})
|
||||
.WithMessage("Should be unique.");
|
||||
|
||||
GetResourceAll = GetAll;
|
||||
|
||||
GetResourceById = GetById;
|
||||
|
||||
UpdateResource = Update;
|
||||
|
||||
CreateResource = Create;
|
||||
|
||||
DeleteResource = DeleteFormat;
|
||||
|
||||
Get("/test", x => Test());
|
||||
|
||||
Post("/test", x => TestWithNewModel());
|
||||
|
||||
Get("schema", x => GetTemplates());
|
||||
}
|
||||
|
||||
private int Create(CustomFormatResource customFormatResource)
|
||||
{
|
||||
var model = customFormatResource.ToModel();
|
||||
return _formatService.Insert(model).Id;
|
||||
}
|
||||
|
||||
private void Update(CustomFormatResource resource)
|
||||
{
|
||||
var model = resource.ToModel();
|
||||
_formatService.Update(model);
|
||||
}
|
||||
|
||||
private CustomFormatResource GetById(int id)
|
||||
{
|
||||
return _formatService.GetById(id).ToResource();
|
||||
}
|
||||
|
||||
private List<CustomFormatResource> GetAll()
|
||||
{
|
||||
return _formatService.All().ToResource();
|
||||
}
|
||||
|
||||
private void DeleteFormat(int id)
|
||||
{
|
||||
_formatService.Delete(id);
|
||||
}
|
||||
|
||||
private object GetTemplates()
|
||||
{
|
||||
return CustomFormatService.Templates.SelectMany(t =>
|
||||
{
|
||||
return t.Value.Select(m =>
|
||||
{
|
||||
var r = m.ToResource();
|
||||
r.Simplicity = t.Key;
|
||||
return r;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private CustomFormatTestResource Test()
|
||||
{
|
||||
var parsed = _parsingService.ParseMovieInfo((string)Request.Query.title, new List<object>());
|
||||
if (parsed == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CustomFormatTestResource
|
||||
{
|
||||
Matches = _formatCalculator.MatchFormatTags(parsed).ToResource(),
|
||||
MatchedFormats = _formatCalculator.ParseCustomFormat(parsed).ToResource()
|
||||
};
|
||||
}
|
||||
|
||||
private CustomFormatTestResource TestWithNewModel()
|
||||
{
|
||||
var queryTitle = (string)Request.Query.title;
|
||||
|
||||
var resource = ReadResourceFromRequest();
|
||||
|
||||
var model = resource.ToModel();
|
||||
model.Name = model.Name += " (New)";
|
||||
|
||||
var parsed = _parsingService.ParseMovieInfo(queryTitle, new List<object> { model });
|
||||
if (parsed == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CustomFormatTestResource
|
||||
{
|
||||
Matches = _formatCalculator.MatchFormatTags(parsed).ToResource(),
|
||||
MatchedFormats = _formatCalculator.ParseCustomFormat(parsed).ToResource()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.CustomFormats
|
||||
{
|
||||
[TestFixture]
|
||||
public class QualityTagFixture : CoreTest
|
||||
{
|
||||
[TestCase("R_1080", TagType.Resolution, Resolution.R1080p)]
|
||||
[TestCase("R_720", TagType.Resolution, Resolution.R720p)]
|
||||
[TestCase("R_576", TagType.Resolution, Resolution.R576p)]
|
||||
[TestCase("R_480", TagType.Resolution, Resolution.R480p)]
|
||||
[TestCase("R_2160", TagType.Resolution, Resolution.R2160p)]
|
||||
[TestCase("S_BLURAY", TagType.Source, Source.BLURAY)]
|
||||
[TestCase("s_tv", TagType.Source, Source.TV)]
|
||||
[TestCase("s_workPRINT", TagType.Source, Source.WORKPRINT)]
|
||||
[TestCase("s_Dvd", TagType.Source, Source.DVD)]
|
||||
[TestCase("S_WEBdL", TagType.Source, Source.WEBDL)]
|
||||
[TestCase("S_CAM", TagType.Source, Source.CAM)]
|
||||
|
||||
// [TestCase("L_English", TagType.Language, Language.English)]
|
||||
// [TestCase("L_Italian", TagType.Language, Language.Italian)]
|
||||
// [TestCase("L_iTa", TagType.Language, Language.Italian)]
|
||||
// [TestCase("L_germaN", TagType.Language, Language.German)]
|
||||
[TestCase("E_Director", TagType.Edition, "director")]
|
||||
[TestCase("E_RX_Director('?s)?", TagType.Edition, "director('?s)?", TagModifier.Regex)]
|
||||
[TestCase("E_RXN_Director('?s)?", TagType.Edition, "director('?s)?", TagModifier.Regex, TagModifier.Not)]
|
||||
[TestCase("E_RXNRQ_Director('?s)?", TagType.Edition, "director('?s)?", TagModifier.Regex, TagModifier.Not, TagModifier.AbsolutelyRequired)]
|
||||
[TestCase("C_Surround", TagType.Custom, "surround")]
|
||||
[TestCase("C_RQ_Surround", TagType.Custom, "surround", TagModifier.AbsolutelyRequired)]
|
||||
[TestCase("C_RQN_Surround", TagType.Custom, "surround", TagModifier.AbsolutelyRequired, TagModifier.Not)]
|
||||
[TestCase("C_RQNRX_Surround|(5|7)(\\.1)?", TagType.Custom, "surround|(5|7)(\\.1)?", TagModifier.AbsolutelyRequired, TagModifier.Not, TagModifier.Regex)]
|
||||
[TestCase("G_10<>20", TagType.Size, new[] { 10737418240L, 21474836480L })]
|
||||
[TestCase("G_15.55<>20", TagType.Size, new[] { 16696685363L, 21474836480L })]
|
||||
[TestCase("G_15.55<>25.1908754", TagType.Size, new[] { 16696685363L, 27048496500L })]
|
||||
[TestCase("R__1080", TagType.Resolution, Resolution.R1080p)]
|
||||
public void should_parse_tag_from_string(string raw, TagType type, object value, params TagModifier[] modifiers)
|
||||
{
|
||||
var parsed = new FormatTag(raw);
|
||||
TagModifier modifier = 0;
|
||||
foreach (var m in modifiers)
|
||||
{
|
||||
modifier |= m;
|
||||
}
|
||||
|
||||
parsed.TagType.Should().Be(type);
|
||||
if (value is long[])
|
||||
{
|
||||
value = (((long[])value)[0], ((long[])value)[1]);
|
||||
}
|
||||
|
||||
if ((parsed.Value as Regex) != null)
|
||||
{
|
||||
(parsed.Value as Regex).ToString().Should().Be(value as string);
|
||||
}
|
||||
else
|
||||
{
|
||||
parsed.Value.Should().Be(value);
|
||||
}
|
||||
|
||||
parsed.TagModifier.Should().Be(modifier);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Dapper;
|
||||
using FluentAssertions;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.Datastore.Migration;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
{
|
||||
[TestFixture]
|
||||
public class custom_format_rework_parserFixture : CoreTest<custom_format_rework>
|
||||
{
|
||||
[TestCase(@"C_RX_(x|h)\.?264", "ReleaseTitleSpecification", false, false, @"(x|h)\.?264")]
|
||||
[TestCase(@"C_(hello)", "ReleaseTitleSpecification", false, false, @"\(hello\)")]
|
||||
[TestCase("C_Surround", "ReleaseTitleSpecification", false, false, "surround")]
|
||||
[TestCase("C_RQ_Surround", "ReleaseTitleSpecification", true, false, "surround")]
|
||||
[TestCase("C_RQN_Surround", "ReleaseTitleSpecification", true, true, "surround")]
|
||||
[TestCase("C_RQNRX_Surround|(5|7)(\\.1)?", "ReleaseTitleSpecification", true, true, "surround|(5|7)(\\.1)?")]
|
||||
[TestCase("R_1080", "ResolutionSpecification", false, false, (int)Resolution.R1080p)]
|
||||
[TestCase("R__1080", "ResolutionSpecification", false, false, (int)Resolution.R1080p)]
|
||||
[TestCase("R_720", "ResolutionSpecification", false, false, (int)Resolution.R720p)]
|
||||
[TestCase("R_576", "ResolutionSpecification", false, false, (int)Resolution.R576p)]
|
||||
[TestCase("R_480", "ResolutionSpecification", false, false, (int)Resolution.R480p)]
|
||||
[TestCase("R_2160", "ResolutionSpecification", false, false, (int)Resolution.R2160p)]
|
||||
[TestCase("S_BLURAY", "SourceSpecification", false, false, (int)Source.BLURAY)]
|
||||
[TestCase("s_tv", "SourceSpecification", false, false, (int)Source.TV)]
|
||||
[TestCase("s_workPRINT", "SourceSpecification", false, false, (int)Source.WORKPRINT)]
|
||||
[TestCase("s_Dvd", "SourceSpecification", false, false, (int)Source.DVD)]
|
||||
[TestCase("S_WEBdL", "SourceSpecification", false, false, (int)Source.WEBDL)]
|
||||
[TestCase("S_CAM", "SourceSpecification", false, false, (int)Source.CAM)]
|
||||
[TestCase("L_English", "LanguageSpecification", false, false, 1)]
|
||||
[TestCase("L_Italian", "LanguageSpecification", false, false, 5)]
|
||||
[TestCase("L_iTa", "LanguageSpecification", false, false, 5)]
|
||||
[TestCase("L_germaN", "LanguageSpecification", false, false, 4)]
|
||||
[TestCase("E_Director", "EditionSpecification", false, false, "director")]
|
||||
[TestCase("E_RX_Director('?s)?", "EditionSpecification", false, false, "director(\u0027?s)?")]
|
||||
[TestCase("E_RXN_Director('?s)?", "EditionSpecification", false, true, "director(\u0027?s)?")]
|
||||
[TestCase("E_RXNRQ_Director('?s)?", "EditionSpecification", true, true, "director(\u0027?s)?")]
|
||||
public void should_convert_custom_format(string raw, string specType, bool required, bool negated, object value)
|
||||
{
|
||||
var format = Subject.ParseFormatTag(raw);
|
||||
format.Negate.Should().Be(negated);
|
||||
format.Required.Should().Be(required);
|
||||
|
||||
format.ToJson().Should().Contain(JsonConvert.ToString(value));
|
||||
}
|
||||
|
||||
[TestCase("G_10<>20", "SizeSpecification", 10, 20)]
|
||||
[TestCase("G_15.55<>20", "SizeSpecification", 15.55, 20)]
|
||||
[TestCase("G_15.55<>25.1908754", "SizeSpecification", 15.55, 25.1908754)]
|
||||
public void should_convert_size_cf(string raw, string specType, double min, double max)
|
||||
{
|
||||
var format = Subject.ParseFormatTag(raw) as SizeSpecification;
|
||||
format.Negate.Should().Be(false);
|
||||
format.Required.Should().Be(false);
|
||||
format.Min.Should().Be(min);
|
||||
format.Max.Should().Be(max);
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class custom_format_reworkFixture : MigrationTest<custom_format_rework>
|
||||
{
|
||||
[Test]
|
||||
public void should_convert_custom_format_row_with_one_spec()
|
||||
{
|
||||
var db = WithDapperMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("CustomFormats").Row(new
|
||||
{
|
||||
Id = 1,
|
||||
Name = "Test",
|
||||
FormatTags = new List<string> { @"C_(hello)" }.ToJson()
|
||||
});
|
||||
});
|
||||
|
||||
var json = db.Query<string>("SELECT Specifications FROM CustomFormats").First();
|
||||
|
||||
ValidateFormatTag(json, "ReleaseTitleSpecification", false, false);
|
||||
json.Should().Contain($"\"name\": \"Test\"");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_convert_custom_format_row_with_two_specs()
|
||||
{
|
||||
var db = WithDapperMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("CustomFormats").Row(new
|
||||
{
|
||||
Id = 1,
|
||||
Name = "Test",
|
||||
FormatTags = new List<string> { @"C_(hello)", "E_Director" }.ToJson()
|
||||
});
|
||||
});
|
||||
|
||||
var json = db.Query<string>("SELECT Specifications FROM CustomFormats").First();
|
||||
|
||||
ValidateFormatTag(json, "ReleaseTitleSpecification", false, false);
|
||||
ValidateFormatTag(json, "EditionSpecification", false, false);
|
||||
json.Should().Contain($"\"name\": \"Release Title 1\"");
|
||||
json.Should().Contain($"\"name\": \"Edition 1\"");
|
||||
}
|
||||
|
||||
private void ValidateFormatTag(string json, string type, bool required, bool negated)
|
||||
{
|
||||
json.Should().Contain($"\"type\": \"{type}\"");
|
||||
json.Should().Contain($"\"required\": {required.ToString().ToLower()}");
|
||||
json.Should().Contain($"\"negate\": {negated.ToString().ToLower()}");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.Annotations
|
||||
{
|
||||
public interface ISelectOptionsConverter
|
||||
{
|
||||
List<SelectOption> GetSelectOptions();
|
||||
}
|
||||
}
|
@ -1,313 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
namespace NzbDrone.Core.CustomFormats
|
||||
{
|
||||
public class FormatTag
|
||||
{
|
||||
public static Regex QualityTagRegex = new Regex(@"^(?<type>R|S|M|E|L|C|I|G)(_((?<m_r>RX)|(?<m_re>RQ)|(?<m_n>N)){0,3})?_(?<value>.*)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public static Regex SizeTagRegex = new Regex(@"(?<min>\d+(\.\d+)?)\s*<>\s*(?<max>\d+(\.\d+)?)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
// This function is needed for json deserialization to work.
|
||||
public FormatTag()
|
||||
{
|
||||
}
|
||||
|
||||
public FormatTag(string raw)
|
||||
{
|
||||
Raw = raw;
|
||||
|
||||
var match = QualityTagRegex.Match(raw);
|
||||
if (!match.Success)
|
||||
{
|
||||
throw new ArgumentException("Quality Tag is not in the correct format!");
|
||||
}
|
||||
|
||||
ParseFormatTagString(match);
|
||||
}
|
||||
|
||||
public string Raw { get; set; }
|
||||
public TagType TagType { get; set; }
|
||||
public TagModifier TagModifier { get; set; }
|
||||
public object Value { get; set; }
|
||||
|
||||
public bool DoesItMatch(ParsedMovieInfo movieInfo)
|
||||
{
|
||||
var match = DoesItMatchWithoutMods(movieInfo);
|
||||
if (TagModifier.HasFlag(TagModifier.Not))
|
||||
{
|
||||
match = !match;
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
private bool MatchString(string compared)
|
||||
{
|
||||
if (compared == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TagModifier.HasFlag(TagModifier.Regex))
|
||||
{
|
||||
var regexValue = (Regex)Value;
|
||||
return regexValue.IsMatch(compared);
|
||||
}
|
||||
else
|
||||
{
|
||||
var stringValue = (string)Value;
|
||||
return compared.ToLower().Contains(stringValue.Replace(" ", string.Empty).ToLower());
|
||||
}
|
||||
}
|
||||
|
||||
private bool DoesItMatchWithoutMods(ParsedMovieInfo movieInfo)
|
||||
{
|
||||
if (movieInfo == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var filename = (string)movieInfo?.ExtraInfo?.GetValueOrDefault("Filename");
|
||||
|
||||
switch (TagType)
|
||||
{
|
||||
case TagType.Edition:
|
||||
return MatchString(movieInfo.Edition);
|
||||
case TagType.Custom:
|
||||
return MatchString(movieInfo.SimpleReleaseTitle) || MatchString(filename);
|
||||
case TagType.Language:
|
||||
return movieInfo?.Languages?.Contains((Language)Value) ?? false;
|
||||
case TagType.Resolution:
|
||||
return (movieInfo?.Quality?.Quality?.Resolution ?? (int)Resolution.Unknown) == (int)(Resolution)Value;
|
||||
case TagType.Modifier:
|
||||
return (movieInfo?.Quality?.Quality?.Modifier ?? (int)Modifier.NONE) == (Modifier)Value;
|
||||
case TagType.Source:
|
||||
return (movieInfo?.Quality?.Quality?.Source ?? (int)Source.UNKNOWN) == (Source)Value;
|
||||
case TagType.Size:
|
||||
var size = (movieInfo?.ExtraInfo?.GetValueOrDefault("Size", 0.0) as long?) ?? 0;
|
||||
var tuple = Value as (long, long)? ?? (0, 0);
|
||||
return size > tuple.Item1 && size < tuple.Item2;
|
||||
case TagType.Indexer:
|
||||
#if !LIBRARY
|
||||
var flags = movieInfo?.ExtraInfo?.GetValueOrDefault("IndexerFlags") as IndexerFlags?;
|
||||
return flags?.HasFlag((IndexerFlags)Value) == true;
|
||||
#endif
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseTagModifier(Match match)
|
||||
{
|
||||
if (match.Groups["m_re"].Success)
|
||||
{
|
||||
TagModifier |= TagModifier.AbsolutelyRequired;
|
||||
}
|
||||
|
||||
if (match.Groups["m_r"].Success)
|
||||
{
|
||||
TagModifier |= TagModifier.Regex;
|
||||
}
|
||||
|
||||
if (match.Groups["m_n"].Success)
|
||||
{
|
||||
TagModifier |= TagModifier.Not;
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseResolutionType(string value)
|
||||
{
|
||||
TagType = TagType.Resolution;
|
||||
switch (value)
|
||||
{
|
||||
case "2160":
|
||||
Value = Resolution.R2160p;
|
||||
break;
|
||||
case "1080":
|
||||
Value = Resolution.R1080p;
|
||||
break;
|
||||
case "720":
|
||||
Value = Resolution.R720p;
|
||||
break;
|
||||
case "576":
|
||||
Value = Resolution.R576p;
|
||||
break;
|
||||
case "480":
|
||||
Value = Resolution.R480p;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseSourceType(string value)
|
||||
{
|
||||
TagType = TagType.Source;
|
||||
switch (value)
|
||||
{
|
||||
case "cam":
|
||||
Value = Source.CAM;
|
||||
break;
|
||||
case "telesync":
|
||||
Value = Source.TELESYNC;
|
||||
break;
|
||||
case "telecine":
|
||||
Value = Source.TELECINE;
|
||||
break;
|
||||
case "workprint":
|
||||
Value = Source.WORKPRINT;
|
||||
break;
|
||||
case "dvd":
|
||||
Value = Source.DVD;
|
||||
break;
|
||||
case "tv":
|
||||
Value = Source.TV;
|
||||
break;
|
||||
case "webdl":
|
||||
Value = Source.WEBDL;
|
||||
break;
|
||||
case "bluray":
|
||||
Value = Source.BLURAY;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseModifierType(string value)
|
||||
{
|
||||
TagType = TagType.Modifier;
|
||||
switch (value)
|
||||
{
|
||||
case "regional":
|
||||
Value = Modifier.REGIONAL;
|
||||
break;
|
||||
case "screener":
|
||||
Value = Modifier.SCREENER;
|
||||
break;
|
||||
case "rawhd":
|
||||
Value = Modifier.RAWHD;
|
||||
break;
|
||||
case "brdisk":
|
||||
Value = Modifier.BRDISK;
|
||||
break;
|
||||
case "remux":
|
||||
Value = Modifier.REMUX;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseIndexerFlagType(string value)
|
||||
{
|
||||
TagType = TagType.Indexer;
|
||||
var flagValues = Enum.GetValues(typeof(IndexerFlags));
|
||||
|
||||
foreach (IndexerFlags flagValue in flagValues)
|
||||
{
|
||||
var flagString = flagValue.ToString();
|
||||
if (flagString.ToLower().Replace("_", string.Empty) != value.ToLower().Replace("_", string.Empty))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Value = flagValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseSizeType(string value)
|
||||
{
|
||||
TagType = TagType.Size;
|
||||
var matches = SizeTagRegex.Match(value);
|
||||
var min = double.Parse(matches.Groups["min"].Value, CultureInfo.InvariantCulture);
|
||||
var max = double.Parse(matches.Groups["max"].Value, CultureInfo.InvariantCulture);
|
||||
Value = (min.Gigabytes(), max.Gigabytes());
|
||||
}
|
||||
|
||||
private void ParseString(string value)
|
||||
{
|
||||
if (TagModifier.HasFlag(TagModifier.Regex))
|
||||
{
|
||||
Value = new Regex(value, RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
}
|
||||
else
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseFormatTagString(Match match)
|
||||
{
|
||||
ParseTagModifier(match);
|
||||
|
||||
var type = match.Groups["type"].Value.ToLower();
|
||||
var value = match.Groups["value"].Value.ToLower();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case "r":
|
||||
ParseResolutionType(value);
|
||||
break;
|
||||
case "s":
|
||||
ParseSourceType(value);
|
||||
break;
|
||||
case "m":
|
||||
ParseModifierType(value);
|
||||
break;
|
||||
case "e":
|
||||
TagType = TagType.Edition;
|
||||
ParseString(value);
|
||||
break;
|
||||
case "l":
|
||||
TagType = TagType.Language;
|
||||
Value = LanguageParser.ParseLanguages(value).First();
|
||||
break;
|
||||
case "i":
|
||||
#if !LIBRARY
|
||||
ParseIndexerFlagType(value);
|
||||
#endif
|
||||
break;
|
||||
case "g":
|
||||
ParseSizeType(value);
|
||||
break;
|
||||
case "c":
|
||||
default:
|
||||
TagType = TagType.Custom;
|
||||
ParseString(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum TagType
|
||||
{
|
||||
Resolution = 1,
|
||||
Source = 2,
|
||||
Modifier = 4,
|
||||
Edition = 8,
|
||||
Language = 16,
|
||||
Custom = 32,
|
||||
Indexer = 64,
|
||||
Size = 128,
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum TagModifier
|
||||
{
|
||||
Regex = 1,
|
||||
Not = 2, // Do not match
|
||||
AbsolutelyRequired = 4
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Core.CustomFormats
|
||||
{
|
||||
public class FormatTagMatchesGroup
|
||||
{
|
||||
public TagType Type { get; set; }
|
||||
|
||||
public Dictionary<FormatTag, bool> Matches { get; set; }
|
||||
|
||||
public bool DidMatch => !(Matches.Any(m => m.Key.TagModifier.HasFlag(TagModifier.AbsolutelyRequired) && m.Value == false) ||
|
||||
Matches.All(m => m.Value == false));
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Core.CustomFormats
|
||||
{
|
||||
public class SpecificationMatchesGroup
|
||||
{
|
||||
public Dictionary<ICustomFormatSpecification, bool> Matches { get; set; }
|
||||
|
||||
public bool DidMatch => !(Matches.Any(m => m.Key.Required && m.Value == false) ||
|
||||
Matches.All(m => m.Value == false));
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.CustomFormats
|
||||
{
|
||||
public abstract class CustomFormatSpecificationBase : ICustomFormatSpecification
|
||||
{
|
||||
public abstract int Order { get; }
|
||||
public abstract string ImplementationName { get; }
|
||||
|
||||
public virtual string InfoLink => "https://github.com/Radarr/Radarr/wiki/Custom-Formats-Aphrodite";
|
||||
|
||||
public string Name { get; set; }
|
||||
public bool Negate { get; set; }
|
||||
public bool Required { get; set; }
|
||||
|
||||
public ICustomFormatSpecification Clone()
|
||||
{
|
||||
return (ICustomFormatSpecification)MemberwiseClone();
|
||||
}
|
||||
|
||||
public bool IsSatisfiedBy(ParsedMovieInfo movieInfo)
|
||||
{
|
||||
var match = IsSatisfiedByWithoutNegate(movieInfo);
|
||||
if (Negate)
|
||||
{
|
||||
match = !match;
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
protected abstract bool IsSatisfiedByWithoutNegate(ParsedMovieInfo movieInfo);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.CustomFormats
|
||||
{
|
||||
public class EditionSpecification : RegexSpecificationBase
|
||||
{
|
||||
public override int Order => 2;
|
||||
public override string ImplementationName => "Edition";
|
||||
public override string InfoLink => "https://github.com/Radarr/Radarr/wiki/Custom-Formats-Aphrodite#edition";
|
||||
|
||||
protected override bool IsSatisfiedByWithoutNegate(ParsedMovieInfo movieInfo)
|
||||
{
|
||||
return MatchString(movieInfo.Edition);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.CustomFormats
|
||||
{
|
||||
public interface ICustomFormatSpecification
|
||||
{
|
||||
int Order { get; }
|
||||
string InfoLink { get; }
|
||||
string ImplementationName { get; }
|
||||
string Name { get; set; }
|
||||
bool Negate { get; set; }
|
||||
bool Required { get; set; }
|
||||
|
||||
ICustomFormatSpecification Clone();
|
||||
bool IsSatisfiedBy(ParsedMovieInfo movieInfo);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.CustomFormats
|
||||
{
|
||||
public class IndexerFlagSpecification : CustomFormatSpecificationBase
|
||||
{
|
||||
public override int Order => 4;
|
||||
public override string ImplementationName => "Indexer Flag";
|
||||
|
||||
[FieldDefinition(1, Label = "Flag", Type = FieldType.Select, SelectOptions = typeof(IndexerFlags))]
|
||||
public int Value { get; set; }
|
||||
|
||||
protected override bool IsSatisfiedByWithoutNegate(ParsedMovieInfo movieInfo)
|
||||
{
|
||||
var flags = movieInfo?.ExtraInfo?.GetValueOrDefault("IndexerFlags") as IndexerFlags?;
|
||||
return flags?.HasFlag((IndexerFlags)Value) == true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.CustomFormats
|
||||
{
|
||||
public class LanguageSpecification : CustomFormatSpecificationBase
|
||||
{
|
||||
public override int Order => 3;
|
||||
public override string ImplementationName => "Language";
|
||||
|
||||
[FieldDefinition(1, Label = "Language", Type = FieldType.Select, SelectOptions = typeof(LanguageFieldConverter))]
|
||||
public int Value { get; set; }
|
||||
|
||||
protected override bool IsSatisfiedByWithoutNegate(ParsedMovieInfo movieInfo)
|
||||
{
|
||||
return movieInfo?.Languages?.Contains((Language)Value) ?? false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
namespace NzbDrone.Core.CustomFormats
|
||||
{
|
||||
public class QualityModifierSpecification : CustomFormatSpecificationBase
|
||||
{
|
||||
public override int Order => 7;
|
||||
public override string ImplementationName => "Quality Modifier";
|
||||
|
||||
[FieldDefinition(1, Label = "Quality Modifier", Type = FieldType.Select, SelectOptions = typeof(Modifier))]
|
||||
public int Value { get; set; }
|
||||
|
||||
protected override bool IsSatisfiedByWithoutNegate(ParsedMovieInfo movieInfo)
|
||||
{
|
||||
return (movieInfo?.Quality?.Quality?.Modifier ?? (int)Modifier.NONE) == (Modifier)Value;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using NzbDrone.Core.Annotations;
|
||||
|
||||
namespace NzbDrone.Core.CustomFormats
|
||||
{
|
||||
public abstract class RegexSpecificationBase : CustomFormatSpecificationBase
|
||||
{
|
||||
protected Regex _regex;
|
||||
protected string _raw;
|
||||
|
||||
[FieldDefinition(1, Label = "Regular Expression")]
|
||||
public string Value
|
||||
{
|
||||
get => _raw;
|
||||
set
|
||||
{
|
||||
_raw = value;
|
||||
_regex = new Regex(value, RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
protected bool MatchString(string compared)
|
||||
{
|
||||
if (compared == null || _regex == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _regex.IsMatch(compared);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.CustomFormats
|
||||
{
|
||||
public class ReleaseTitleSpecification : RegexSpecificationBase
|
||||
{
|
||||
public override int Order => 1;
|
||||
public override string ImplementationName => "Release Title";
|
||||
public override string InfoLink => "https://github.com/Radarr/Radarr/wiki/Custom-Formats-Aphrodite#release-title";
|
||||
|
||||
protected override bool IsSatisfiedByWithoutNegate(ParsedMovieInfo movieInfo)
|
||||
{
|
||||
var filename = (string)movieInfo?.ExtraInfo?.GetValueOrDefault("Filename");
|
||||
|
||||
return MatchString(movieInfo?.SimpleReleaseTitle) || MatchString(filename);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.CustomFormats
|
||||
{
|
||||
public class ResolutionSpecification : CustomFormatSpecificationBase
|
||||
{
|
||||
public override int Order => 6;
|
||||
public override string ImplementationName => "Resolution";
|
||||
|
||||
[FieldDefinition(1, Label = "Resolution", Type = FieldType.Select, SelectOptions = typeof(Resolution))]
|
||||
public int Value { get; set; }
|
||||
|
||||
protected override bool IsSatisfiedByWithoutNegate(ParsedMovieInfo movieInfo)
|
||||
{
|
||||
return (movieInfo?.Quality?.Quality?.Resolution ?? (int)Resolution.Unknown) == Value;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.CustomFormats
|
||||
{
|
||||
public class SizeSpecification : CustomFormatSpecificationBase
|
||||
{
|
||||
public override int Order => 8;
|
||||
public override string ImplementationName => "Size";
|
||||
|
||||
[FieldDefinition(1, Label = "Minimum Size", Unit = "GB", Type = FieldType.Number)]
|
||||
public double Min { get; set; }
|
||||
|
||||
[FieldDefinition(1, Label = "Maximum Size", Unit = "GB", Type = FieldType.Number)]
|
||||
public double Max { get; set; }
|
||||
|
||||
protected override bool IsSatisfiedByWithoutNegate(ParsedMovieInfo movieInfo)
|
||||
{
|
||||
var size = (movieInfo?.ExtraInfo?.GetValueOrDefault("Size", 0.0) as long?) ?? 0;
|
||||
|
||||
return size > Min.Gigabytes() && size < Max.Gigabytes();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
namespace NzbDrone.Core.CustomFormats
|
||||
{
|
||||
public class SourceSpecification : CustomFormatSpecificationBase
|
||||
{
|
||||
public override int Order => 5;
|
||||
public override string ImplementationName => "Source";
|
||||
|
||||
[FieldDefinition(1, Label = "Source", Type = FieldType.Select, SelectOptions = typeof(Source))]
|
||||
public int Value { get; set; }
|
||||
|
||||
protected override bool IsSatisfiedByWithoutNegate(ParsedMovieInfo movieInfo)
|
||||
{
|
||||
return (movieInfo?.Quality?.Quality?.Source ?? (int)Source.UNKNOWN) == (Source)Value;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,222 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Dapper;
|
||||
using FluentMigrator;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(168)]
|
||||
public class custom_format_rework : NzbDroneMigrationBase
|
||||
{
|
||||
private static readonly Regex QualityTagRegex = new Regex(@"^(?<type>R|S|M|E|L|C|I|G)(_((?<m_r>RX)|(?<m_re>RQ)|(?<m_n>N)){0,3})?_(?<value>.*)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
private static readonly Regex SizeTagRegex = new Regex(@"(?<min>\d+(\.\d+)?)\s*<>\s*(?<max>\d+(\.\d+)?)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Alter.Table("CustomFormats").AddColumn("Specifications").AsString().WithDefaultValue("[]");
|
||||
|
||||
Execute.WithConnection(UpdateCustomFormats);
|
||||
|
||||
Delete.Column("FormatTags").FromTable("CustomFormats");
|
||||
}
|
||||
|
||||
private void UpdateCustomFormats(IDbConnection conn, IDbTransaction tran)
|
||||
{
|
||||
var existing = conn.Query<FormatTag167>("SELECT Id, Name, FormatTags FROM CustomFormats");
|
||||
|
||||
var updated = new List<Specification168>();
|
||||
|
||||
foreach (var row in existing)
|
||||
{
|
||||
var specs = row.FormatTags.Select(ParseFormatTag).ToList();
|
||||
|
||||
// Use format name for spec if only one spec, otherwise use spec type and a digit
|
||||
if (specs.Count == 1)
|
||||
{
|
||||
specs[0].Name = row.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
var groups = specs.GroupBy(x => x.ImplementationName);
|
||||
foreach (var group in groups)
|
||||
{
|
||||
var i = 1;
|
||||
foreach (var spec in group)
|
||||
{
|
||||
spec.Name = $"{spec.ImplementationName} {i}";
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updated.Add(new Specification168
|
||||
{
|
||||
Id = row.Id,
|
||||
Specifications = specs
|
||||
});
|
||||
}
|
||||
|
||||
var updateSql = "UPDATE CustomFormats SET Specifications = @Specifications WHERE Id = @Id";
|
||||
conn.Execute(updateSql, updated, transaction: tran);
|
||||
}
|
||||
|
||||
public ICustomFormatSpecification ParseFormatTag(string raw)
|
||||
{
|
||||
var match = QualityTagRegex.Match(raw);
|
||||
if (!match.Success)
|
||||
{
|
||||
throw new ArgumentException("Quality Tag is not in the correct format!");
|
||||
}
|
||||
|
||||
var result = InitializeSpecification(match);
|
||||
result.Negate = match.Groups["m_n"].Success;
|
||||
result.Required = match.Groups["m_re"].Success;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private ICustomFormatSpecification InitializeSpecification(Match match)
|
||||
{
|
||||
var type = match.Groups["type"].Value.ToLower();
|
||||
var value = match.Groups["value"].Value.ToLower();
|
||||
var isRegex = match.Groups["m_r"].Success;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case "r":
|
||||
return new ResolutionSpecification { Value = (int)ParseResolution(value) };
|
||||
case "s":
|
||||
return new SourceSpecification { Value = (int)ParseSource(value) };
|
||||
case "m":
|
||||
return new QualityModifierSpecification { Value = (int)ParseModifier(value) };
|
||||
case "e":
|
||||
return new EditionSpecification { Value = ParseString(value, isRegex) };
|
||||
case "l":
|
||||
return new LanguageSpecification { Value = (int)LanguageParser.ParseLanguages(value).First() };
|
||||
case "i":
|
||||
return new IndexerFlagSpecification { Value = (int)ParseIndexerFlag(value) };
|
||||
case "g":
|
||||
var minMax = ParseSize(value);
|
||||
return new SizeSpecification { Min = minMax.Item1, Max = minMax.Item2 };
|
||||
case "c":
|
||||
default:
|
||||
return new ReleaseTitleSpecification { Value = ParseString(value, isRegex) };
|
||||
}
|
||||
}
|
||||
|
||||
private Resolution ParseResolution(string value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case "2160":
|
||||
return Resolution.R2160p;
|
||||
case "1080":
|
||||
return Resolution.R1080p;
|
||||
case "720":
|
||||
return Resolution.R720p;
|
||||
case "576":
|
||||
return Resolution.R576p;
|
||||
case "480":
|
||||
return Resolution.R480p;
|
||||
default:
|
||||
return Resolution.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
private Source ParseSource(string value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case "cam":
|
||||
return Source.CAM;
|
||||
case "telesync":
|
||||
return Source.TELESYNC;
|
||||
case "telecine":
|
||||
return Source.TELECINE;
|
||||
case "workprint":
|
||||
return Source.WORKPRINT;
|
||||
case "dvd":
|
||||
return Source.DVD;
|
||||
case "tv":
|
||||
return Source.TV;
|
||||
case "webdl":
|
||||
return Source.WEBDL;
|
||||
case "bluray":
|
||||
return Source.BLURAY;
|
||||
default:
|
||||
return Source.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
private Modifier ParseModifier(string value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case "regional":
|
||||
return Modifier.REGIONAL;
|
||||
case "screener":
|
||||
return Modifier.SCREENER;
|
||||
case "rawhd":
|
||||
return Modifier.RAWHD;
|
||||
case "brdisk":
|
||||
return Modifier.BRDISK;
|
||||
case "remux":
|
||||
return Modifier.REMUX;
|
||||
default:
|
||||
return Modifier.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
private IndexerFlags ParseIndexerFlag(string value)
|
||||
{
|
||||
var flagValues = Enum.GetValues(typeof(IndexerFlags));
|
||||
|
||||
foreach (IndexerFlags flagValue in flagValues)
|
||||
{
|
||||
var flagString = flagValue.ToString();
|
||||
if (flagString.ToLower().Replace("_", string.Empty) != value.ToLower().Replace("_", string.Empty))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
return flagValue;
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
private (double, double) ParseSize(string value)
|
||||
{
|
||||
var matches = SizeTagRegex.Match(value);
|
||||
var min = double.Parse(matches.Groups["min"].Value, CultureInfo.InvariantCulture);
|
||||
var max = double.Parse(matches.Groups["max"].Value, CultureInfo.InvariantCulture);
|
||||
return (min, max);
|
||||
}
|
||||
|
||||
private string ParseString(string value, bool isRegex)
|
||||
{
|
||||
return isRegex ? value : Regex.Escape(value);
|
||||
}
|
||||
|
||||
private class FormatTag167 : ModelBase
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public List<string> FormatTags { get; set; }
|
||||
}
|
||||
|
||||
private class Specification168 : ModelBase
|
||||
{
|
||||
public List<ICustomFormatSpecification> Specifications { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Annotations;
|
||||
|
||||
namespace NzbDrone.Core.Languages
|
||||
{
|
||||
public class LanguageFieldConverter : ISelectOptionsConverter
|
||||
{
|
||||
public List<SelectOption> GetSelectOptions()
|
||||
{
|
||||
return Language.All.ConvertAll(v => new SelectOption { Value = v.Id, Name = v.Name });
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using Radarr.Http.ClientSchema;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
namespace Radarr.Api.V3.CustomFormats
|
||||
{
|
||||
public class CustomFormatSpecificationSchema : RestResource
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Implementation { get; set; }
|
||||
public string ImplementationName { get; set; }
|
||||
public string InfoLink { get; set; }
|
||||
public bool Negate { get; set; }
|
||||
public bool Required { get; set; }
|
||||
public List<Field> Fields { get; set; }
|
||||
public List<CustomFormatSpecificationSchema> Presets { get; set; }
|
||||
}
|
||||
|
||||
public static class CustomFormatSpecificationSchemaMapper
|
||||
{
|
||||
public static CustomFormatSpecificationSchema ToSchema(this ICustomFormatSpecification model)
|
||||
{
|
||||
return new CustomFormatSpecificationSchema
|
||||
{
|
||||
Name = model.Name,
|
||||
Implementation = model.GetType().Name,
|
||||
ImplementationName = model.ImplementationName,
|
||||
InfoLink = model.InfoLink,
|
||||
Negate = model.Negate,
|
||||
Required = model.Required,
|
||||
Fields = SchemaBuilder.ToSchema(model)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
namespace Radarr.Api.V3.CustomFormats
|
||||
{
|
||||
public class CustomFormatMatchResultResource : RestResource
|
||||
{
|
||||
public CustomFormatResource CustomFormat { get; set; }
|
||||
public List<FormatTagGroupMatchesResource> GroupMatches { get; set; }
|
||||
}
|
||||
|
||||
public class FormatTagGroupMatchesResource : RestResource
|
||||
{
|
||||
public string GroupName { get; set; }
|
||||
public IDictionary<string, bool> Matches { get; set; }
|
||||
public bool DidMatch { get; set; }
|
||||
}
|
||||
|
||||
public class CustomFormatTestResource : RestResource
|
||||
{
|
||||
public List<CustomFormatMatchResultResource> Matches { get; set; }
|
||||
public List<CustomFormatResource> MatchedFormats { get; set; }
|
||||
}
|
||||
|
||||
public static class QualityTagMatchResultResourceMapper
|
||||
{
|
||||
public static CustomFormatMatchResultResource ToResource(this CustomFormatMatchResult model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CustomFormatMatchResultResource
|
||||
{
|
||||
CustomFormat = model.CustomFormat.ToResource(),
|
||||
GroupMatches = model.GroupMatches.ToResource()
|
||||
};
|
||||
}
|
||||
|
||||
public static List<CustomFormatMatchResultResource> ToResource(this IList<CustomFormatMatchResult> models)
|
||||
{
|
||||
return models.Select(ToResource).ToList();
|
||||
}
|
||||
|
||||
public static FormatTagGroupMatchesResource ToResource(this FormatTagMatchesGroup model)
|
||||
{
|
||||
return new FormatTagGroupMatchesResource
|
||||
{
|
||||
GroupName = model.Type.ToString(),
|
||||
DidMatch = model.DidMatch,
|
||||
Matches = model.Matches.SelectDictionary(m => m.Key.Raw, m => m.Value)
|
||||
};
|
||||
}
|
||||
|
||||
public static List<FormatTagGroupMatchesResource> ToResource(this IList<FormatTagMatchesGroup> models)
|
||||
{
|
||||
return models.Select(ToResource).ToList();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentValidation.Validators;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
|
||||
namespace Radarr.Api.V3.CustomFormats
|
||||
{
|
||||
public class FormatTagValidator : PropertyValidator
|
||||
{
|
||||
public FormatTagValidator()
|
||||
: base("{ValidationMessage}")
|
||||
{
|
||||
}
|
||||
|
||||
protected override bool IsValid(PropertyValidatorContext context)
|
||||
{
|
||||
if (context.PropertyValue == null)
|
||||
{
|
||||
context.SetMessage("Format Tags cannot be null!");
|
||||
return false;
|
||||
}
|
||||
|
||||
var tags = (IEnumerable<string>)context.PropertyValue.ToString().Split(',');
|
||||
|
||||
var invalidTags = tags.Where(t => !FormatTag.QualityTagRegex.IsMatch(t));
|
||||
|
||||
if (!invalidTags.Any())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var formatMessage =
|
||||
$"Format Tags ({string.Join(", ", invalidTags)}) are in an invalid format! Check the Wiki to learn how they should look.";
|
||||
context.SetMessage(formatMessage);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PropertyValidatorExtensions
|
||||
{
|
||||
public static void SetMessage(this PropertyValidatorContext context, string message, string argument = "ValidationMessage")
|
||||
{
|
||||
context.MessageFormatter.AppendArgument(argument, message);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue