Mercurial > cplay
comparison cplay @ 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 | aa5f022eac8a |
children |
comparison
equal
deleted
inserted
replaced
1:7db0dc9d32d3 | 2:c7d8ec7da73b |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # -*- python -*- | 2 # -*- python -*- |
3 | 3 |
4 __version__ = "cplay 1.49" | 4 __version__ = "cplay 1.49-meillo" |
5 | 5 |
6 """ | 6 """ |
7 cplay - A curses front-end for various audio players | 7 cplay - A curses front-end for various audio players |
8 Copyright (C) 1998-2003 Ulf Betlehem <flu@iki.fi> | 8 Copyright (C) 1998-2003 Ulf Betlehem <flu@iki.fi> |
9 | 9 |
1204 try: os.execv(self.argv[0], self.argv) | 1204 try: os.execv(self.argv[0], self.argv) |
1205 except: os._exit(1) | 1205 except: os._exit(1) |
1206 self.stopped = 0 | 1206 self.stopped = 0 |
1207 self.paused = 0 | 1207 self.paused = 0 |
1208 self.step = 0 | 1208 self.step = 0 |
1209 self.setlength() | |
1209 self.update_status() | 1210 self.update_status() |
1210 | 1211 |
1211 def stop(self, quiet=0): | 1212 def stop(self, quiet=0): |
1212 self.paused and self.toggle_pause(quiet) | 1213 self.paused and self.toggle_pause(quiet) |
1213 try: | 1214 try: |
1275 elif self.paused: | 1276 elif self.paused: |
1276 app.set_default_status(_("Paused: %s") % self.entry.vp()) | 1277 app.set_default_status(_("Paused: %s") % self.entry.vp()) |
1277 else: | 1278 else: |
1278 app.set_default_status(_("Playing: %s") % self.entry.vp()) | 1279 app.set_default_status(_("Playing: %s") % self.entry.vp()) |
1279 | 1280 |
1281 def setlength(self): | |
1282 return | |
1283 | |
1280 # ------------------------------------------ | 1284 # ------------------------------------------ |
1281 class FrameOffsetPlayer(Player): | 1285 class FrameOffsetPlayer(Player): |
1282 re_progress = re.compile("Time.*\s(\d+):(\d+).*\[(\d+):(\d+)") | 1286 re_progress = re.compile("Time.*\s(\d+):(\d+).*\[(\d+):(\d+)") |
1283 | 1287 |
1284 def parse_buf(self): | 1288 def parse_buf(self): |
1297 if match: | 1301 if match: |
1298 h, m, s = map(string.atoi, match.groups()) | 1302 h, m, s = map(string.atoi, match.groups()) |
1299 tail = h*3600+m*60+s | 1303 tail = h*3600+m*60+s |
1300 head = max(self.length, tail) - tail | 1304 head = max(self.length, tail) - tail |
1301 self.set_position(head, head+tail, [head, tail]) | 1305 self.set_position(head, head+tail, [head, tail]) |
1306 | |
1307 # ------------------------------------------ | |
1308 class TimeOffsetMplayer(Player): | |
1309 re_progress = re.compile("A: *(\d+)") | |
1310 | |
1311 def parse_buf(self): | |
1312 match = self.re_progress.search(self.buf) | |
1313 if match: | |
1314 head = string.atoi(match.groups()[0]) | |
1315 tail = max(self.length, head) - head | |
1316 self.set_position(head, head+tail, [head, tail]) | |
1317 | |
1318 def setlength(self): | |
1319 while 1: | |
1320 self.buf = os.read(self.stdout_r, 512) | |
1321 re_length = re.compile("ID_LENGTH=(\d+)") | |
1322 match = re_length.search(self.buf) | |
1323 if match: | |
1324 self.length = string.atoi(match.groups()[0]) | |
1325 break | |
1302 | 1326 |
1303 # ------------------------------------------ | 1327 # ------------------------------------------ |
1304 class NoOffsetPlayer(Player): | 1328 class NoOffsetPlayer(Player): |
1305 | 1329 |
1306 def parse_buf(self): | 1330 def parse_buf(self): |
1506 try: | 1530 try: |
1507 import ossaudiodev | 1531 import ossaudiodev |
1508 mixer = ossaudiodev.openmixer() | 1532 mixer = ossaudiodev.openmixer() |
1509 get, set = mixer.get, mixer.set | 1533 get, set = mixer.get, mixer.set |
1510 self.channels = self.channels or \ | 1534 self.channels = self.channels or \ |
1511 [['MASTER', ossaudiodev.SOUND_MIXER_VOLUME], | 1535 [['PCM', ossaudiodev.SOUND_MIXER_PCM], |
1512 ['PCM', ossaudiodev.SOUND_MIXER_PCM]] | 1536 ['MASTER', ossaudiodev.SOUND_MIXER_VOLUME]] |
1513 except ImportError: | 1537 except ImportError: |
1514 import oss | 1538 import oss |
1515 mixer = oss.open_mixer() | 1539 mixer = oss.open_mixer() |
1516 get, set = mixer.read_channel, mixer.write_channel | 1540 get, set = mixer.read_channel, mixer.write_channel |
1517 self.channels = self.channels or \ | 1541 self.channels = self.channels or \ |
1518 [['MASTER', oss.SOUND_MIXER_VOLUME], | 1542 [['PCM', oss.SOUND_MIXER_PCM], |
1519 ['PCM', oss.SOUND_MIXER_PCM]] | 1543 ['MASTER', oss.SOUND_MIXER_VOLUME]] |
1520 if cmd is "toggle": self.channels.insert(0, self.channels.pop()) | 1544 if cmd is "toggle": self.channels.insert(0, self.channels.pop()) |
1521 name, channel = self.channels[0] | 1545 name, channel = self.channels[0] |
1522 if cmd is "cue": arg = min(100, max(0, get(channel)[0] + arg)) | 1546 if cmd is "cue": arg = min(100, max(0, get(channel)[0] + arg)) |
1523 if cmd in ["set", "cue"]: set(channel, (arg, arg)) | 1547 if cmd in ["set", "cue"]: set(channel, (arg, arg)) |
1524 app.status(_("%s volume %s%%") % (name, get(channel)[0]), 1) | 1548 app.status(_("%s volume %s%%") % (name, get(channel)[0]), 1) |
1625 import traceback | 1649 import traceback |
1626 traceback.print_exc() | 1650 traceback.print_exc() |
1627 | 1651 |
1628 # ------------------------------------------ | 1652 # ------------------------------------------ |
1629 PLAYERS = [ | 1653 PLAYERS = [ |
1654 TimeOffsetMplayer("mplayer -vo null -identify -ss %d %s", "(^http://|\.(mp[1-4]|flv|mkv|m4a)$)"), | |
1630 FrameOffsetPlayer("ogg123 -q -v -k %d %s", "\.ogg$"), | 1655 FrameOffsetPlayer("ogg123 -q -v -k %d %s", "\.ogg$"), |
1631 FrameOffsetPlayer("splay -f -k %d %s", "(^http://|\.mp[123]$)", 38.28), | 1656 FrameOffsetPlayer("splay -f -k %d %s", "(^http://|\.mp[123]$)", 38.28), |
1632 FrameOffsetPlayer("mpg123 -q -v -k %d %s", "(^http://|\.mp[123]$)", 38.28), | 1657 FrameOffsetPlayer("mpg123 -q -v -k %d %s", "(^http://|\.mp[123]$)", 38.28), |
1633 FrameOffsetPlayer("mpg321 -q -v -k %d %s", "(^http://|\.mp[123]$)", 38.28), | 1658 FrameOffsetPlayer("mpg321 -q -v -k %d %s", "(^http://|\.mp[123]$)", 38.28), |
1634 TimeOffsetPlayer("madplay -v --display-time=remaining -s %d %s", "\.mp[123]$"), | 1659 TimeOffsetPlayer("madplay -v --display-time=remaining -s %d %s", "\.mp[123]$"), |