Propagate enviornment variables to the player executable

This commit is contained in:
Fabio Manganiello 2019-02-02 15:51:12 +01:00
parent 63b423cf75
commit 1713c0c940
2 changed files with 12 additions and 2 deletions

View file

@ -51,7 +51,8 @@ class MediaPlugin(Plugin):
_supported_media_plugins = { 'media.mplayer', 'media.omxplayer' } _supported_media_plugins = { 'media.mplayer', 'media.omxplayer' }
def __init__(self, media_dirs=[], download_dir=None, *args, **kwargs): def __init__(self, media_dirs=[], download_dir=None, env=None,
*args, **kwargs):
""" """
:param media_dirs: Directories that will be scanned for media files when :param media_dirs: Directories that will be scanned for media files when
a search is performed (default: none) a search is performed (default: none)
@ -60,6 +61,10 @@ class MediaPlugin(Plugin):
:param download_dir: Directory where external resources/torrents will be :param download_dir: Directory where external resources/torrents will be
downloaded (default: none) downloaded (default: none)
:type download_dir: str :type download_dir: str
:param env: Environment variables key-values to pass to the
player executable (e.g. DISPLAY, XDG_VTNR, PULSE_SINK etc.)
:type env: dict
""" """
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@ -84,6 +89,7 @@ class MediaPlugin(Plugin):
setattr(self, action, getattr(plugin, action)) setattr(self, action, getattr(plugin, action))
self.registered_actions.add(action) self.registered_actions.add(action)
self._environment = environment or {}
self.media_dirs = set( self.media_dirs = set(
filter( filter(
lambda _: os.path.isdir(_), lambda _: os.path.isdir(_),

View file

@ -112,7 +112,11 @@ class MediaMplayerPlugin(MediaPlugin):
if arg not in args: if arg not in args:
args.append(arg) args.append(arg)
self._mplayer = subprocess.Popen(args, env = os.environ.copy()
if self._environment:
env.update(self._environment)
self._mplayer = subprocess.Popen(args, env=env, shell=True,
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=subprocess.PIPE) stdout=subprocess.PIPE)