diff --git a/mopidy/backends/spotify/session_manager.py b/mopidy/backends/spotify/session_manager.py index 8f520896..3e8f1b67 100644 --- a/mopidy/backends/spotify/session_manager.py +++ b/mopidy/backends/spotify/session_manager.py @@ -33,9 +33,14 @@ class SpotifySessionManager(process.BaseThread, PyspotifySessionManager): self.cache_location = config['spotify']['cache_dir'] self.settings_location = config['spotify']['cache_dir'] + # Add proxy port only if available + full_proxy = config['proxy']['hostname'] + if 'port' in config['proxy']: + full_proxy = full_proxy + ':' + str(config['proxy']['port']) + PyspotifySessionManager.__init__( self, config['spotify']['username'], config['spotify']['password'], - proxy=config['proxy']['hostname'], + proxy=full_proxy, proxy_username=config['proxy']['username'], proxy_password=config['proxy']['password']) diff --git a/mopidy/config/__init__.py b/mopidy/config/__init__.py index e9ae7d86..7ccaa3f3 100644 --- a/mopidy/config/__init__.py +++ b/mopidy/config/__init__.py @@ -29,6 +29,7 @@ _proxy_schema = ConfigSchema('proxy') _proxy_schema['hostname'] = Hostname(optional=True) _proxy_schema['username'] = String(optional=True) _proxy_schema['password'] = Secret(optional=True) +_proxy_schema['port'] = Port(optional=True) # NOTE: if multiple outputs ever comes something like LogLevelConfigSchema #_outputs_schema = config.AudioOutputConfigSchema() diff --git a/mopidy/config/convert.py b/mopidy/config/convert.py index 6cb20fcd..3c3edb85 100644 --- a/mopidy/config/convert.py +++ b/mopidy/config/convert.py @@ -39,6 +39,7 @@ def convert(settings): helper('audio/output', 'OUTPUT') helper('proxy/hostname', 'SPOTIFY_PROXY_HOST') + helper('proxy/port', 'SPOTIFY_PROXY_PORT') helper('proxy/username', 'SPOTIFY_PROXY_USERNAME') helper('proxy/password', 'SPOTIFY_PROXY_PASSWORD') diff --git a/mopidy/config/default.conf b/mopidy/config/default.conf index b525ef47..204c789b 100644 --- a/mopidy/config/default.conf +++ b/mopidy/config/default.conf @@ -16,3 +16,4 @@ output = autoaudiosink hostname = username = password = +port = \ No newline at end of file diff --git a/mopidy/config/types.py b/mopidy/config/types.py index ec0be1de..3dff0908 100644 --- a/mopidy/config/types.py +++ b/mopidy/config/types.py @@ -117,7 +117,10 @@ class Integer(ConfigValue): self._choices = choices def deserialize(self, value): - value = int(value) + try: + value = int(value) + except: + value = 0 validators.validate_choice(value, self._choices) validators.validate_minimum(value, self._minimum) validators.validate_maximum(value, self._maximum) @@ -222,7 +225,8 @@ class Port(Integer): allocate a port for us. """ # TODO: consider probing if port is free or not? - def __init__(self, choices=None): + def __init__(self, choices=None, optional=False): + self._required = not optional super(Port, self).__init__( minimum=0, maximum=2 ** 16 - 1, choices=choices)