stt/stt.py

119 lines
3.5 KiB
Python
Raw Normal View History

2020-06-17 06:35:34 +02:00
#!/usr/bin/env python3
# include standard modules
import argparse
import os
import sys
import re
import json
mydir = os.path.dirname(os.path.realpath(__file__))
def commandline():
# initiate the parser
parser = argparse.ArgumentParser(description="Awesome tool to...")
# option without argument via 'store_true'
parser.add_argument("-V", "--version", help="show program version", action="store_true")
# option with argument
parser.add_argument("--width", "-w", help="set output width")
parser.add_argument("--input", "-i", help="set input file")
# read arguments from the command line
args = parser.parse_args()
# handle arguments
# check for --version or -V
if args.version:
print("this is myprogram version 0.1")
# check for --width
if args.width:
print("set output width to %s" % args.width)
return args
def get_json(html):
result = re.search(r'<script id="state" type="application/json">(?P<json>.*?)</script', html, re.MULTILINE)
if result:
data = json.loads(result.group("json"))
else:
print("Can't find the magic")
return data
args = commandline()
with open(args.input, 'r') as content_file:
content = content_file.read()
jsondata = get_json(content)
print( "Artist: " + jsondata["meta"]["artist"] )
print( "Title: " + jsondata["meta"]["title"] )
print( "Instrument: " + jsondata["data"]["part"]["instrument"] )
print( "BPM: " + str( jsondata["data"]["part"]["measures"][0]["voices"][0]["beats"][0]["tempo"]["bpm"] ) )
# Index:
# CC1 Crash Cymbal 1 { "string": 0, "fret": 49 }
# CC2 Crash Cymbal 2 { "string": 0, "fret": 57 }
# RC Ride Cymbal { "string": 0, "fret": 51 }
# fH Foot Hi Hat { "string": 0, "fret": 44 }
# HMT Hi-Mid Tom { "string": 3, "fret": 48 }
# FT Floor Tom { "string": 3, "fret": 43 }
# LMT Low-Mid Tom { "string": 3, "fret": 47 }
# S Snare { "string": 4, "fret": 38 }
# BD Bass Drum { "string": 5, "fret": 35 }
2020-06-17 20:08:59 +02:00
### CC|-Crash cymbal----|
### HH|-Hi-hat----------|
### Rd|-Ride cymbal-----|
### SN|-Snare-drum------|
### T1|-High-tom--------|
### T2|-Low-tom---------|
### FT|-Floor-tom-------|
### BD |-Bass-drum------|
### Hf/FH|-Hi-hat-w/foot|
###
###Cymbals
###
### |-x-| Strike cymbal or hi-hat
### |-X-| Strike loose hi-hat, or hit crash hard
### |-o-| Open hi-hat
### |-#-| Choke cymbal (grab cymbal with hand after striking it)
### |-s-| Splash cymbal
### |-c-| China cymbal
### |-b-| Bell of ride
### |-x-| Click hi-hat with foot
###
###Drums
###
### |-o-| Strike
### |-O-| Accent
### |-g-| Ghost note
### |-f-| Flam
### |-d-| Drag
### |-b-| Soft one-handed roll
### |-B-| Accented one-handed roll
### |-@-| Snare rim
print("")
print( str( jsondata["data"]["part"]["measures"][5]["voices"][0]["beats"] ) )
print( "Type: " + str( jsondata["data"]["part"]["measures"][5]["voices"][0]["beats"][0]["type"] ) )
for i in range(len(jsondata["data"]["part"]["measures"][5]["voices"][0]["beats"])):
beats = jsondata["data"]["part"]["measures"][5]["voices"][0]["beats"][i]
print( str(i+1) + " note " + str( jsondata["data"]["part"]["measures"][5]["voices"][0]["beats"][i]["notes"] ) )
for beat in beats:
if note == { "string": 5, "fret": 35 }:
print("BD")
elif note == { "string": 4, "fret": 38 }:
print("S")
elif note == { "string": 0, "fret": 51 }:
print("Rd")
elif note == { "string": 0, "fret": 57 }:
print("CC")
else:
print(note)
2020-06-17 06:35:34 +02:00