cplay

changeset 2:c7d8ec7da73b 1.49-meillo

Add mplayer as a backend player Plus: exchange PCM and Master mixer.
author markus schnalke <meillo@marmaro.de>
date Thu, 27 Jul 2017 07:08:00 +0200
parents 7db0dc9d32d3
children 07e746bdb6bb
files cplay
diffstat 1 files changed, 30 insertions(+), 5 deletions(-) [+]
line diff
     1.1 --- a/cplay	Wed Sep 27 09:25:24 2017 +0200
     1.2 +++ b/cplay	Thu Jul 27 07:08:00 2017 +0200
     1.3 @@ -1,7 +1,7 @@
     1.4  #!/usr/bin/env python
     1.5  # -*- python -*-
     1.6  
     1.7 -__version__ = "cplay 1.49"
     1.8 +__version__ = "cplay 1.49-meillo"
     1.9  
    1.10  """
    1.11  cplay - A curses front-end for various audio players
    1.12 @@ -1206,6 +1206,7 @@
    1.13          self.stopped = 0
    1.14          self.paused = 0
    1.15          self.step = 0
    1.16 +        self.setlength()
    1.17          self.update_status()
    1.18  
    1.19      def stop(self, quiet=0):
    1.20 @@ -1277,6 +1278,9 @@
    1.21          else:
    1.22              app.set_default_status(_("Playing: %s") % self.entry.vp())
    1.23  
    1.24 +    def setlength(self):
    1.25 +        return
    1.26 +
    1.27  # ------------------------------------------
    1.28  class FrameOffsetPlayer(Player):
    1.29      re_progress = re.compile("Time.*\s(\d+):(\d+).*\[(\d+):(\d+)")
    1.30 @@ -1301,6 +1305,26 @@
    1.31              self.set_position(head, head+tail, [head, tail])
    1.32  
    1.33  # ------------------------------------------
    1.34 +class TimeOffsetMplayer(Player):
    1.35 +    re_progress = re.compile("A: *(\d+)")
    1.36 +
    1.37 +    def parse_buf(self):
    1.38 +        match = self.re_progress.search(self.buf)
    1.39 +        if match:
    1.40 +            head = string.atoi(match.groups()[0])
    1.41 +            tail = max(self.length, head) - head
    1.42 +            self.set_position(head, head+tail, [head, tail])
    1.43 +
    1.44 +    def setlength(self):
    1.45 +        while 1:
    1.46 +            self.buf = os.read(self.stdout_r, 512)
    1.47 +            re_length = re.compile("ID_LENGTH=(\d+)")
    1.48 +            match = re_length.search(self.buf)
    1.49 +            if match:
    1.50 +                self.length = string.atoi(match.groups()[0])
    1.51 +                break
    1.52 +
    1.53 +# ------------------------------------------
    1.54  class NoOffsetPlayer(Player):
    1.55  
    1.56      def parse_buf(self):
    1.57 @@ -1508,15 +1532,15 @@
    1.58              mixer = ossaudiodev.openmixer()
    1.59              get, set = mixer.get, mixer.set
    1.60              self.channels = self.channels or \
    1.61 -                [['MASTER', ossaudiodev.SOUND_MIXER_VOLUME],
    1.62 -                 ['PCM', ossaudiodev.SOUND_MIXER_PCM]]
    1.63 +                [['PCM', ossaudiodev.SOUND_MIXER_PCM],
    1.64 +                 ['MASTER', ossaudiodev.SOUND_MIXER_VOLUME]]
    1.65          except ImportError:
    1.66              import oss
    1.67              mixer = oss.open_mixer()
    1.68              get, set = mixer.read_channel, mixer.write_channel
    1.69              self.channels = self.channels or \
    1.70 -                [['MASTER', oss.SOUND_MIXER_VOLUME],
    1.71 -                 ['PCM', oss.SOUND_MIXER_PCM]]
    1.72 +                [['PCM', oss.SOUND_MIXER_PCM],
    1.73 +                 ['MASTER', oss.SOUND_MIXER_VOLUME]]
    1.74          if cmd is "toggle": self.channels.insert(0, self.channels.pop())
    1.75          name, channel = self.channels[0]
    1.76          if cmd is "cue": arg = min(100, max(0, get(channel)[0] + arg))
    1.77 @@ -1627,6 +1651,7 @@
    1.78  
    1.79  # ------------------------------------------
    1.80  PLAYERS = [
    1.81 +    TimeOffsetMplayer("mplayer -vo null -identify -ss %d %s", "(^http://|\.(mp[1-4]|flv|mkv|m4a)$)"),
    1.82      FrameOffsetPlayer("ogg123 -q -v -k %d %s", "\.ogg$"),
    1.83      FrameOffsetPlayer("splay -f -k %d %s", "(^http://|\.mp[123]$)", 38.28),
    1.84      FrameOffsetPlayer("mpg123 -q -v -k %d %s", "(^http://|\.mp[123]$)", 38.28),