|
@@ -2,8 +2,8 @@ import subprocess
|
|
|
import os
|
|
import os
|
|
|
import base
|
|
import base
|
|
|
import output
|
|
import output
|
|
|
-
|
|
|
|
|
-_FOLDER = '/mnt/nas/music/albums'
|
|
|
|
|
|
|
+import conf
|
|
|
|
|
+import input_sources
|
|
|
|
|
|
|
|
class Music(base.BaseService):
|
|
class Music(base.BaseService):
|
|
|
folders = None
|
|
folders = None
|
|
@@ -13,7 +13,7 @@ class Music(base.BaseService):
|
|
|
self.initialized = False
|
|
self.initialized = False
|
|
|
|
|
|
|
|
def init(self):
|
|
def init(self):
|
|
|
- folders = [unicode(os.path.join(_FOLDER, f).decode('utf-8')) for f in os.listdir(_FOLDER)]
|
|
|
|
|
|
|
+ folders = [unicode(os.path.join(conf.MUSIC_FOLDER, f).decode('utf-8')) for f in os.listdir(conf.MUSIC_FOLDER)]
|
|
|
folders = [f for f in folders if os.path.isdir(f)]
|
|
folders = [f for f in folders if os.path.isdir(f)]
|
|
|
self.folders = {os.path.basename(f).lower(): f for f in folders}
|
|
self.folders = {os.path.basename(f).lower(): f for f in folders}
|
|
|
self.initialized = True
|
|
self.initialized = True
|
|
@@ -27,7 +27,7 @@ class Music(base.BaseService):
|
|
|
t = t.lower()
|
|
t = t.lower()
|
|
|
eligible = {f: v for f, v in eligible.iteritems() if t in f}
|
|
eligible = {f: v for f, v in eligible.iteritems() if t in f}
|
|
|
|
|
|
|
|
- output.debug('tokens: %s; eligible: %s', tokens, eligible.keys())
|
|
|
|
|
|
|
+ output.debug('tokens: %s; eligible: %s' % (tokens, eligible.keys()))
|
|
|
if eligible:
|
|
if eligible:
|
|
|
return eligible[eligible.keys()[0]]
|
|
return eligible[eligible.keys()[0]]
|
|
|
|
|
|
|
@@ -37,15 +37,27 @@ class Music(base.BaseService):
|
|
|
self.current_process = None
|
|
self.current_process = None
|
|
|
|
|
|
|
|
def call(self):
|
|
def call(self):
|
|
|
- tokens = ears.listen(pause_threshold=3, preferred_phrases=self.folders.keys()[:300])
|
|
|
|
|
- f = self._search(tokens)
|
|
|
|
|
|
|
+ phrases = self.folders.keys()[:300]
|
|
|
|
|
|
|
|
- if f:
|
|
|
|
|
- output.debug('playing %s' % f)
|
|
|
|
|
- self.current_process = subprocess.Popen(['cvlc', '-Z', f, ])
|
|
|
|
|
|
|
+ tokens = []
|
|
|
|
|
+ while input_sources.token_available():
|
|
|
|
|
+ tokens.append(input_sources.get_token(0, preferred_phrases=phrases))
|
|
|
|
|
|
|
|
|
|
+ if not tokens:
|
|
|
|
|
+ output.failure('No play command specified.')
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+ if tokens[0] == 'stop':
|
|
|
|
|
+ self.stop()
|
|
|
|
|
+
|
|
|
else:
|
|
else:
|
|
|
- output.failure()
|
|
|
|
|
|
|
+ f = self._search(tokens)
|
|
|
|
|
+ if f:
|
|
|
|
|
+ output.debug('playing %s' % f)
|
|
|
|
|
+ self.current_process = subprocess.Popen(['cvlc', '-Z', f, ])
|
|
|
|
|
+
|
|
|
|
|
+ else:
|
|
|
|
|
+ output.failure()
|
|
|
|
|
|
|
|
def help(self):
|
|
def help(self):
|
|
|
return 'Plays music. Example: "play Coldplay".'
|
|
return 'Plays music. Example: "play Coldplay".'
|