initial commit with music tools

This commit is contained in:
aj 2020-08-04 20:48:57 +01:00
commit 924e5912aa
3 changed files with 240 additions and 0 deletions

4
README.md Normal file
View File

@ -0,0 +1,4 @@
Phone Scripts
===================
Helper Python scripts using [Pythonista](http://omz-software.com/pythonista/).

76
music-tools.py Normal file
View File

@ -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')

160
music-tools.pyui Normal file
View File

@ -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" : "<System>",
"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
}
]