Support for default media player volume
This commit is contained in:
parent
70fe2459de
commit
a9dbda455f
7 changed files with 29 additions and 4 deletions
|
@ -3,6 +3,8 @@ import functools
|
||||||
import os
|
import os
|
||||||
import queue
|
import queue
|
||||||
import re
|
import re
|
||||||
|
from typing import Optional, List, Dict, Union
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
|
@ -69,20 +71,23 @@ class MediaPlugin(Plugin):
|
||||||
_supported_media_types = ['file', 'torrent', 'youtube']
|
_supported_media_types = ['file', 'torrent', 'youtube']
|
||||||
_default_search_timeout = 60 # 60 seconds
|
_default_search_timeout = 60 # 60 seconds
|
||||||
|
|
||||||
def __init__(self, media_dirs=None, download_dir=None, env=None,
|
def __init__(self,
|
||||||
|
media_dirs: Optional[List[str]] = None,
|
||||||
|
download_dir: Optional[str] = None,
|
||||||
|
env: Optional[Dict[str, str]] = None,
|
||||||
|
volume: Optional[Union[float, int]] = None,
|
||||||
*args, **kwargs):
|
*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)
|
||||||
:type media_dirs: list
|
|
||||||
|
|
||||||
:param download_dir: Directory where external resources/torrents will be
|
:param download_dir: Directory where external resources/torrents will be
|
||||||
downloaded (default: ~/Downloads)
|
downloaded (default: ~/Downloads)
|
||||||
:type download_dir: str
|
|
||||||
|
|
||||||
:param env: Environment variables key-values to pass to the
|
:param env: Environment variables key-values to pass to the
|
||||||
player executable (e.g. DISPLAY, XDG_VTNR, PULSE_SINK etc.)
|
player executable (e.g. DISPLAY, XDG_VTNR, PULSE_SINK etc.)
|
||||||
:type env: dict
|
|
||||||
|
:param volume: Default volume for the player (default: None, maximum volume).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
@ -134,6 +139,7 @@ class MediaPlugin(Plugin):
|
||||||
os.makedirs(self.download_dir, exist_ok=True)
|
os.makedirs(self.download_dir, exist_ok=True)
|
||||||
|
|
||||||
self.media_dirs.add(self.download_dir)
|
self.media_dirs.add(self.download_dir)
|
||||||
|
self.volume = volume
|
||||||
self._videos_queue = []
|
self._videos_queue = []
|
||||||
self._youtube_proc = None
|
self._youtube_proc = None
|
||||||
|
|
||||||
|
|
|
@ -318,6 +318,10 @@ class MediaChromecastPlugin(MediaPlugin):
|
||||||
mc.register_status_listener(self.SubtitlesAsyncHandler(mc, subtitle_id))
|
mc.register_status_listener(self.SubtitlesAsyncHandler(mc, subtitle_id))
|
||||||
|
|
||||||
mc.block_until_active()
|
mc.block_until_active()
|
||||||
|
|
||||||
|
if self.volume:
|
||||||
|
self.set_volume(volume=self.volume, chromecast=chromecast)
|
||||||
|
|
||||||
return self.status(chromecast=chromecast)
|
return self.status(chromecast=chromecast)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -173,6 +173,9 @@ class MediaKodiPlugin(MediaPlugin):
|
||||||
resource = resource[7:]
|
resource = resource[7:]
|
||||||
|
|
||||||
result = self._get_kodi().Player.Open(item={'file': resource})
|
result = self._get_kodi().Player.Open(item={'file': resource})
|
||||||
|
if self.volume:
|
||||||
|
self.set_volume(volume=int(self.volume))
|
||||||
|
|
||||||
return self._build_result(result)
|
return self._build_result(result)
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
|
|
@ -268,6 +268,10 @@ class MediaMplayerPlugin(MediaPlugin):
|
||||||
|
|
||||||
self._exec('loadfile', resource, mplayer_args=mplayer_args)
|
self._exec('loadfile', resource, mplayer_args=mplayer_args)
|
||||||
self._post_event(MediaPlayEvent, resource=resource)
|
self._post_event(MediaPlayEvent, resource=resource)
|
||||||
|
|
||||||
|
if self.volume:
|
||||||
|
self.set_volume(volume=self.volume)
|
||||||
|
|
||||||
return self.status()
|
return self.status()
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
|
|
@ -140,6 +140,9 @@ class MediaMpvPlugin(MediaPlugin):
|
||||||
resource = resource[7:]
|
resource = resource[7:]
|
||||||
|
|
||||||
self._player.play(resource)
|
self._player.play(resource)
|
||||||
|
if self.volume:
|
||||||
|
self.set_volume(volume=self.volume)
|
||||||
|
|
||||||
return self.status()
|
return self.status()
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
|
|
@ -82,6 +82,9 @@ class MediaOmxplayerPlugin(MediaPlugin):
|
||||||
self.logger.exception(e)
|
self.logger.exception(e)
|
||||||
|
|
||||||
self._player.pause()
|
self._player.pause()
|
||||||
|
if self.volume:
|
||||||
|
self.set_volume(volume=self.volume)
|
||||||
|
|
||||||
self._player.play()
|
self._player.play()
|
||||||
return self.status()
|
return self.status()
|
||||||
|
|
||||||
|
|
|
@ -167,6 +167,8 @@ class MediaVlcPlugin(MediaPlugin):
|
||||||
self._player.video_set_subtitle_file(subtitles)
|
self._player.video_set_subtitle_file(subtitles)
|
||||||
|
|
||||||
self._player.play()
|
self._player.play()
|
||||||
|
if self.volume:
|
||||||
|
self.set_volume(volume=self.volume)
|
||||||
|
|
||||||
if fullscreen or self._default_fullscreen:
|
if fullscreen or self._default_fullscreen:
|
||||||
self.set_fullscreen(True)
|
self.set_fullscreen(True)
|
||||||
|
|
Loading…
Reference in a new issue