-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from bjarneo/feature/commander
Commander
- Loading branch information
Showing
6 changed files
with
99 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
|
||
class Commander(): | ||
def __init__(self, Pytifylib): | ||
self.pytify = Pytifylib | ||
|
||
def parse(self, command): | ||
if command and command[0] != '/': | ||
return '' | ||
|
||
command = command.replace('/', '') | ||
|
||
return command | ||
|
||
def commands(self): | ||
return { | ||
'help': 'list all commands', | ||
'current': 'print current song (currently linux only)', | ||
'next': 'play next song', | ||
'prev': 'play previous song', | ||
'pp': 'play or pause song', | ||
'stop': 'stop', | ||
'history': 'last five search results' | ||
} | ||
|
||
def validate(self, command): | ||
for key in self.commands(): | ||
if command != key: | ||
continue | ||
|
||
return True | ||
|
||
return False | ||
|
||
def help(self): | ||
print('\nCommands:') | ||
|
||
for key, val in self.commands().items(): | ||
print(' {0:20} {1:75}'.format(key, val)) | ||
|
||
print('\n') | ||
|
||
def run(self, command): | ||
command = self.parse(command) | ||
|
||
if not command: | ||
return False | ||
|
||
if not self.validate(command): | ||
self.help() | ||
|
||
if command == 'help': | ||
self.help() | ||
|
||
elif command == 'current': | ||
print(self.pytify.get_current_playing()) | ||
|
||
elif command == 'next': | ||
self.pytify.next() | ||
|
||
elif command == 'prev': | ||
self.pytify.prev() | ||
|
||
elif command == 'pp': | ||
self.pytify.play_pause() | ||
|
||
elif command == 'stop': | ||
self.pytify.stop() | ||
|
||
elif command == 'history': | ||
self.pytify.print_history() | ||
|
||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from setuptools import setup | ||
|
||
__version__ = '3.1.5' | ||
__version__ = '3.3.0' | ||
|
||
setup( | ||
name='pytify', | ||
|