From 0988eed2c89eaf81042c0feae34666ffc711f4d9 Mon Sep 17 00:00:00 2001 From: Aditya Mehra Date: Fri, 4 May 2018 00:34:12 +0930 Subject: [PATCH 1/4] Update to 18.02 --- __init__.py | 193 +++++++++++++++++++++++++++++--------------------- settings.json | 1 + 2 files changed, 112 insertions(+), 82 deletions(-) create mode 100644 settings.json diff --git a/__init__.py b/__init__.py index 8bdbc6b..a2564b3 100644 --- a/__init__.py +++ b/__init__.py @@ -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() diff --git a/settings.json b/settings.json new file mode 100644 index 0000000..b556862 --- /dev/null +++ b/settings.json @@ -0,0 +1 @@ +{"__mycroft_skill_firstrun": false} \ No newline at end of file From db58dcec4da78aa05c75bcdc23001e0776804a75 Mon Sep 17 00:00:00 2001 From: Aditya Mehra Date: Fri, 4 May 2018 01:10:38 +0930 Subject: [PATCH 2/4] Update README.md --- README.md | 50 ++++++++++++++------------------------------------ 1 file changed, 14 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index af9b788..86891a0 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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] From 7d3aae691449ca5ea95e8ba0c454b631c89e5c86 Mon Sep 17 00:00:00 2001 From: Aditya Mehra Date: Fri, 4 May 2018 01:12:55 +0930 Subject: [PATCH 3/4] Create requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..555438c --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +dbus-python From 6b70bcc373ab82f87c34e52b8781b92344067791 Mon Sep 17 00:00:00 2001 From: Aditya Mehra Date: Fri, 4 May 2018 02:37:49 +0930 Subject: [PATCH 4/4] Add system deps --- requirements.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 requirements.sh diff --git a/requirements.sh b/requirements.sh new file mode 100755 index 0000000..47417ab --- /dev/null +++ b/requirements.sh @@ -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 $?