|
12 | 12 | import collections |
13 | 13 | import json |
14 | 14 | import socket |
| 15 | +from shutil import copyfile as shutil_copy_file |
15 | 16 |
|
16 | 17 | import locale |
17 | 18 | locale.setlocale(locale.LC_ALL, "") |
@@ -348,6 +349,7 @@ def _get_all_config_files(self): |
348 | 349 | else: |
349 | 350 | config_files = [] |
350 | 351 | self.all_config_files['mplayer'] = config_files[:] |
| 352 | + self._restore_win_player_config_file() |
351 | 353 |
|
352 | 354 | @property |
353 | 355 | def profile_name(self): |
@@ -607,8 +609,36 @@ def _do_save_volume(self, config_string): |
607 | 609 | return ret_strings[2].format(str(self.volume)) |
608 | 610 | self.volume = -1 |
609 | 611 | self.PROFILE_FROM_USER = True |
| 612 | + self.bck_win_player_config_file(config_file) |
610 | 613 | return ret_string |
611 | 614 |
|
| 615 | + def bck_win_player_config_file(self, config_file=None): |
| 616 | + if platform.startswith('win'): |
| 617 | + ''' backup player config ''' |
| 618 | + if config_file is None: |
| 619 | + cnf_file = self.config_files[0] |
| 620 | + else: |
| 621 | + cnf_file = config_file |
| 622 | + if os.path.exists(cnf_file): |
| 623 | + bck_file = os.path.join(os.getenv('APPDATA'), "pyradio", self.PLAYER_NAME + "-active.conf") |
| 624 | + try: |
| 625 | + shutil_copy_file(cnf_file, bck_file) |
| 626 | + except: |
| 627 | + pass |
| 628 | + |
| 629 | + def _restore_win_player_config_file(self): |
| 630 | + if platform.startswith('win'): |
| 631 | + ''' restore player config ''' |
| 632 | + for k in ('mplayer', 'mpv'): |
| 633 | + cnf_file = self.all_config_files[k][0] |
| 634 | + if os.path.exists(cnf_file): |
| 635 | + bck_file = os.path.join(os.getenv('APPDATA'), "pyradio", k + "-active.conf") |
| 636 | + if os.path.exists(bck_file): |
| 637 | + try: |
| 638 | + shutil_copy_file(bck_file, cnf_file) |
| 639 | + except: |
| 640 | + pass |
| 641 | + |
612 | 642 | def _stop_delay_thread(self): |
613 | 643 | if self.delay_thread is not None: |
614 | 644 | try: |
@@ -1549,16 +1579,28 @@ def play(self, |
1549 | 1579 |
|
1550 | 1580 | def _sendCommand(self, command): |
1551 | 1581 | ''' send keystroke command to player ''' |
1552 | | - for a_process in (self.process, self.monitor_process): |
1553 | | - if a_process is not None: |
1554 | | - if logger.isEnabledFor(logging.DEBUG): |
1555 | | - logger.debug('Sending Command: {}'.format(command).strip()) |
1556 | | - try: |
1557 | | - a_process.stdin.write(command.encode('utf-8', 'replace')) |
1558 | | - a_process.stdin.flush() |
1559 | | - except: |
1560 | | - if logger.isEnabledFor(logging.ERROR): |
1561 | | - logger.error('Error while sending Command: {}'.format(command).strip(), exc_info=True) |
| 1582 | + for a_process in (self.monitor_process, self.process): |
| 1583 | + self._command_to_player(a_process, command) |
| 1584 | + return |
| 1585 | + if command in ('q', '/', '*'): |
| 1586 | + for a_process in (self.monitor_process, self.process): |
| 1587 | + self._command_to_player(a_process, command) |
| 1588 | + elif self.recording == self.NO_RECORDING or \ |
| 1589 | + self.recording == self.RECORD_WITH_SILENCE: |
| 1590 | + self._command_to_player(self.process, command) |
| 1591 | + elif self.recording == self.RECORD_AND_LISTEN: |
| 1592 | + self._command_to_player(self.monitor_process, command) |
| 1593 | + |
| 1594 | + def _command_to_player(self, a_process, command): |
| 1595 | + if a_process is not None: |
| 1596 | + if logger.isEnabledFor(logging.DEBUG): |
| 1597 | + logger.debug('Sending Command: {}'.format(command).strip()) |
| 1598 | + try: |
| 1599 | + a_process.stdin.write(command.encode('utf-8', 'replace')) |
| 1600 | + a_process.stdin.flush() |
| 1601 | + except: |
| 1602 | + if logger.isEnabledFor(logging.ERROR): |
| 1603 | + logger.error('Error while sending Command: {}'.format(command).strip(), exc_info=True) |
1562 | 1604 |
|
1563 | 1605 | def close_from_windows(self): |
1564 | 1606 | ''' kill player instance when window console is closed ''' |
|
0 commit comments