From 924e5912aa898776e39f0d81ec5adab02c577234 Mon Sep 17 00:00:00 2001 From: aj Date: Tue, 4 Aug 2020 20:48:57 +0100 Subject: [PATCH] initial commit with music tools --- README.md | 4 ++ music-tools.py | 76 ++++++++++++++++++++++ music-tools.pyui | 160 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 240 insertions(+) create mode 100644 README.md create mode 100644 music-tools.py create mode 100644 music-tools.pyui diff --git a/README.md b/README.md new file mode 100644 index 0000000..618252d --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +Phone Scripts +=================== + +Helper Python scripts using [Pythonista](http://omz-software.com/pythonista/). \ No newline at end of file diff --git a/music-tools.py b/music-tools.py new file mode 100644 index 0000000..77771b9 --- /dev/null +++ b/music-tools.py @@ -0,0 +1,76 @@ +import ui +import sys +import dialogs +import requests +import webbrowser +import clipboard + +from requests.auth import HTTPBasicAuth +from requests import Session + +auth = HTTPBasicAuth(sys.argv[1], sys.argv[2]) +rsession = Session() + +@ui.in_background +def do_sort_playlist(sender): + name = dialogs.input_alert(title="Playlist Name") + + if name and len(name) > 0: + res = rsession.post("https://music.sarsoo.xyz/api/spotify/sort", + json={"playlist_name": name}, auth=auth) + + if 200 <= res.status_code < 300: + output = 'Success' + else: + output = f'Failed {res.status_code} {res.body}' + + sender.superview['output_label'].text = output + +@ui.in_background +def do_daily_scrobbles(sender): + res = rsession.get("https://music.sarsoo.xyz/api/fm/today", auth=auth) + + if 200 <= res.status_code < 300: + sender.superview['output_label'].text = str(res.json()['scrobbles_today']) + else: + sender.superview['output_label'].text = f'Failed {res.status_code} {res.body}' + +@ui.in_background +def do_view_user(sender): + res = rsession.get("https://music.sarsoo.xyz/api/user", auth=auth) + + if 200 <= res.status_code < 300: + clipboard.set(res.text) + webbrowser.open('jayson:///view?clipboard=true') + else: + sender.superview['output_label'].text = f'Failed {res.status_code} {res.body}' + +@ui.in_background +def do_view_playlist(sender): + name = dialogs.input_alert(title="Playlist Name") + + if name and len(name) > 0: + res = rsession.get("https://music.sarsoo.xyz/api/playlist", params={'name': name}, auth=auth) + + if 200 <= res.status_code < 300: + clipboard.set(res.text) + webbrowser.open('jayson:///view?clipboard=true') + else: + sender.superview['output_label'].text = f'Failed {res.status_code} {res.body}' + +@ui.in_background +def do_view_tag(sender): + tag_id = dialogs.input_alert(title="Tag ID") + + if tag_id and len(tag_id) > 0: + res = rsession.get(f"https://music.sarsoo.xyz/api/tag/{tag_id}", auth=auth) + + if 200 <= res.status_code < 300: + clipboard.set(res.text) + webbrowser.open('jayson:///view?clipboard=true') + else: + sender.superview['output_label'].text = f'Failed {res.status_code} {res.body}' + +if __name__ == '__main__': + v = ui.load_view() + v.present('sheet') diff --git a/music-tools.pyui b/music-tools.pyui new file mode 100644 index 0000000..6ca79ad --- /dev/null +++ b/music-tools.pyui @@ -0,0 +1,160 @@ +[ + { + "nodes" : [ + { + "nodes" : [ + + ], + "frame" : "{{6, 6}, {288, 32}}", + "class" : "Button", + "attributes" : { + "uuid" : "CA0E7F94-5A7F-4FE4-8BBE-E3A8249D899B", + "font_size" : 15, + "corner_radius" : 8, + "background_color" : "RGBA(0.441176,0.441176,0.441176,1.000000)", + "frame" : "{{106, 146}, {80, 32}}", + "border_color" : "RGBA(0.000000,0.000000,0.000000,1.000000)", + "border_width" : 3, + "tint_color" : "RGBA(1.000000,1.000000,1.000000,1.000000)", + "title" : "Daily Scrobbles", + "action" : "do_daily_scrobbles", + "font_bold" : false, + "class" : "Button", + "name" : "daily_scrobbles", + "flex" : "W" + }, + "selected" : false + }, + { + "nodes" : [ + + ], + "frame" : "{{6, 46}, {288, 32}}", + "class" : "Button", + "attributes" : { + "uuid" : "CA0E7F94-5A7F-4FE4-8BBE-E3A8249D899B", + "font_size" : 15, + "corner_radius" : 8, + "background_color" : "RGBA(0.439216,0.439216,0.439216,1.000000)", + "frame" : "{{106, 146}, {80, 32}}", + "border_color" : "RGBA(0.000000,0.000000,0.000000,1.000000)", + "border_width" : 3, + "tint_color" : "RGBA(1.000000,1.000000,1.000000,1.000000)", + "title" : "Sort Playlist", + "action" : "do_sort_playlist", + "font_bold" : false, + "class" : "Button", + "name" : "sort_playlist", + "flex" : "W" + }, + "selected" : false + }, + { + "nodes" : [ + + ], + "frame" : "{{6, 86}, {288, 32}}", + "class" : "Label", + "attributes" : { + "uuid" : "DC4D6264-AFB7-497E-B410-6F5A09F0A3BE", + "font_size" : 18, + "corner_radius" : 6, + "frame" : "{{75, 146}, {150, 32}}", + "border_color" : "RGBA(0.656863,0.656863,0.656863,1.000000)", + "border_width" : 3, + "alignment" : "center", + "text" : "", + "font_name" : "", + "class" : "Label", + "name" : "output_label", + "flex" : "W" + }, + "selected" : false + }, + { + "nodes" : [ + + ], + "frame" : "{{6, 126}, {288, 32}}", + "class" : "Button", + "attributes" : { + "uuid" : "CA0E7F94-5A7F-4FE4-8BBE-E3A8249D899B", + "flex" : "W", + "corner_radius" : 8, + "background_color" : "RGBA(0.439216,0.439216,0.439216,1.000000)", + "frame" : "{{106, 146}, {80, 32}}", + "border_color" : "RGBA(0.000000,0.000000,0.000000,1.000000)", + "border_width" : 3, + "tint_color" : "RGBA(1.000000,1.000000,1.000000,1.000000)", + "title" : "View User", + "action" : "do_view_user", + "font_bold" : false, + "class" : "Button", + "name" : "view_user", + "font_size" : 15 + }, + "selected" : false + }, + { + "nodes" : [ + + ], + "frame" : "{{6, 166}, {288, 32}}", + "class" : "Button", + "attributes" : { + "uuid" : "CA0E7F94-5A7F-4FE4-8BBE-E3A8249D899B", + "font_size" : 15, + "corner_radius" : 8, + "background_color" : "RGBA(0.439216,0.439216,0.439216,1.000000)", + "frame" : "{{106, 146}, {80, 32}}", + "border_color" : "RGBA(0.000000,0.000000,0.000000,1.000000)", + "border_width" : 3, + "tint_color" : "RGBA(1.000000,1.000000,1.000000,1.000000)", + "title" : "View Playlist", + "action" : "do_view_playlist", + "font_bold" : false, + "class" : "Button", + "name" : "view_playlist", + "flex" : "W" + }, + "selected" : false + }, + { + "nodes" : [ + + ], + "frame" : "{{6, 206}, {288, 32}}", + "class" : "Button", + "attributes" : { + "uuid" : "CA0E7F94-5A7F-4FE4-8BBE-E3A8249D899B", + "flex" : "W", + "corner_radius" : 8, + "background_color" : "RGBA(0.439216,0.439216,0.439216,1.000000)", + "frame" : "{{106, 146}, {80, 32}}", + "border_color" : "RGBA(0.000000,0.000000,0.000000,1.000000)", + "border_width" : 3, + "tint_color" : "RGBA(1.000000,1.000000,1.000000,1.000000)", + "title" : "View Tag", + "action" : "do_view_tag", + "alpha" : 1, + "font_bold" : false, + "class" : "Button", + "name" : "view_tag", + "font_size" : 15 + }, + "selected" : true + } + ], + "frame" : "{{0, 0}, {300, 324}}", + "class" : "View", + "attributes" : { + "name" : "Music Tools", + "enabled" : true, + "border_color" : "RGBA(0.000000,0.000000,0.000000,1.000000)", + "background_color" : "RGBA(1.000000,1.000000,1.000000,1.000000)", + "tint_color" : "RGBA(0.000000,0.478000,1.000000,1.000000)", + "flex" : "" + }, + "selected" : false + } +] \ No newline at end of file