Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 14 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# mycroft-amarok-player-plasma-skill
This skill integrates Amarok Music Player with Mycroft which enables users to Play Local Music.
## Amarok-Player-Skill
This skill integrates Amarok Music Player with Mycroft which enables users to Play Local Music.

## Description

#### Installation of skill:
* Download or Clone Git
* Create /opt/mycroft/skills folder if it does not exist
* Extract Downloaded Skill into a folder. "mycroft-amarok-player-plasma-skill". (Clone does not require this step)
* Copy the mycroft-internals-plasma-skill folder to /opt/mycroft/skills/ folder
* Extract Downloaded Skill into a folder. "amarok-player-skill". (Clone does not require this step)
* Copy the amarok-player-skill folder to /opt/mycroft/skills/ folder

#### Installation of requirements:
##### Fedora:
Expand All @@ -23,36 +25,12 @@ This skill integrates Amarok Music Player with Mycroft which enables users to Pl
* For other distributions:
- Python Dbus and Python Psutil package is required and copying the Python Dbus folder and lib from your system python install over to /home/$USER/.virtualenvs/mycroft/lib/python2.7/site-packages/.

##### How To Use:
###### Play Music/Song
- "Hey Mycroft, amarock play music"
- "Hey Mycroft, amarock play song"

###### Pause Music/Song
- "Hey Mycroft, amarock pause music"
- "Hey Mycroft, amarock pause song"

###### Stop Music/Song
- "Hey Mycroft, amarock stop music"
- "Hey Mycroft, amarock stop song"

###### Next Song
- "Hey Mycroft, amarock next song"

###### Previous Song
- "Hey Mycroft, amarock previous song"

## Current state

Working features:
* Play Music
* Pause Music
* Stop Music
* Next Song
* Previous Song

Known issues:
* None
## Examples
* "Amarok play music"
* "Amarok stop music"
* "Amarok next song"
* "Amarok previous song"
* "Amarok pause music/song"

TODO:
* None
## Credits
Aix [Github: https://github.com/AIIX]
193 changes: 111 additions & 82 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,109 +1,138 @@
import sys
import dbus
import glib
"""
Amarok Player Mycroft Skill.
"""

import os
import psutil
from traceback import print_exc
from os.path import dirname
import dbus
import psutil
from adapt.intent import IntentBuilder
from mycroft.skills.core import MycroftSkill
from mycroft.util.log import getLogger
from mycroft.skills.core import MycroftSkill, intent_handler

__author__ = 'aix'

LOGGER = getLogger(__name__)

class AmarokMusicPlayerSkill(MycroftSkill):

# The constructor of the skill, which calls MycroftSkill's constructor
class AmarokSkill(MycroftSkill):
"""
Amarok Skill Class.
"""

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
"""
Initialization.
"""
super(AmarokSkill, self).__init__(name="AmarokSkill")

@intent_handler(IntentBuilder("AmarokPlayKeywordIntent")
.require("AmarokPlayKeyword").build())
def handle_internals_amarok_play_skill_intent(self):
"""
Amarok Play Music
"""
self.speak_dialog("amarok.play")
amarok_running = False

for proc in psutil.process_iter():
pinfo = proc.as_dict(attrs=['pid', 'name'])
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):
amarok_running = True

if amarok_running:
def runplay():
"""
Amarok Skip Run Then Play
"""
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():
"""
Amarok Run First Then Play
"""
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()

@intent_handler(IntentBuilder("AmarokStopKeywordIntent")
.require("AmarokStopKeyword").build())
def handle_internals_amarok_stop_skill_intent(self):
"""
Amarok Stop Music
"""
bus = dbus.SessionBus()
remote_object = bus.get_object("org.mpris.MediaPlayer2.amarok","/org/mpris/MediaPlayer2")
remote_object.Stop(dbus_interface = "org.mpris.MediaPlayer2.Player")

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):

@intent_handler(IntentBuilder("AmarokNextKeywordIntent")
.require("AmarokNextKeyword").build())
def handle_internals_amarok_next_skill_intent(self):
"""
Amarok Next Song
"""
bus = dbus.SessionBus()
remote_object = bus.get_object("org.mpris.MediaPlayer2.amarok","/org/mpris/MediaPlayer2")
remote_object.Next(dbus_interface = "org.mpris.MediaPlayer2.Player")

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):


@intent_handler(IntentBuilder("AmarokPreviousKeywordIntent")
.require("AmarokPreviousKeyword").build())
def handle_internals_amarok_previous_skill_intent(self):
"""
Amarok Previous Song
"""
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")
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):

@intent_handler(IntentBuilder("AmarokPauseKeywordIntent")
.require("AmarokPauseKeyword").build())
def handle_internals_amarok_pause_skill_intent(self):
"""
Amarok Pause Song
"""
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")

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):
"""
Mycroft Stop Function
"""
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()
"""
Mycroft Create Skill Function
"""
return AmarokSkill()
20 changes: 20 additions & 0 deletions requirements.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
# Find our package manager
if VERB="$( which apt-get )" 2> /dev/null; then
echo "Installing libdbus-1-dev libdbus-glib-1-dev"
sudo apt install -y libdbus-1-dev libdbus-glib-1-dev
elif VERB="$( which dnf )" 2> /dev/null; then
echo "Installing dbus-devel dbus-glib-devel"
sudo dnf install -y dbus-devel dbus-glib-devel
elif VERB="$( which zypper )" 2> /dev/null; then
echo "Installing dbus-devel dbus-glib-devel"
sudo zypper install -y dbus-devel dbus-glib-devel
else
echo "Package Manager Not Found." >&2
exit 1
fi
if [[ 1 -ne $# ]]; then
exit 1
fi
$VERB "$1"
exit $?
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dbus-python
1 change: 1 addition & 0 deletions settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"__mycroft_skill_firstrun": false}