コード例 #1
0
ファイル: mpdhelper.py プロジェクト: nhrx/mpdc
 def search(self, filtername, pattern):
     if filtername == 'extension':
         return [s for s in self.get_all_songs() if
                 s.lower().endswith(pattern.lower())]
     else:
         output = check_output(self.mpc_c + ['search', filtername, pattern])
         return format_mpc_output(output.decode())
コード例 #2
0
ファイル: mpdhelper.py プロジェクト: nhrx/mpdc
 def get_playlist_positions(self):
     positions = collections.defaultdict(list)
     output = check_output(self.mpc_c + ['-f', '%file% %position%',
                                         'playlist'])
     for line in format_mpc_output(output.decode()):
         song, position = line.rsplit(' ', 1)
         positions[song].append(int(position))
     return positions
コード例 #3
0
ファイル: mpdhelper.py プロジェクト: madjar/mpdc
 def get_playlist_positions(self):
     output = check_output(self.mpc_c + ['-f', '%file% %position%',
                                         'playlist'])
     lines = format_mpc_output(output.decode())
     positions = OrderedDict()
     for line in lines:
         song, position = line.rsplit(' ', 1)
         if song in positions:
             positions[song].append(int(position))
         else:
             positions[song] = [int(position)]
     return positions
コード例 #4
0
ファイル: parser.py プロジェクト: nhrx/mpdc
def p_expression_collection(p):
    'expression : COLLECTION'
    p[0] = OrderedSet()
    if p[1] in collectionsmanager.c:
        collection = collectionsmanager.c[p[1]]
        if 'expression' in collection:
            p[0] |= parser.parse(collection['expression'],
                    lexer=lex.lex(debug=0, reflags=re.UNICODE|re.IGNORECASE))
        if 'songs' in collection:
            p[0] |= OrderedSet(collection['songs'])
        if enable_command and 'command' in collection:
            try:
                output = subprocess.check_output(collection['command'],
                                                 shell=True)
                p[0] |= OrderedSet(format_mpc_output(output.decode()))
            except subprocess.CalledProcessError:
                warning('Error while executing `command` in collection [{}]'.
                        format(p[1]))
                sys.exit(0)
        if 'sort' in collection:
            p[0] = mpd.set_sort(p[0])
    elif p[1] == 'all':
        p[0] = OrderedSet(mpd.get_all_songs())
    elif p[1] == 'c':
        p[0] = OrderedSet(mpd.get_playlist_songs())
    elif p[1] == 'C':
        c_song = mpd.get_current_song()
        if c_song is not None:
            p[0] = OrderedSet([c_song])
    elif p[1] == 'A':
        c_song = mpd.get_current_song()
        if c_song is not None:
            p[0] = OrderedSet(mpd.find('artist',
                                       mpd.get_tag(c_song, 'artist')))
    elif p[1] == 'B':
        c_song = mpd.get_current_song()
        if c_song is not None:
            p[0] = OrderedSet(mpd.find_multiple(
                              albumartist=mpd.get_tag(c_song, 'albumartist'),
                              album=mpd.get_tag(c_song, 'album')))
            if not p[0]:
                p[0] = OrderedSet(mpd.find_multiple(
                                  artist=mpd.get_tag(c_song, 'artist'),
                                  album=mpd.get_tag(c_song, 'album')))
    else:
        warning('Collection [{}] does not exist'.format(p[1]))
        sys.exit(0)
コード例 #5
0
ファイル: parser.py プロジェクト: madjar/mpdc
def p_expression_collection(p):
    'expression : COLLECTION'
    if p[1] in collections:
        collection = collections[p[1]]
        p[0] = OrderedSet()
        if 'expression' in collection:
            p[0] |= p.parser.parse(collection['expression'],
                                   lexer=lex.lex(debug=0, reflags=re.UNICODE))
        if 'songs' in collection:
            p[0] |= OrderedSet(collection['songs'])
        if enable_command and 'command' in collection:
            try:
                output = check_output(collection['command'], shell=True)
                p[0] |= OrderedSet(format_mpc_output(output.decode()))
            except CalledProcessError:
                warning('Error while executing `command` in collection [%s]' %
                        p[1])
                sys.exit(0)
        if 'sort' in collection:
            p[0] = mpd.set_sort(p[0])

    elif p[1] == 'all':
        p[0] = OrderedSet(mpd.get_all_songs())
    elif p[1] == 'c':
        p[0] = OrderedSet(mpd.get_playlist_songs())
    elif p[1] == 'C':
        p[0] = OrderedSet([mpd.get_current_song()])
    elif p[1] == 'A':
        c_song = mpd.get_current_song()
        p[0] = OrderedSet(mpd.find('artist', mpd.get_tag(c_song, 'artist')))
    elif p[1] == 'B':
        c_song = mpd.get_current_song()
        p[0] = OrderedSet(mpd.find_multiple(
                                        artist=mpd.get_tag(c_song, 'artist'),
                                        album=mpd.get_tag(c_song, 'album')))
    else:
        warning('Collection [%s] doesn\'t exist' % p[1])
        sys.exit(0)
コード例 #6
0
ファイル: mpdhelper.py プロジェクト: nhrx/mpdc
 def get_playlist_songs(self):
     output = check_output(self.mpc_c + ['-f', '%file%', 'playlist'])
     return format_mpc_output(output.decode())
コード例 #7
0
ファイル: mpdhelper.py プロジェクト: nhrx/mpdc
 def list_artists(self):
     output = check_output(self.mpc_c + ['list', 'artist'])
     return format_mpc_output(output.decode())