Skip to content

Commit

Permalink
Try to default to a video player that's available
Browse files Browse the repository at this point in the history
Part of #136
  • Loading branch information
otsaloma committed Jul 28, 2019
1 parent 272f63c commit ff9a5a6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions aeidon/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import aeidon
import os
import shutil
import sys

from aeidon.i18n import _
Expand Down Expand Up @@ -159,6 +160,7 @@ class PlayerMPlayer(aeidon.EnumerationItem):
# http://www.mplayerhq.hu/DOCS/HTML/en/faq.html#idm5930
command_utf_8 = "{} < /dev/null".format(command_utf_8)

found = shutil.which(_get_mplayer_executable()) is not None
label = "MPlayer"

class PlayerMPV(aeidon.EnumerationItem):
Expand All @@ -179,6 +181,7 @@ class PlayerMPV(aeidon.EnumerationItem):
"--sub-codepage=utf-8",
"$VIDEOFILE",))

found = shutil.which(_get_mpv_executable()) is not None
label = "mpv"

class PlayerVLC(aeidon.EnumerationItem):
Expand All @@ -193,6 +196,7 @@ class PlayerVLC(aeidon.EnumerationItem):
":sub-file=$SUBFILE",
":subsdec-encoding=UTF-8",))

found = shutil.which(_get_vlc_executable()) is not None
label = "VLC"

players = aeidon.Enumeration()
Expand Down
7 changes: 3 additions & 4 deletions gaupol/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,9 @@
"preview": {
"custom_command": "",
"force_utf_8": True,
"offset": (5.0 if sys.platform == "win32" else 1.0),
"player": (aeidon.players.VLC if sys.platform == "win32"
else aeidon.players.MPV),

# mpv is the only player that supports precise seek, others need a longer offset.
"offset": 1.0 if gaupol.util.get_default_player() == aeidon.players.MPV else 5.0,
"player": gaupol.util.get_default_player(),
"use_custom_command": False,
},
"search": {
Expand Down
6 changes: 6 additions & 0 deletions gaupol/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ def get_content_size(widget, font=None):
raise ValueError("Unsupported container type: {!r}"
.format(type(widget)))

def get_default_player():
"""Return the default video player to use for preview."""
players = [aeidon.players.MPV, aeidon.players.MPLAYER, aeidon.players.VLC]
players = [x for x in players if x.found]
return players[0] if players else aeidon.players.MPV

def get_font():
"""Return custom font or blank string."""
return (gaupol.conf.editor.custom_font if
Expand Down

0 comments on commit ff9a5a6

Please sign in to comment.