Exemplo n.º 1
0
Arquivo: xmms2.py Projeto: sahib/lyvi
    def get_status(self):
        data = {'artist': None, 'album': None, 'title': None, 'file': None, 'state': 'play', 'length': None}
        try:
            data['state'], data['artist'], data['album'], data['title'], data['file'], data['length'] = \
                    check_output('xmms2 current -f \'${playback_status}|${artist}|${album}|${title}|${url}|${duration}\' 2> /dev/null').split('|')
        except ValueError:
            return

        data['state'] = (data['state']
                .replace('Playing', 'play')
                .replace('Paused', 'pause')
                .replace('Stopped', 'stop'))

        # unquote_plus replaces % not as plus signs but as spaces (url decode)
        data['file'] = (urllib.parse.unquote_plus(data['file']).strip()
                .replace('\'', '')
                .replace("file://", ""))

        try:
            data['length'] = int(data['length'].split(':')[0]) * 60 + int(data['length'].split(':')[1])
        except ValueError:
            data['length'] = None

        for k in data:
            setattr(self, k, data[k])
Exemplo n.º 2
0
    def get_status(self):
        data = {
            'artist': None,
            'album': None,
            'title': None,
            'file': None,
            'length': None
        }

        for line in check_output('mocp -i').splitlines():
            info_value = self.get_info_value(line)
            if line.startswith('State: '):
                data['state'] = info_value.lower()
            elif line.startswith('Artist: '):
                data['artist'] = info_value
            elif line.startswith('Album: '):
                data['album'] = info_value
            elif line.startswith('SongTitle: '):
                data['title'] = info_value
            elif line.startswith('File: '):
                data['file'] = info_value
            elif line.startswith('TotalSec: '):
                data['length'] = int(info_value or '0')

        for k in data:
            setattr(self, k, data[k])
Exemplo n.º 3
0
    def get_status(self):
        data = {
            'artist': None,
            'album': None,
            'title': None,
            'file': None,
            'state': 'play',
            'length': None
        }
        try:
            data['state'], data['artist'], data['album'], data['title'], data['file'], data['length'] = \
                check_output('xmms2 current -f \'${playback_status}|${artist}|${album}|${title}|${url}|${duration}\'').split('|')
        except ValueError:
            return

        for x, y in (('Playing', 'play'), ('Paused', 'pause'), ('Stopped',
                                                                'stop')):
            data['state'] = data['state'].replace(x, y)

        # unquote_plus replaces % not as plus signs but as spaces (url decode)
        data['file'] = unquote_plus(data['file']).strip()
        for x, y in (('\'', ''), ('file://', '')):
            data['file'] = data['file'].replace(x, y)

        try:
            data['length'] = int(data['length'].split(':')[0]) * 60 + int(
                data['length'].split(':')[1])
        except ValueError:
            data['length'] = None

        for k in data:
            setattr(self, k, data[k])
Exemplo n.º 4
0
    def get_status(self):
        data = {
            'artist': None,
            'album': None,
            'title': None,
            'file': None,
            'length': None
        }

        for line in check_output('cmus-remote -Q').splitlines():
            if line.startswith('status '):
                data['state'] = (line.split()[1]
                                 or '').replace('playing', 'play')
                for x, y in (('playing', 'play'), ('paused', 'pause'),
                             ('stopped', 'stop')):
                    data['state'] = data['state'].replace(x, y)
            elif line.startswith('tag artist '):
                data['artist'] = self.get_info_value(line, 2)
            elif line.startswith('tag album '):
                data['album'] = self.get_info_value(line, 2)
            elif line.startswith('tag title '):
                data['title'] = self.get_info_value(line, 2)
            elif line.startswith('file '):
                data['file'] = self.get_info_value(line, 1)
            elif line.startswith('duration '):
                data['length'] = int(self.get_info_value(line, 1) or '0')

        for k in data:
            setattr(self, k, data[k])
Exemplo n.º 5
0
 def _get_layout(self):
     """Return a list containing Pane instances representing all tmux panes."""
     display = check_output('tmux display -p \'#{window_layout}\'')
     for delim in '[]{}':
         display = display.replace(delim, ',')
     layout = [self.Pane()]
     layout[0].w, layout[0].h = (int(a) for a in display.split(',')[1].split('x'))
     display = display.split(',', 1)[1]
     chunks = display.split(',')
     for i in range(0, len(chunks) - 1):
         if 'x' in chunks[i] and 'x' not in chunks[i + 3]:
             layout.append(self.Pane())
             layout[-1].w, layout[-1].h = (int(a) for a in chunks[i].split('x'))
             layout[-1].x = int(chunks[i + 1])
             layout[-1].y = int(chunks[i + 2])
     lsp = check_output('tmux lsp').splitlines()
     for chunk in lsp:
         layout[lsp.index(chunk) + 1].active = 'active' in chunk
     return layout
Exemplo n.º 6
0
 def _get_layout(self):
     """Return a list containing Pane instances representing all tmux panes."""
     display = check_output('tmux display -p \'#{window_layout}\'')
     for delim in '[]{}':
         display = display.replace(delim, ',')
     layout = [self.Pane()]
     layout[0].w, layout[0].h = (int(a) for a in display.split(',')[1].split('x'))
     display = display.split(',', 1)[1]
     chunks = display.split(',')
     for i in range(0, len(chunks) - 1):
         if 'x' in chunks[i] and 'x' not in chunks[i + 3]:
             layout.append(self.Pane())
             layout[-1].w, layout[-1].h = (int(a) for a in chunks[i].split('x'))
             layout[-1].x = int(chunks[i + 1])
             layout[-1].y = int(chunks[i + 2])
     lsp = check_output('tmux lsp').splitlines()
     for chunk in lsp:
         layout[lsp.index(chunk) + 1].active = 'active' in chunk
     return layout
Exemplo n.º 7
0
 def _get_size_px(self):
     """Return a tuple (width, height) with the tmux window dimensions in px."""
     while(True):
         # Use xwininfo command to get the window dimensions
         info = check_output('xwininfo -name ' + lyvi.config['bg_tmux_window_title'])
         try:
             width = int(info.split('Width: ')[1].split('\n')[0])
             height = int(info.split('Height: ')[1].split('\n')[0])
         except IndexError:
             continue
         else:
             return width, height
Exemplo n.º 8
0
 def _get_size_px(self):
     """Return a tuple (width, height) with the tmux window dimensions in px."""
     while(True):
         # Use xwininfo command to get the window dimensions
         info = check_output('xwininfo -name ' + lyvi.config['bg_tmux_window_title'])
         try:
             width = int(info.split('Width: ')[1].split('\n')[0])
             height = int(info.split('Height: ')[1].split('\n')[0])
         except IndexError:
             continue
         else:
             return width, height
Exemplo n.º 9
0
    def get_status(self):
        data = {'artist': None, 'album': None, 'title': None, 'file': None, 'length': None}

        for line in check_output('mocp -i').splitlines():
            if line.startswith('State: '):
                data['state'] = line.split()[1].lower()
            elif line.startswith('Artist: '):
                data['artist'] = line.split(maxsplit=1)[1]
            elif line.startswith('Album: '):
                data['album'] = line.split(maxsplit=1)[1]
            elif line.startswith('SongTitle: '):
                data['title'] = line.split(maxsplit=1)[1]
            elif line.startswith('File: '):
                data['file'] = line.split(maxsplit=1)[1]
            elif line.startswith('TotalSec: '):
                data['length'] = int(line.split(maxsplit=1)[1])

        for k in data:
            setattr(self, k, data[k])
Exemplo n.º 10
0
    def get_status(self):
        data = {'artist': None, 'album': None, 'title': None, 'file': None, 'length': None}

        for line in check_output('mocp -i').splitlines():
            info_value = self.get_info_value(line)
            if line.startswith('State: '):
                data['state'] = info_value.lower()
            elif line.startswith('Artist: '):
                data['artist'] = info_value or ''
            elif line.startswith('Album: '):
                data['album'] = info_value or ''
            elif line.startswith('SongTitle: '):
                data['title'] = info_value or ''
            elif line.startswith('File: '):
                data['file'] = info_value
            elif line.startswith('TotalSec: '):
                data['length'] = int(info_value)

        for k in data:
            setattr(self, k, data[k])
Exemplo n.º 11
0
Arquivo: cmus.py Projeto: sahib/lyvi
    def get_status(self):
        data = {'artist': None, 'album': None, 'title': None, 'file': None, 'length': None}

        for line in check_output('cmus-remote -Q').splitlines():
            if line.startswith('status '):
                data['state'] = (line.split()[1].replace('playing', 'play')
                        .replace('paused', 'pause')
                        .replace('stopped', 'stop'))
            elif line.startswith('tag artist '):
                data['artist'] = line.split(' ', 2)[2]
            elif line.startswith('tag album '):
                data['album'] = line.split(' ', 2)[2]
            elif line.startswith('tag title '):
                data['title'] = line.split(' ', 2)[2]
            elif line.startswith('file '):
                data['file'] = line.split(' ', 1)[1]
            elif line.startswith('duration '):
                data['length'] = int(line.split(' ', 1)[1])

        for k in data:
            setattr(self, k, data[k])
Exemplo n.º 12
0
    def get_status(self):
        data = {'artist': None, 'album': None, 'title': None, 'file': None, 'length': None}

        for line in check_output('cmus-remote -Q').splitlines():
            if line.startswith('status '):
                data['state'] = (line.split()[1] or '').replace('playing', 'play')
                for x, y in (('playing', 'play'), ('paused', 'pause'), ('stopped', 'stop')):
                    data['state'] = data['state'].replace(x, y)
            elif line.startswith('tag artist '):
                data['artist'] = self.get_info_value(line, 2)
            elif line.startswith('tag album '):
                data['album'] = self.get_info_value(line, 2)
            elif line.startswith('tag title '):
                data['title'] = self.get_info_value(line, 2)
            elif line.startswith('file '):
                data['file'] = self.get_info_value(line, 1)
            elif line.startswith('duration '):
                data['length'] = int(self.get_info_value(line, 1) or '0')

        for k in data:
            setattr(self, k, data[k])
Exemplo n.º 13
0
Arquivo: moc.py Projeto: sahib/lyvi
    def get_status(self):
        data = {'artist': None, 'album': None, 'title': None, 'file': None, 'length': None}

        for line in check_output('mocp -i 2> /dev/null').splitlines():
            if line.startswith('State: '):
                data['state'] = (line.split()[1]
                        .replace('PLAY', 'play')
                        .replace('PAUSE', 'pause')
                        .replace('STOP', 'stop'))
            elif line.startswith('Artist: '):
                data['artist'] = line.split(' ', 1)[1]
            elif line.startswith('Album: '):
                data['album'] = line.split(' ', 1)[1]
            elif line.startswith('SongTitle: '):
                data['title'] = line.split(' ', 1)[1]
            elif line.startswith('File: '):
                data['file'] = line.split(' ', 1)[1]
            elif line.startswith('TotalSec: '):
                data['length'] = int(line.split(' ', 1)[1])

        for k in data:
            setattr(self, k, data[k])
Exemplo n.º 14
0
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The F**k You Want To Public License, Version 2,
# as published by Sam Hocevar. See the COPYING file for more details.
"""Classes for normal and Tmux backgrounds."""

import os
import sys
from io import BytesIO

from PIL import Image

import lyvi
from lyvi.utils import check_output

# Get the terminal background color from the 'xrdb' command
for line in check_output('xrdb -query').splitlines():
    if 'background' in line:
        BG_COLOR = line.split(':')[1].strip()
        break
else:
    BG_COLOR = '#FFFFFF'


def pil_image(image):
    """Return the initialized Image class.

    Keyword arguments:
    image -- bytes or Image instance
    """
    if isinstance(image, bytes):
        buf = BytesIO(image)
Exemplo n.º 15
0
# as published by Sam Hocevar. See the COPYING file for more details.

"""Classes for normal and Tmux backgrounds."""


import os
from io import BytesIO

from PIL import Image

import lyvi
from lyvi.utils import check_output


# Get the terminal background color from the 'xrdb' command
for line in check_output('xrdb -query').splitlines():
    if 'background' in line:
        BG_COLOR = line.split(':')[1].strip()
        break
else:
    BG_COLOR = '#FFFFFF'


def pil_image(image):
    """Return the initialized Image class.

    Keyword arguments:
    image -- bytes or Image instance
    """
    if isinstance(image, bytes):
        buf = BytesIO(image)