diff options
author | Mike Crute <mcrute@gmail.com> | 2017-06-12 22:09:47 -0700 |
---|---|---|
committer | Mike Crute <mcrute@gmail.com> | 2017-06-12 22:22:38 -0700 |
commit | bd7fb11786c6b84af3f702ce915e3f07a7280b2b (patch) | |
tree | 3afb6149292d01073cb60aea79d22e31fd4d57f8 /pandora | |
parent | 9cc2ff1434c0d34452c8e02da63fd4c919261509 (diff) | |
download | pydora-bd7fb11786c6b84af3f702ce915e3f07a7280b2b.tar.bz2 pydora-bd7fb11786c6b84af3f702ce915e3f07a7280b2b.tar.xz pydora-bd7fb11786c6b84af3f702ce915e3f07a7280b2b.zip |
Split player backends, add VLC strategy
Extract core player logic and mpg123-bound logic into parent-child
classes so that other player backend strategies can be added. Create a
headless VLC strategy that uses VLC if it's available. Update the pydora
player to prefer VLC if it's available on the system because it supports
a much more broad set of codecs and Pandora is now preferring AAC
formatted files.
Diffstat (limited to 'pandora')
-rw-r--r-- | pandora/py2compat.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/pandora/py2compat.py b/pandora/py2compat.py index d83f8c5..fe45462 100644 --- a/pandora/py2compat.py +++ b/pandora/py2compat.py | |||
@@ -26,3 +26,50 @@ except ImportError: | |||
26 | from mock import Mock, MagicMock, call, patch # noqa: F401 | 26 | from mock import Mock, MagicMock, call, patch # noqa: F401 |
27 | except ImportError: | 27 | except ImportError: |
28 | pass | 28 | pass |
29 | |||
30 | |||
31 | try: | ||
32 | from shutil import which | ||
33 | except ImportError: | ||
34 | import os | ||
35 | import sys | ||
36 | |||
37 | # Copypasta from Python 3.6, exists in 3.3+ | ||
38 | def which(cmd, mode=os.F_OK | os.X_OK, path=None): | ||
39 | def _access_check(fn, mode): | ||
40 | return (os.path.exists(fn) and os.access(fn, mode) | ||
41 | and not os.path.isdir(fn)) | ||
42 | |||
43 | if os.path.dirname(cmd): | ||
44 | if _access_check(cmd, mode): | ||
45 | return cmd | ||
46 | return None | ||
47 | |||
48 | if path is None: | ||
49 | path = os.environ.get("PATH", os.defpath) | ||
50 | if not path: | ||
51 | return None | ||
52 | path = path.split(os.pathsep) | ||
53 | |||
54 | if sys.platform == "win32": | ||
55 | if os.curdir not in path: | ||
56 | path.insert(0, os.curdir) | ||
57 | |||
58 | pathext = os.environ.get("PATHEXT", "").split(os.pathsep) | ||
59 | if any(cmd.lower().endswith(ext.lower()) for ext in pathext): | ||
60 | files = [cmd] | ||
61 | else: | ||
62 | files = [cmd + ext for ext in pathext] | ||
63 | else: | ||
64 | files = [cmd] | ||
65 | |||
66 | seen = set() | ||
67 | for dir in path: | ||
68 | normdir = os.path.normcase(dir) | ||
69 | if normdir not in seen: | ||
70 | seen.add(normdir) | ||
71 | for thefile in files: | ||
72 | name = os.path.join(dir, thefile) | ||
73 | if _access_check(name, mode): | ||
74 | return name | ||
75 | return None | ||