Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import itertools
- import os
- import sys
- top = sys.argv[1]
- for root, dirs, files in os.walk(top, topdown=False):
- ignore = ['Tachyon', 'All The Rounds', 'Sharpnelshortz', 'SPEEED', 'Happy', 'Crossover', 'Valex', 'Gensokyo', 'Fraxtil', 'Mute']
- if any(s in root for s in ignore): continue
- for name in files:
- if name[-3:] != '.sm':
- continue
- fullname = os.path.join(root, name)
- with open(fullname) as f:
- try:
- while 1:
- l = next(f).strip('\n\r;')
- if l.startswith("#TITLE:"):
- title = l[7:]
- break
- while 1:
- l = next(f).strip('\n\r;')
- if l.startswith("#DISPLAYBPM:"):
- displaybpm = l[12:]
- try:
- bpm = str(int(float(displaybpm.split(':')[-1]) +.5))
- if ':' in displaybpm:
- bpm += "[?]"
- except ValueError:
- bpm = "[?]"
- break
- elif l.startswith("#BPMS:"):
- bpms = l[6:].split(',')
- if not all(bpms):
- bpms = [float(bpms[0].split('=')[1]), 0]
- else:
- bpms = [float(v.split('=')[1]) for v in bpms]
- bpm = str(int(bpms[0]+.5))
- if len(bpms) > 1:
- bpm += "[?]"
- break
- while 1:
- while 1:
- l = next(f)
- if "dance-single:" in l:
- next(f)
- break
- while 1:
- l = next(f).strip()
- if l and l[-1] == ':' and l[:-1].isdigit():
- difficulty = int(l[:-1])
- break
- measures = [] # [num notes]
- cur = []
- closest = 1
- while 1:
- l = next(f)
- if '//' in l:
- l = l[:l.index('//')]
- l = l.strip()
- if l == ';':
- break
- if l == ',':
- notes = [i for i,x in enumerate(cur) if '1' in x or '2' in x]
- measures.append(len(notes))
- fl = float(len(cur))
- if len(notes) > 1:
- c = min((j-i)/fl for i,j in zip(notes, notes[1:]))
- closest = min(c, closest)
- cur = []
- continue
- if not l or ',' in l:
- continue
- cur.append(l)
- m = [x > 12 for x in measures]
- if not(any(m)):
- continue
- if not m[0]: m = m[m.index(True):]
- while not m[-1]: m = m[:-1]
- res = ""
- for stream, v in itertools.groupby(m):
- length = len(list(v))
- if stream: res += str(length)
- elif length == 1: res += "-"
- elif length <= 4: res += " . "
- elif length <= 16: res += " .. "
- else: res += " ... "
- fs = "[FS?]" * (closest < 0.0625)
- if 10 <= difficulty <= 24:
- print "%d/%s%s - %s/%s - %s" % (difficulty, bpm, fs, root.split('/')[-2], title, res)
- except StopIteration:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement