From 1aeb72fd8f5cf3d128219fead9116b53867296ad Mon Sep 17 00:00:00 2001 From: krateng Date: Thu, 18 Mar 2021 18:58:53 +0100 Subject: [PATCH] Added Python library for music players / scrobblers --- README.md | 2 +- .../predefined/krateng_kpopgirlgroups.tsv | 5 ++++ malojalib/__init__.py | 27 +++++++++++++++++++ malojalib/__pkginfo__.py | 22 +++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 malojalib/__init__.py create mode 100644 malojalib/__pkginfo__.py diff --git a/README.md b/README.md index e8efd18..814727e 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ These solutions allow you to directly setup scrobbling to your Maloja server: If you want to implement your own method of scrobbling, it's very simple: You only need one POST request to `/apis/mlj_1/newscrobble` with the keys `artist`, `title` and `key` (and optionally `album`,`duration` (in seconds) and `time`(for cached scrobbles)) - either as form-data or json. -If you're the maintainer of a music player or server and would like to implement native Maloja scrobbling, feel free to reach out - I'll try my best to help. +If you're the maintainer of a music player or server and would like to implement native Maloja scrobbling, feel free to reach out - I'll try my best to help. For Python applications, you can simply use the [`malojalib` package](https://pypi.org/project/maloja-lib/) for a consistent interface even with future updates. ### Standard-compliant API diff --git a/maloja/data_files/config/rules/predefined/krateng_kpopgirlgroups.tsv b/maloja/data_files/config/rules/predefined/krateng_kpopgirlgroups.tsv index 7e859c9..182b411 100644 --- a/maloja/data_files/config/rules/predefined/krateng_kpopgirlgroups.tsv +++ b/maloja/data_files/config/rules/predefined/krateng_kpopgirlgroups.tsv @@ -168,6 +168,11 @@ replacetitle 달라달라 (DALLA DALLA) Dalla Dalla # K/DA belongtogether K/DA +# (G)I-DLE +countas Soyeon (G)I-DLE +countas Miyeon (G)I-DLE + + # 2NE1 countas CL 2NE1 diff --git a/malojalib/__init__.py b/malojalib/__init__.py new file mode 100644 index 0000000..4221992 --- /dev/null +++ b/malojalib/__init__.py @@ -0,0 +1,27 @@ +import requests + +class MalojaInstance: + def __init__(self,base_url,key): + self.base_url = base_url + self.key = key + + def test(self): + url = self.base_url + '/apis/mlj_1/test' + response = requests.get(url,{'key':self.key}) + + return (response.status_code == 200) + + def scrobble(self,artists,title,timestamp=None,album=None,duration=None): + payload = { + 'key':self.key, + 'artists':artists, + 'title':title, + 'time':timestamp, + 'album':album, + 'duration':duration + } + + url = self.base_url + '/apis/mlj_1/newscrobble' + response = requests.post(url,payload) + + return response.json() diff --git a/malojalib/__pkginfo__.py b/malojalib/__pkginfo__.py new file mode 100644 index 0000000..5a69fc4 --- /dev/null +++ b/malojalib/__pkginfo__.py @@ -0,0 +1,22 @@ +name = "maloja-lib" +desc = "Utilities to interact with Maloja servers" +author = { + "name":"Johannes Krattenmacher", + "email":"maloja@dev.krateng.ch", + "github": "krateng" +} +version = 1,0,0 +versionstr = ".".join(str(n) for n in version) +links = { + "pypi":"maloja-lib", + "github":"maloja" +} +python_version = ">=3.6" +requires = [ + "requests" +] +resources = [ +] + +commands = { +}