-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path__init__.py
109 lines (82 loc) · 4.47 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
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
import sys
import dbus
import glib
import os
import psutil
from traceback import print_exc
from os.path import dirname
from adapt.intent import IntentBuilder
from mycroft.skills.core import MycroftSkill
from mycroft.util.log import getLogger
__author__ = 'aix'
LOGGER = getLogger(__name__)
class AmarokMusicPlayerSkill(MycroftSkill):
# The constructor of the skill, which calls MycroftSkill's constructor
def __init__(self):
super(AmarokMusicPlayerSkill, self).__init__(name="AmarokMusicPlayerSkill")
# This method loads the files needed for the skill's functioning, and
# creates and registers each intent that the skill uses
def initialize(self):
self.load_data_files(dirname(__file__))
internals_amarok_play_skill_intent = IntentBuilder("AmarokPlayKeywordIntent").\
require("AmarokPlayKeyword").build()
self.register_intent(internals_amarok_play_skill_intent, self.handle_internals_amarok_play_skill_intent)
internals_amarok_stop_skill_intent = IntentBuilder("AmarokStopKeywordIntent").\
require("AmarokStopKeyword").build()
self.register_intent(internals_amarok_stop_skill_intent, self.handle_internals_amarok_stop_skill_intent)
internals_amarok_next_skill_intent = IntentBuilder("AmarokNextKeywordIntent").\
require("AmarokNextKeyword").build()
self.register_intent(internals_amarok_next_skill_intent, self.handle_internals_amarok_next_skill_intent)
internals_amarok_previous_skill_intent = IntentBuilder("AmarokPreviousKeywordIntent").\
require("AmarokPreviousKeyword").build()
self.register_intent(internals_amarok_previous_skill_intent, self.handle_internals_amarok_previous_skill_intent)
internals_amarok_pause_skill_intent = IntentBuilder("AmarokPauseKeywordIntent").\
require("AmarokPauseKeyword").build()
self.register_intent(internals_amarok_pause_skill_intent, self.handle_internals_amarok_pause_skill_intent)
def handle_internals_amarok_play_skill_intent(self, message):
self.speak_dialog("amarok.play")
amarokRunning = False
for proc in psutil.process_iter():
pinfo = proc.as_dict(attrs=['pid', 'name'])
if pinfo['name'] == 'amarok':
amarokRunning = True
if amarokRunning:
#print('yes')
def runplay():
bus = dbus.SessionBus()
remote_object = bus.get_object("org.mpris.MediaPlayer2.amarok","/org/mpris/MediaPlayer2")
remote_object.Play(dbus_interface = "org.mpris.MediaPlayer2.Player")
runplay()
else:
def runprocandplay():
os.system("amarok")
bus = dbus.SessionBus()
remote_object = bus.get_object("org.mpris.MediaPlayer2.amarok","/org/mpris/MediaPlayer2")
remote_object.Play(dbus_interface = "org.mpris.MediaPlayer2.Player")
runprocandplay()
def handle_internals_amarok_stop_skill_intent(self, message):
bus = dbus.SessionBus()
remote_object = bus.get_object("org.mpris.MediaPlayer2.amarok","/org/mpris/MediaPlayer2")
remote_object.Stop(dbus_interface = "org.mpris.MediaPlayer2.Player")
self.speak_dialog("amarok.stop")
def handle_internals_amarok_next_skill_intent(self, message):
bus = dbus.SessionBus()
remote_object = bus.get_object("org.mpris.MediaPlayer2.amarok","/org/mpris/MediaPlayer2")
remote_object.Next(dbus_interface = "org.mpris.MediaPlayer2.Player")
self.speak_dialog("amarok.next")
def handle_internals_amarok_previous_skill_intent(self, message):
bus = dbus.SessionBus()
remote_object = bus.get_object("org.mpris.MediaPlayer2.amarok","/org/mpris/MediaPlayer2")
remote_object.Previous(dbus_interface = "org.mpris.MediaPlayer2.Player")
self.speak_dialog("amarok.previous")
def handle_internals_amarok_pause_skill_intent(self, message):
bus = dbus.SessionBus()
remote_object = bus.get_object("org.mpris.MediaPlayer2.amarok","/org/mpris/MediaPlayer2")
remote_object.Pause(dbus_interface = "org.mpris.MediaPlayer2.Player")
self.speak_dialog("amarok.pause")
def stop(self):
pass
# The "create_skill()" method is used to create an instance of the skill.
# Note that it's outside the class itself.
def create_skill():
return AmarokMusicPlayerSkill()