-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controller.py
executable file
·147 lines (113 loc) · 4.32 KB
/
Controller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python
#coding: utf-8
import xmmsclient
from xmmsclient import collections as cx
import os
class Controller(object):
"""A simple wrapper class of XMMSSync."""
def __init__(self, options):
self.c = xmmsclient.XMMSSync('Rokola')
try:
self.c.connect()
except IOError:
os.system('xmms2-launcher')
self.c.connect()
self.options = options
def is_playing(self):
return self.c.playback_status() == xmmsclient.PLAYBACK_STATUS_PLAY
def play(self, pos):
self.c.playlist_set_next(pos)
self.c.playback_start()
def play_start(self):
self.c.playback_start()
def add_idtopls(self,id):
self.c.playlist_add_id(id)
def delete(self, pos):
"""Remove a song from playlist.
#cambiar esto porque no se puede parar la musica
If the song to be removed is playing now, we first stop it.
"""
if self.is_playing():
if self.current_position() == pos:
self.c.playback_stop()
self.c.playlist_remove_entry(pos)
def stop(self):
self.c.playback_stop()
def load(self, name):
self.c.playlist_load(name)
def clear(self):
#self.c.playback_stop()
self.c.playlist_clear()
def current_position(self):
print self.c.playlist_current_pos()
"""Return current position in the playlist."""
# It is an error to call playlist_current_pos when there are
# no entries in the playlist.
try:
return self.c.playlist_current_pos()
except xmmsclient.XMMSError:
return None
def playlist(self):
"""Format the playlist.
First we try to get imformation from id3v2, if it fails,
then try id3, else we just display the file name.
"""
def iconv(s):
encoding = self.options["id3_encoding"]
if encoding:
return s.encode('latin1').decode(encoding).encode('utf-8')
else:
return s.encode('latin1')
lst = []
for id in self.c.playlist_list_entries():
song = self.c.medialib_get_info(id)
try:
artist = iconv(song[('plugin/id3v2', 'artist')])
except KeyError:
try:
artist = iconv(song[('plugin/mad', 'artist')])
except KeyError:
artist = ''
try:
title = iconv(song[('plugin/id3v2', 'title')])
except KeyError:
try:
title = iconv(song[('plugin/mad', 'title')])
except KeyError:
title = ''
if artist == "" and title == "":
name = os.path.split(song[('server', 'url')])[1]
name = os.path.splitext(name)[0]
name = urllib.unquote(name.decode('utf-8').encode('latin1'))
name = name.replace("+", " ")
lst.append(' ' + name)
else:
lst.append(' %s - %s' % (artist.ljust(6), title))
return lst
def get_coll_ids(self, collection):
res = self.c.coll_query_ids(collection)
return res
def get_current_mode(self):
res = self.c.playback_status()
return res
def get_coll_values(self, collection, fields):
res = self.c.coll_query_infos(collection, fields)
return res
def get_av_artist_list(self):
#res = self.c.coll_query_infos(coll=xmmsclient.xmmsapi.Universe(), fields=['artist'] )
res = self.c.coll_query_infos(coll=cx.Universe(), fields=['artist'], groupby=['artist'])
return res
# retrive bindata for given hash key
def get_bindata(self, hash):
res = self.c.bindata_retrive(hash)
return res.get_bin()
# create a collection that contains tracks of artist and album
def create_a_coll(self, artist):
print '------------- funcion create_a_coll-----------------'
m = cx.Match(field="artist", value=artist)
print m
ids = self.c.coll_query_ids(m)
print ids
infor = self.c.coll_query_infos(m, ["id","artist", "title" ])
print infor
return infor