summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2022-06-15 12:05:51 -0500
committerHombreLaser <sebastian-440@live.com>2022-06-15 12:05:51 -0500
commite07e82b9dd93c97e53521f9fcdc967febf8d0eeb (patch)
treeadd66fb450082b2cdcf6811ea8711d3463ea8a7c
parent71a2a3fd8b13f6c3e942df5e68bb56e5aad50c2f (diff)
Added bot's code
-rw-r--r--src/ampache/client.py (renamed from src/ampache/ampache.py)0
-rw-r--r--src/bot.py62
-rw-r--r--src/config.py23
-rw-r--r--src/main.py24
4 files changed, 94 insertions, 15 deletions
diff --git a/src/ampache/ampache.py b/src/ampache/client.py
index b58ba36..b58ba36 100644
--- a/src/ampache/ampache.py
+++ b/src/ampache/client.py
diff --git a/src/bot.py b/src/bot.py
new file mode 100644
index 0000000..9b10736
--- /dev/null
+++ b/src/bot.py
@@ -0,0 +1,62 @@
+from config import Config
+from ampache.client import AmpacheClient
+from collections import deque
+import pymumble_py3 as pymumble
+
+class Bot:
+ """
+ The bot class. It reads a config file (given in the constructor)
+ and with it populates its own and the ampache client's variables.
+ """
+ def __init__(self, config_file):
+ # The file may not exist. If it doesn't, the configparser will
+ # throw a key error exception. TODO: first open the file, if
+ # it doesn't exist it will throw a more ad hoc exception.
+ self._configuration = Config(config_file)
+ self._playlist = deque()
+ self._init_client()
+ self._init_bot()
+ self._init_misc()
+
+ def _init_misc(self):
+ miscellaneous = self._configuration.get_directories()
+ self._download_dir = miscellaneous[0]
+ self._automatically_delete = miscellaneous[1]
+
+ def _init_client(self):
+ client_info = self._configuration.get_ampache_config()
+ auth_info = self._configuration.get_auth()
+ self._client = AmpacheClient(client_info[0], auth_info,
+ client_info[1])
+
+ def _init_bot(self):
+ mumble_info = self._configuration.get_mumble_config()
+ host = mumble_info[0]
+ password = mumble_info[1]
+ certfile = mumble_info[2]
+ keyfile = mumble_info[3]
+ bot_nick = mumble_info[4]
+ self._bot = pymumble.Mumble(host, bot_nick, password=password, certfile=certfile,
+ keyfile=keyfile, reconnect=True, stereo=True)
+
+ def read_command(self):
+ pass
+
+ def parse_command(self):
+ pass
+
+ def add_to_playlist(self, ):
+ pass
+
+ def play_song(self, ):
+ pass
+
+ # API methods.
+ def query_song(self, song_id):
+ pass
+
+ def query_album(self, album_id):
+ pass
+
+ def download_song(self):
+ pass
diff --git a/src/config.py b/src/config.py
index 4191c4d..0c4916d 100644
--- a/src/config.py
+++ b/src/config.py
@@ -2,15 +2,26 @@ import configparser
class Config:
"""
- A cconfig reader class.
+ A config reader class.
"""
def __init__(self, config_file):
self._parser = configparser.ConfigParser()
self._parser.read(config_file)
- def get_server_config(self):
- host = self._parser['Server']['host']
- version = self._parser['Server']['api_version']
+ # Mumble config
+ def get_mumble_config(self, ):
+ host = self._parser['MumbleServer']['host']
+ password = self._parser['MumbleServer']['password']
+ certfile = self._parser['MumbleServer']['certfile']
+ keyfile = self._parser['MumbleServer']['keyfile']
+ name = self._parser['MumbleServer']['name']
+
+ return (host, password, certfile, keyfile, name)
+
+ # Ampache config
+ def get_ampache_config(self):
+ host = self._parser['AmpacheServer']['host']
+ version = self._parser['AmpacheServer']['api_version']
return (host, version)
@@ -20,8 +31,8 @@ class Config:
return auth
def get_directories(self):
- download = self._parser['Directories']['download_folder']
- delete_after_playing = bool(self._parser['Directories']
+ download = self._parser['Misc']['download_folder']
+ delete_after_playing = bool(self._parser['Misc']
['delete_after_playing'])
return (download, delete_after_playing)
diff --git a/src/main.py b/src/main.py
index 118434b..4a87586 100644
--- a/src/main.py
+++ b/src/main.py
@@ -1,16 +1,22 @@
-import ampache
+from config import Config
import pymumble_py3 as pymumble
+from ampache.client import AmpacheClient
+# def main():
+# example_bot = pymumble.Mumble('192.168.15.18', 'ampache', password='cultoblandonianoEXTREME', certfile='../ampache.pem', keyfile='../ampachekey.pem',
+# reconnect=True, stereo=True)
+# example_bot.set_application_string('ampache-client')
+# example_bot.start()
+# example_bot.is_ready()
+# example_bot.set_loop_rate(.01)
+
+# while True:
+# continue
def main():
- example_bot = pymumble.Mumble('192.168.15.18', 'ampache', password='cultoblandonianoEXTREME', certfile='../ampache.pem', keyfile='../ampachekey.pem',
- reconnect=True, stereo=True)
- example_bot.set_application_string('ampache-client')
- example_bot.start()
- example_bot.is_ready()
- example_bot.set_loop_rate(.01)
+ config = Config('../example.cfg')
+ client = AmpacheClient('https://music.silosneeded.com', '4dee7fe5554cf581a3f69ea023ea378a', 53200)
- while True:
- continue
+ return 0
if __name__ == '__main__':