|
17 | 17 | pass |
18 | 18 | if platform.startswith('win'): |
19 | 19 | import win32pipe, win32file, pywintypes |
20 | | - |
21 | 20 | try: |
22 | 21 | from urllib import unquote |
23 | 22 | except: |
24 | 23 | from urllib.parse import unquote |
25 | | -from .cjkwrap import wrap |
26 | | -from .encodings import get_encodings |
| 24 | + |
| 25 | +''' In case of import from win.py ''' |
| 26 | +try: |
| 27 | + from .cjkwrap import wrap |
| 28 | +except: |
| 29 | + pass |
| 30 | +''' In case of import from win.py ''' |
| 31 | +try: |
| 32 | + from .encodings import get_encodings |
| 33 | +except: |
| 34 | + pass |
27 | 35 |
|
28 | 36 | logger = logging.getLogger(__name__) |
29 | 37 |
|
@@ -120,6 +128,25 @@ def find_vlc_on_windows(config_dir=None): |
120 | 128 | # result.append(os.path.join(root, name)) |
121 | 129 | #return result |
122 | 130 |
|
| 131 | +def find_mpv_on_windows(): |
| 132 | + for a_path in ( |
| 133 | + os.path.join(os.getenv('APPDATA'), 'pyradio', 'mpv', 'mpv.exe'), |
| 134 | + os.path.join(os.getenv('APPDATA'), 'mpv', 'mpv.exe'), |
| 135 | + os.path.join(expanduser("~"), 'mpv', 'mpv.exe') |
| 136 | + ): |
| 137 | + if os.path.exists(a_path): |
| 138 | + return a_path |
| 139 | + return 'mpv' |
| 140 | + |
| 141 | +def find_mplayer_on_windows(): |
| 142 | + for a_path in ( |
| 143 | + os.path.join(os.getenv('APPDATA'), 'pyradio', 'mplayer', 'mplayer.exe'), |
| 144 | + os.path.join(os.getenv('APPDATA'), 'mplayer', 'mplayer.exe'), |
| 145 | + os.path.join(expanduser("~"), 'mplayer', 'mplayer.exe') |
| 146 | + ): |
| 147 | + if os.path.exists(a_path): |
| 148 | + return a_path |
| 149 | + return 'mplayer' |
123 | 150 |
|
124 | 151 | def info_dict_to_list(info, fix_highlight, max_width): |
125 | 152 | max_len = 0 |
@@ -620,7 +647,7 @@ def updateStatus(self, *args): |
620 | 647 | self.GET_AUDIO_CODEC_NAME): |
621 | 648 | response = self._send_mpv_command( a_cmd, return_response=True) |
622 | 649 | if response: |
623 | | - self._get_mpv_metadata(response, lambda: False) |
| 650 | + self._get_mpv_metadata(response, lambda: False, enable_crash_detection_function) |
624 | 651 | self.info_display_handler() |
625 | 652 | else: |
626 | 653 | if logger.isEnabledFor(logging.INFO): |
@@ -787,7 +814,7 @@ def updateMPVStatus(self, *args): |
787 | 814 | if a_data: |
788 | 815 | all_data = a_data.split(b'\n') |
789 | 816 | for n in all_data: |
790 | | - if self._get_mpv_metadata(n, stop): |
| 817 | + if self._get_mpv_metadata(n, stop, enable_crash_detection_function): |
791 | 818 | self._request_mpv_info_data(sock) |
792 | 819 | else: |
793 | 820 | try: |
@@ -1094,7 +1121,7 @@ def _get_mpv_metadata(self, *args): |
1094 | 1121 |
|
1095 | 1122 | a_data = args[0] |
1096 | 1123 | stop = args[1] |
1097 | | - |
| 1124 | + enable_crash_detection_function = [2] |
1098 | 1125 | if b'"icy-title":"' in a_data: |
1099 | 1126 | if version_info > (3, 0): |
1100 | 1127 | title = a_data.split(b'"icy-title":"')[1].split(b'"}')[0] |
@@ -1421,18 +1448,21 @@ def _kill_process_tree(self, pid): |
1421 | 1448 | if logger.isEnabledFor(logging.DEBUG): |
1422 | 1449 | logger.debug('PID {} does not exist...'.format(pid)) |
1423 | 1450 | return |
1424 | | - children = parent.children(recursive=True) |
1425 | 1451 | try: |
1426 | | - os.kill(parent.pid, 9) |
1427 | | - except: |
1428 | | - pass |
1429 | | - for child in children: |
| 1452 | + children = parent.children(recursive=True) |
1430 | 1453 | try: |
1431 | | - os.kill(child.pid, 9) |
| 1454 | + os.kill(parent.pid, 9) |
1432 | 1455 | except: |
1433 | 1456 | pass |
1434 | | - if logger.isEnabledFor(logging.DEBUG): |
1435 | | - logger.debug('PID {} (and its children) killed...'.format(pid)) |
| 1457 | + for child in children: |
| 1458 | + try: |
| 1459 | + os.kill(child.pid, 9) |
| 1460 | + except: |
| 1461 | + pass |
| 1462 | + if logger.isEnabledFor(logging.DEBUG): |
| 1463 | + logger.debug('PID {} (and its children) killed...'.format(pid)) |
| 1464 | + except psutil.NoSuchProcess: |
| 1465 | + pass |
1436 | 1466 |
|
1437 | 1467 | def _killall(self, name): |
1438 | 1468 | if name: |
@@ -1524,6 +1554,11 @@ class MpvPlayer(Player): |
1524 | 1554 |
|
1525 | 1555 | PLAYER_NAME = 'mpv' |
1526 | 1556 | PLAYER_CMD = 'mpv' |
| 1557 | + WIN = False |
| 1558 | + if platform.startswith('win'): |
| 1559 | + WIN = True |
| 1560 | + if WIN: |
| 1561 | + PLAYER_CMD = find_mpv_on_windows() |
1527 | 1562 | NEW_PROFILE_STRING = 'volume=50\n\n' |
1528 | 1563 | if pywhich(PLAYER_CMD): |
1529 | 1564 | executable_found = True |
@@ -1951,6 +1986,11 @@ class MpPlayer(Player): |
1951 | 1986 |
|
1952 | 1987 | PLAYER_NAME = 'mplayer' |
1953 | 1988 | PLAYER_CMD = 'mplayer' |
| 1989 | + WIN = False |
| 1990 | + if platform.startswith('win'): |
| 1991 | + WIN = True |
| 1992 | + if WIN: |
| 1993 | + PLAYER_CMD = find_mplayer_on_windows() |
1954 | 1994 | NEW_PROFILE_STRING = 'softvol=1\nsoftvol-max=300\nvolstep=1\nvolume=50\n\n' |
1955 | 1995 | if pywhich(PLAYER_CMD): |
1956 | 1996 | executable_found = True |
|
0 commit comments