-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
85 lines (69 loc) · 3.03 KB
/
__init__.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
from mycroft import MycroftSkill, intent_handler
from mycroft.util.log import LOG
from mycroft.audio.services.vlc import VlcService
import re
import time
class StreamPlayer(MycroftSkill):
def __init__(self):
MycroftSkill.__init__(self)
url = ''
mediaplayer=''
@intent_handler('player.stream.intent')
def handle_stream_intent(self, message):
utterance = message.data.get('utterance')
# LOG.info(utterance)
instance = None
empty_record = 'empty_record'
url_record = 'junk'
count = 0
mediaplayer = None
while url_record != None and url_record != empty_record:
count = count + 1
stream_name = 'stream' + str(count)
url_record = self.settings.get(stream_name)
if url_record == None or url_record == empty_record:
...
if url_record == None:
print(" Returned: None")
else:
print(" Returned: " + empty_record)
...
continue
strings = url_record.split(",")
slen = len(strings)
if re.search(strings[0].lower(), utterance) or \
(slen > 2 and re.search(strings[2].lower(), utterance)):
if instance == None:
self.mediaplayer = VlcService(config={'low_volume': 10, 'duck': True})
if self.mediaplayer is None:
LOG.exception("VLC could not create an Instance")
break
#Play the media
self.url = strings[1]
self.speak_dialog("player.stream")
time.sleep(2.0)
tracklist = []
tracklist.append(self.url)
self.mediaplayer.add_list(tracklist)
self.mediaplayer.play()
break
# if we didn't find our station
if url_record == empty_record or url_record == None:
self.speak_dialog("player.settings")
# if there is no open record in the user's table, create one
if url_record == None:
f = open("skills/stream-player-skill/settingsmeta.yaml","a+")
f.write(" - name: stream%d\n" % count)
f.write(" type: text\n")
f.write(" label: Stream %d\n" % count)
f.write(" value: \"empty_record\"\n")
f.close()
@intent_handler('player.stop.intent')
def handle_stop_intent(self, message):
mystring = message.data.get('utterance')
LOG.info(mystring)
self.mediaplayer.stop()
self.mediaplayer.clear_list()
self.url = ''
def create_skill():
return StreamPlayer()