Add Advanced Option for Alternate Metadata Provider Source

pull/94/head
Qstick 7 years ago
parent f460f630c3
commit 0201aa812e

@ -14,7 +14,7 @@ function Metadatas(props) {
return ( return (
<FieldSet <FieldSet
legend="Metadata" legend="Metadata Consumers"
> >
<PageSectionContent <PageSectionContent
errorMessage="Unable to load Metadata" errorMessage="Unable to load Metadata"

@ -0,0 +1,75 @@
import PropTypes from 'prop-types';
import React from 'react';
import { inputTypes, sizes } from 'Helpers/Props';
import LoadingIndicator from 'Components/Loading/LoadingIndicator';
import FieldSet from 'Components/FieldSet';
import Form from 'Components/Form/Form';
import FormGroup from 'Components/Form/FormGroup';
import FormLabel from 'Components/Form/FormLabel';
import FormInputGroup from 'Components/Form/FormInputGroup';
function MetadataProvider(props) {
const {
advancedSettings,
isFetching,
error,
settings,
hasSettings,
onInputChange
} = props;
return (
<div>
{
isFetching &&
<LoadingIndicator />
}
{
!isFetching && error &&
<div>Unable to load Metadata Provider settings</div>
}
{
hasSettings && !isFetching && !error &&
<Form>
{
advancedSettings &&
<FieldSet
legend="Metadata Provider Source"
>
<FormGroup
advancedSettings={advancedSettings}
isAdvanced={true}
>
<FormLabel>Metadata Source</FormLabel>
<FormInputGroup
type={inputTypes.TEXT}
name="metadataSource"
helpText="Alternative Metadata Source (Leave blank for default)"
helpLink="https://github.com/Lidarr/Lidarr/wiki/Metadata-Source"
onChange={onInputChange}
{...settings.metadataSource}
/>
</FormGroup>
</FieldSet>
}
</Form>
}
</div>
);
}
MetadataProvider.propTypes = {
advancedSettings: PropTypes.bool.isRequired,
isFetching: PropTypes.bool.isRequired,
error: PropTypes.object,
settings: PropTypes.object.isRequired,
hasSettings: PropTypes.bool.isRequired,
onInputChange: PropTypes.func.isRequired
};
export default MetadataProvider;

@ -0,0 +1,92 @@
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { createSelector } from 'reselect';
import createSettingsSectionSelector from 'Store/Selectors/createSettingsSectionSelector';
import { setMetadataProviderValue, saveMetadataProvider, fetchMetadataProvider } from 'Store/Actions/settingsActions';
import { clearPendingChanges } from 'Store/Actions/baseActions';
import connectSection from 'Store/connectSection';
import MetadataProvider from './MetadataProvider';
function createMapStateToProps() {
return createSelector(
(state) => state.settings.advancedSettings,
createSettingsSectionSelector(),
(advancedSettings, sectionSettings) => {
return {
advancedSettings,
...sectionSettings
};
}
);
}
const mapDispatchToProps = {
setMetadataProviderValue,
saveMetadataProvider,
fetchMetadataProvider,
clearPendingChanges
};
class MetadataProviderConnector extends Component {
//
// Lifecycle
componentDidMount() {
this.props.fetchMetadataProvider();
}
componentDidUpdate(prevProps) {
if (this.props.hasPendingChanges !== prevProps.hasPendingChanges) {
this.props.onHasPendingChange(this.props.hasPendingChanges);
}
}
componentWillUnmount() {
this.props.clearPendingChanges({ section: this.props.section });
}
//
// Control
save = () => {
this.props.saveMetadataProvider();
}
//
// Listeners
onInputChange = ({ name, value }) => {
this.props.setMetadataProviderValue({ name, value });
}
//
// Render
render() {
return (
<MetadataProvider
onInputChange={this.onInputChange}
{...this.props}
/>
);
}
}
MetadataProviderConnector.propTypes = {
section: PropTypes.string.isRequired,
hasPendingChanges: PropTypes.bool.isRequired,
setMetadataProviderValue: PropTypes.func.isRequired,
saveMetadataProvider: PropTypes.func.isRequired,
fetchMetadataProvider: PropTypes.func.isRequired,
clearPendingChanges: PropTypes.func.isRequired,
onHasPendingChange: PropTypes.func.isRequired
};
export default connectSection(
createMapStateToProps,
mapDispatchToProps,
undefined,
{ withRef: true },
{ section: 'metadataProvider' }
)(MetadataProviderConnector);

@ -1,21 +1,60 @@
import React from 'react'; import React, { Component } from 'react';
import PageContent from 'Components/Page/PageContent'; import PageContent from 'Components/Page/PageContent';
import PageContentBodyConnector from 'Components/Page/PageContentBodyConnector'; import PageContentBodyConnector from 'Components/Page/PageContentBodyConnector';
import SettingsToolbarConnector from 'Settings/SettingsToolbarConnector'; import SettingsToolbarConnector from 'Settings/SettingsToolbarConnector';
import MetadatasConnector from './Metadata/MetadatasConnector'; import MetadatasConnector from './Metadata/MetadatasConnector';
import MetadataProviderConnector from './MetadataProvider/MetadataProviderConnector';
function MetadataSettings() { class MetadataSettings extends Component {
return (
<PageContent title="Metadata Settings"> //
<SettingsToolbarConnector // Lifecycle
showSave={false}
/> constructor(props, context) {
super(props, context);
<PageContentBodyConnector>
<MetadatasConnector /> this.state = {
</PageContentBodyConnector> hasPendingChanges: false
</PageContent> };
); }
//
// Listeners
setMetadataProviderRef = (ref) => {
this._metadataProvider = ref;
}
onHasPendingChange = (hasPendingChanges) => {
this.setState({
hasPendingChanges
});
}
onSavePress = () => {
this._metadataProvider.getWrappedInstance().save();
}
//
// Render
render() {
return (
<PageContent title="Metadata Settings">
<SettingsToolbarConnector
hasPendingChanges={this.state.hasPendingChanges}
onSavePress={this.onSavePress}
/>
<PageContentBodyConnector>
<MetadatasConnector />
<MetadataProviderConnector
ref={this.setMetadataProviderRef}
onHasPendingChange={this.onHasPendingChange}
/>
</PageContentBodyConnector>
</PageContent>
);
}
} }
export default MetadataSettings; export default MetadataSettings;

@ -297,6 +297,10 @@ export const SET_METADATA_VALUE = 'SET_METADATA_VALUE';
export const SET_METADATA_FIELD_VALUE = 'SET_METADATA_FIELD_VALUE'; export const SET_METADATA_FIELD_VALUE = 'SET_METADATA_FIELD_VALUE';
export const SAVE_METADATA = 'SAVE_METADATA'; export const SAVE_METADATA = 'SAVE_METADATA';
export const FETCH_METADATA_PROVIDER = 'FETCH_METADATA_PROVIDER';
export const SET_METADATA_PROVIDER_VALUE = 'SET_METADATA_PROVIDER_VALUE';
export const SAVE_METADATA_PROVIDER = 'SAVE_METADATA_PROVIDER';
// //
// System // System

@ -243,6 +243,9 @@ const settingsActionHandlers = {
'/metadata', '/metadata',
(state) => state.settings.metadata), (state) => state.settings.metadata),
[types.FETCH_METADATA_PROVIDER]: createFetchHandler('metadataProvider', '/config/metadataProvider'),
[types.SAVE_METADATA_PROVIDER]: createSaveHandler('metadataProvider', '/config/metadataProvider', (state) => state.settings.metadataProvider),
[types.FETCH_GENERAL_SETTINGS]: createFetchHandler('general', '/config/host'), [types.FETCH_GENERAL_SETTINGS]: createFetchHandler('general', '/config/host'),
[types.SAVE_GENERAL_SETTINGS]: createSaveHandler('general', '/config/host', (state) => state.settings.general) [types.SAVE_GENERAL_SETTINGS]: createSaveHandler('general', '/config/host', (state) => state.settings.general)
}; };

@ -203,6 +203,15 @@ export const setMetadataFieldValue = createAction(types.SET_METADATA_FIELD_VALUE
}; };
}); });
export const fetchMetadataProvider = settingsActionHandlers[types.FETCH_METADATA_PROVIDER];
export const saveMetadataProvider = settingsActionHandlers[types.SAVE_METADATA_PROVIDER];
export const setMetadataProviderValue = createAction(types.SET_METADATA_PROVIDER_VALUE, (payload) => {
return {
section: 'metadataProvider',
...payload
};
});
export const fetchGeneralSettings = settingsActionHandlers[types.FETCH_GENERAL_SETTINGS]; export const fetchGeneralSettings = settingsActionHandlers[types.FETCH_GENERAL_SETTINGS];
export const saveGeneralSettings = settingsActionHandlers[types.SAVE_GENERAL_SETTINGS]; export const saveGeneralSettings = settingsActionHandlers[types.SAVE_GENERAL_SETTINGS];
export const setGeneralSettingsValue = createAction(types.SET_GENERAL_SETTINGS_VALUE, (payload) => { export const setGeneralSettingsValue = createAction(types.SET_GENERAL_SETTINGS_VALUE, (payload) => {

@ -201,6 +201,16 @@ export const defaultState = {
pendingChanges: {} pendingChanges: {}
}, },
metadataProvider: {
isFetching: false,
isPopulated: false,
error: null,
pendingChanges: {},
isSaving: false,
saveError: null,
item: {}
},
general: { general: {
isFetching: false, isFetching: false,
isPopulated: false, isPopulated: false,
@ -226,7 +236,8 @@ const propertyNames = [
'qualityDefinitions', 'qualityDefinitions',
'indexerOptions', 'indexerOptions',
'downloadClientOptions', 'downloadClientOptions',
'general' 'general',
'metadataProvider'
]; ];
const providerPropertyNames = [ const providerPropertyNames = [
@ -330,6 +341,8 @@ const settingsReducers = handleActions({
[types.SET_METADATA_VALUE]: createSetSettingValueReducer('metadata'), [types.SET_METADATA_VALUE]: createSetSettingValueReducer('metadata'),
[types.SET_METADATA_FIELD_VALUE]: createSetProviderFieldValueReducer('metadata'), [types.SET_METADATA_FIELD_VALUE]: createSetProviderFieldValueReducer('metadata'),
[types.SET_METADATA_PROVIDER_VALUE]: createSetSettingValueReducer('metadataProvider'),
[types.SET_GENERAL_SETTINGS_VALUE]: createSetSettingValueReducer('general') [types.SET_GENERAL_SETTINGS_VALUE]: createSetSettingValueReducer('general')
}, defaultState); }, defaultState);

@ -0,0 +1,21 @@
using System.Linq;
using System.Reflection;
using NzbDrone.Core.Configuration;
using Lidarr.Http;
namespace Lidarr.Api.V3.Config
{
public class MetadataProviderConfigModule : SonarrConfigModule<MetadataProviderConfigResource>
{
public MetadataProviderConfigModule(IConfigService configService)
: base(configService)
{
}
protected override MetadataProviderConfigResource ToResource(IConfigService model)
{
return MetadataProviderConfigResourceMapper.ToResource(model);
}
}
}

@ -0,0 +1,24 @@
using NzbDrone.Core.Configuration;
using Lidarr.Http.REST;
namespace Lidarr.Api.V3.Config
{
public class MetadataProviderConfigResource : RestResource
{
//Calendar
public string MetadataSource { get; set; }
}
public static class MetadataProviderConfigResourceMapper
{
public static MetadataProviderConfigResource ToResource(IConfigService model)
{
return new MetadataProviderConfigResource
{
MetadataSource = model.MetadataSource,
};
}
}
}

@ -95,6 +95,8 @@
<Compile Include="Calendar\CalendarModule.cs" /> <Compile Include="Calendar\CalendarModule.cs" />
<Compile Include="Commands\CommandModule.cs" /> <Compile Include="Commands\CommandModule.cs" />
<Compile Include="Commands\CommandResource.cs" /> <Compile Include="Commands\CommandResource.cs" />
<Compile Include="Config\MetadataProviderConfigModule.cs" />
<Compile Include="Config\MetadataProviderConfigResource.cs" />
<Compile Include="TrackFiles\TrackFileListResource.cs" /> <Compile Include="TrackFiles\TrackFileListResource.cs" />
<Compile Include="TrackFiles\MediaInfoResource.cs" /> <Compile Include="TrackFiles\MediaInfoResource.cs" />
<Compile Include="Indexers\ReleaseModuleBase.cs" /> <Compile Include="Indexers\ReleaseModuleBase.cs" />

@ -7,7 +7,6 @@ namespace NzbDrone.Common.Cloud
IHttpRequestBuilderFactory Services { get; } IHttpRequestBuilderFactory Services { get; }
IHttpRequestBuilderFactory Search { get; } IHttpRequestBuilderFactory Search { get; }
IHttpRequestBuilderFactory InternalSearch { get; } IHttpRequestBuilderFactory InternalSearch { get; }
IHttpRequestBuilderFactory SkyHookTvdb { get; }
} }
public class LidarrCloudRequestBuilder : ILidarrCloudRequestBuilder public class LidarrCloudRequestBuilder : ILidarrCloudRequestBuilder
@ -19,11 +18,6 @@ namespace NzbDrone.Common.Cloud
Search = new HttpRequestBuilder("https://api.lidarr.audio/api/v0/{route}/") // TODO: Add {version} once LidarrAPI.Metadata is released. Search = new HttpRequestBuilder("https://api.lidarr.audio/api/v0/{route}/") // TODO: Add {version} once LidarrAPI.Metadata is released.
.CreateFactory(); .CreateFactory();
SkyHookTvdb = new HttpRequestBuilder("http://skyhook.lidarr.tv/v1/tvdb/{route}/{language}/")
.SetSegment("language", "en")
.CreateFactory();
} }
public IHttpRequestBuilderFactory Services { get; } public IHttpRequestBuilderFactory Services { get; }
@ -31,7 +25,5 @@ namespace NzbDrone.Common.Cloud
public IHttpRequestBuilderFactory Search { get; } public IHttpRequestBuilderFactory Search { get; }
public IHttpRequestBuilderFactory InternalSearch { get; } public IHttpRequestBuilderFactory InternalSearch { get; }
public IHttpRequestBuilderFactory SkyHookTvdb { get; }
} }
} }

@ -78,7 +78,7 @@
<Compile Include="Cache\CachedDictionary.cs" /> <Compile Include="Cache\CachedDictionary.cs" />
<Compile Include="Cache\ICached.cs" /> <Compile Include="Cache\ICached.cs" />
<Compile Include="Cache\ICachedDictionary.cs" /> <Compile Include="Cache\ICachedDictionary.cs" />
<Compile Include="Cloud\SonarrCloudRequestBuilder.cs" /> <Compile Include="Cloud\LidarrCloudRequestBuilder.cs" />
<Compile Include="Composition\Container.cs" /> <Compile Include="Composition\Container.cs" />
<Compile Include="Composition\ContainerBuilderBase.cs" /> <Compile Include="Composition\ContainerBuilderBase.cs" />
<Compile Include="Composition\IContainer.cs" /> <Compile Include="Composition\IContainer.cs" />

@ -238,6 +238,13 @@ namespace NzbDrone.Core.Configuration
set { SetValue("ChownGroup", value); } set { SetValue("ChownGroup", value); }
} }
public string MetadataSource
{
get { return GetValue("MetadataSource", ""); }
set { SetValue("MetadataSource", value); }
}
public int FirstDayOfWeek public int FirstDayOfWeek
{ {
get { return GetValueInt("FirstDayOfWeek", (int)CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek); } get { return GetValueInt("FirstDayOfWeek", (int)CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek); }

@ -58,6 +58,9 @@ namespace NzbDrone.Core.Configuration
//Internal //Internal
bool CleanupMetadataImages { get; set; } bool CleanupMetadataImages { get; set; }
//MetadataSource
string MetadataSource { get; set; }
//Forms Auth //Forms Auth
string RijndaelPassphrase { get; } string RijndaelPassphrase { get; }

@ -13,6 +13,7 @@ using NzbDrone.Core.Tv;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using NzbDrone.Core.Music; using NzbDrone.Core.Music;
using Newtonsoft.Json; using Newtonsoft.Json;
using NzbDrone.Core.Configuration;
namespace NzbDrone.Core.MetadataSource.SkyHook namespace NzbDrone.Core.MetadataSource.SkyHook
{ {
@ -23,15 +24,20 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
private readonly IArtistService _artistService; private readonly IArtistService _artistService;
private readonly IHttpRequestBuilderFactory _requestBuilder; private readonly IHttpRequestBuilderFactory _requestBuilder;
private readonly IConfigService _configService;
public SkyHookProxy(IHttpClient httpClient, ILidarrCloudRequestBuilder requestBuilder, IArtistService artistService, Logger logger) private IHttpRequestBuilderFactory customerRequestBuilder;
public SkyHookProxy(IHttpClient httpClient, ILidarrCloudRequestBuilder requestBuilder, IArtistService artistService, Logger logger, IConfigService configService)
{ {
_httpClient = httpClient; _httpClient = httpClient;
_configService = configService;
_requestBuilder = requestBuilder.Search; _requestBuilder = requestBuilder.Search;
_artistService = artistService; _artistService = artistService;
_logger = logger; _logger = logger;
} }
[Obsolete("Used for Sonarr, not Lidarr")]
public Tuple<Series, List<Episode>> GetSeriesInfo(int tvdbSeriesId) public Tuple<Series, List<Episode>> GetSeriesInfo(int tvdbSeriesId)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@ -42,8 +48,9 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
_logger.Debug("Getting Artist with LidarrAPI.MetadataID of {0}", foreignArtistId); _logger.Debug("Getting Artist with LidarrAPI.MetadataID of {0}", foreignArtistId);
// We need to perform a direct lookup of the artist SetCustomProvider();
var httpRequest = _requestBuilder.Create()
var httpRequest = customerRequestBuilder.Create()
.SetSegment("route", "artists/" + foreignArtistId) .SetSegment("route", "artists/" + foreignArtistId)
.Build(); .Build();
@ -99,7 +106,9 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
} }
} }
var httpRequest = _requestBuilder.Create() SetCustomProvider();
var httpRequest = customerRequestBuilder.Create()
.SetSegment("route", "search") .SetSegment("route", "search")
.AddQueryParam("type", "artist") .AddQueryParam("type", "artist")
.AddQueryParam("query", title.ToLower().Trim()) .AddQueryParam("query", title.ToLower().Trim())
@ -113,12 +122,12 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
} }
catch (HttpException) catch (HttpException)
{ {
throw new SkyHookException("Search for '{0}' failed. Unable to communicate with SkyHook.", title); throw new SkyHookException("Search for '{0}' failed. Unable to communicate with LidarrAPI.", title);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.Warn(ex, ex.Message); _logger.Warn(ex, ex.Message);
throw new SkyHookException("Search for '{0}' failed. Invalid response received from SkyHook.", title); throw new SkyHookException("Search for '{0}' failed. Invalid response received from LidarrAPI.", title);
} }
} }
@ -268,5 +277,17 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
return MediaCoverTypes.Unknown; return MediaCoverTypes.Unknown;
} }
} }
private void SetCustomProvider()
{
if (_configService.MetadataSource.IsNotNullOrWhiteSpace())
{
customerRequestBuilder = new HttpRequestBuilder(_configService.MetadataSource + "{route}/").CreateFactory();
}
else
{
customerRequestBuilder = _requestBuilder;
}
}
} }
} }

Loading…
Cancel
Save