Advertisement
Guest User

Untitled

a guest
May 29th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.92 KB | None | 0 0
  1. import itertools
  2. import os
  3. import sys
  4. top = sys.argv[1]
  5. for root, dirs, files in os.walk(top, topdown=False):
  6.     ignore = ['Tachyon', 'All The Rounds', 'Sharpnelshortz', 'SPEEED', 'Happy', 'Crossover', 'Valex', 'Gensokyo', 'Fraxtil', 'Mute']
  7.     if any(s in root for s in ignore): continue
  8.     for name in files:
  9.         if name[-3:] != '.sm':
  10.             continue
  11.         fullname = os.path.join(root, name)
  12.         with open(fullname) as f:
  13.             try:
  14.                 while 1:
  15.                     l = next(f).strip('\n\r;')
  16.                     if l.startswith("#TITLE:"):
  17.                         title = l[7:]
  18.                         break
  19.                 while 1:
  20.                     l = next(f).strip('\n\r;')
  21.                     if l.startswith("#DISPLAYBPM:"):
  22.                         displaybpm = l[12:]
  23.                         try:
  24.                             bpm = str(int(float(displaybpm.split(':')[-1]) +.5))
  25.                             if ':' in displaybpm:
  26.                                 bpm += "[?]"
  27.                         except ValueError:
  28.                             bpm = "[?]"
  29.                         break
  30.                     elif l.startswith("#BPMS:"):
  31.                         bpms = l[6:].split(',')
  32.                         if not all(bpms):
  33.                             bpms = [float(bpms[0].split('=')[1]), 0]
  34.                         else:
  35.                             bpms = [float(v.split('=')[1]) for v in bpms]
  36.                         bpm = str(int(bpms[0]+.5))
  37.                         if len(bpms) > 1:
  38.                             bpm += "[?]"
  39.                         break
  40.                 while 1:
  41.                     while 1:
  42.                         l = next(f)
  43.                         if "dance-single:" in l:
  44.                             next(f)
  45.                             break
  46.                     while 1:
  47.                         l = next(f).strip()
  48.                         if l and l[-1] == ':' and l[:-1].isdigit():
  49.                             difficulty = int(l[:-1])
  50.                             break
  51.                     measures = [] # [num notes]
  52.                     cur = []
  53.                     closest = 1
  54.                     while 1:
  55.                         l = next(f)
  56.                         if '//' in l:
  57.                             l = l[:l.index('//')]
  58.                         l = l.strip()
  59.                         if l == ';':
  60.                             break
  61.                         if l == ',':
  62.                             notes = [i for i,x in enumerate(cur) if '1' in x or '2' in x]
  63.                             measures.append(len(notes))
  64.                             fl = float(len(cur))
  65.                             if len(notes) > 1:
  66.                                 c = min((j-i)/fl for i,j in zip(notes, notes[1:]))
  67.                                 closest = min(c, closest)
  68.                             cur = []
  69.                             continue
  70.                         if not l or ',' in l:
  71.                             continue
  72.                         cur.append(l)
  73.                     m = [x > 12 for x in measures]
  74.                     if not(any(m)):
  75.                         continue
  76.                     if not m[0]: m = m[m.index(True):]
  77.                     while not m[-1]: m = m[:-1]
  78.                     res = ""
  79.                     for stream, v in itertools.groupby(m):
  80.                         length = len(list(v))
  81.                         if stream: res += str(length)
  82.                         elif length == 1: res += "-"
  83.                         elif length <= 4: res += " . "
  84.                         elif length <= 16: res += " .. "
  85.                         else: res += " ... "
  86.                     fs = "[FS?]" * (closest < 0.0625)
  87.                     if 10 <= difficulty <= 24:
  88.                         print "%d/%s%s - %s/%s - %s" % (difficulty, bpm, fs, root.split('/')[-2], title, res)
  89.             except StopIteration:
  90.                 pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement