|
Revision 2266, 1.3 kB
(checked in by mattn, 5 years ago)
|
|
lang/python/otolog4linux: initial import.
|
| Line | |
|---|
| 1 | #!/usr/bin/python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | import os |
|---|
| 4 | import sys |
|---|
| 5 | import string |
|---|
| 6 | |
|---|
| 7 | __author__ = 'Yasuhiro Matsumoto <mattn.jp@gmail.com>' |
|---|
| 8 | |
|---|
| 9 | def get_capability(): |
|---|
| 10 | return ['player'] |
|---|
| 11 | |
|---|
| 12 | def get_name(): |
|---|
| 13 | return 'mpc' |
|---|
| 14 | |
|---|
| 15 | # should be return supported version. |
|---|
| 16 | def get_version(): return '0.11.2' |
|---|
| 17 | |
|---|
| 18 | def play(): |
|---|
| 19 | file = os.popen('mpc play') |
|---|
| 20 | res = file.readline()[:-1] |
|---|
| 21 | file.close() |
|---|
| 22 | print res |
|---|
| 23 | |
|---|
| 24 | def stop(): |
|---|
| 25 | file = os.popen('mpc stop') |
|---|
| 26 | res = file.readline()[:-1] |
|---|
| 27 | file.close() |
|---|
| 28 | print res |
|---|
| 29 | |
|---|
| 30 | def pause(): |
|---|
| 31 | sys.stderr.write('mpc pause\n') |
|---|
| 32 | |
|---|
| 33 | def next(): |
|---|
| 34 | file = os.popen('mpc next') |
|---|
| 35 | res = file.readline()[:-1] |
|---|
| 36 | file.close() |
|---|
| 37 | print res |
|---|
| 38 | |
|---|
| 39 | def prev(): |
|---|
| 40 | file = os.popen('mpc prev') |
|---|
| 41 | res = file.readline()[:-1] |
|---|
| 42 | file.close() |
|---|
| 43 | print res |
|---|
| 44 | |
|---|
| 45 | def get_info(settings): |
|---|
| 46 | info = {} |
|---|
| 47 | try: |
|---|
| 48 | # Check kscd is working |
|---|
| 49 | file = os.popen('mpc status --format "%album%\t%artist%\t%title%\t%time%"') |
|---|
| 50 | lines = file.read().split('\n') |
|---|
| 51 | file.close() |
|---|
| 52 | print lines |
|---|
| 53 | if len(lines) > 2: |
|---|
| 54 | if lines[1][0:9] == "[playing]": |
|---|
| 55 | info['status'] = True |
|---|
| 56 | else: |
|---|
| 57 | info['status'] = False |
|---|
| 58 | else: |
|---|
| 59 | return None |
|---|
| 60 | songinfo = lines[0].split('\t') |
|---|
| 61 | info['album'] = songinfo[0] |
|---|
| 62 | info['artist'] = songinfo[1] |
|---|
| 63 | info['track'] = songinfo[2] |
|---|
| 64 | dur = songinfo[3].split(':') |
|---|
| 65 | info['duration'] = int(dur[0])*60+int(dur[1]) |
|---|
| 66 | except Exception, e: |
|---|
| 67 | print(e) |
|---|
| 68 | return info |
|---|
| 69 | |
|---|