Commit c0d9edbb authored by Rob Nelson's avatar Rob Nelson
Browse files

Playlists are no longer hardcoded.

Also cleaned up some warnings.
parent 6dd79b2e
...@@ -4,3 +4,5 @@ ...@@ -4,3 +4,5 @@
*.pyc *.pyc
grabmusic.sh grabmusic.sh
.pre-commit-config.yaml
\ No newline at end of file
# All available playlists.
playlists: playlists:
# We want to include the jazz playlist in the bar mix. rock: {}
bar: jazz: {}
include: endgame: {}
playlists: shuttle: {}
- jazz muzak: {}
tracks: [] emagged: {}
files: clockwork: {}
- "rock/Starcraft 2 Jukebox - Big Tuna - Jem's Song-_k5YVy2QabQ.mp3" thunderdome: {}
- "rock/Starcraft 2 Jukebox - Whiteboy James and the Blues Express - Excuse Me For Scribblin'-muUQqtqU6GY.mp3" delta: {}
- "rock/Starcraft 2 Jukebox - Whiteboy James and the Blues Express - A Zerg, A Shotgun and You-WVRZAJTJKYs.mp3" beach: {}
- "rock/Starcraft 2 Jukebox - Bourbon Cowboys - Suspicious Minds-5RmM57wicb4.mp3" lobby-main: {}
lobby-snow: {}
malfdelta: {}
nukesquad: {}
# We want to include the jazz playlist in the bar mix.
bar:
include:
playlists:
- jazz
tracks: []
files:
- "rock/Starcraft 2 Jukebox - Big Tuna - Jem's Song-_k5YVy2QabQ.mp3"
- "rock/Starcraft 2 Jukebox - Whiteboy James and the Blues Express - Excuse Me For Scribblin'-muUQqtqU6GY.mp3"
- "rock/Starcraft 2 Jukebox - Whiteboy James and the Blues Express - A Zerg, A Shotgun and You-WVRZAJTJKYs.mp3"
- "rock/Starcraft 2 Jukebox - Bourbon Cowboys - Suspicious Minds-5RmM57wicb4.mp3"
...@@ -26,11 +26,11 @@ sys.path.append('lib/ryetalin') ...@@ -26,11 +26,11 @@ sys.path.append('lib/ryetalin')
import ryetalin import ryetalin
OUTPUT_DIR = os.path.abspath(u'files-upl') OUTPUT_DIR = os.path.abspath('files-upl')
OUTPUT_EXT = u'mp3' # WAS MP3 OUTPUT_EXT = 'mp3' # WAS MP3
TIME_SOURCE = time.time # time.clock on windows TIME_SOURCE = time.clock if os.name == 'nt' else time.time # time.clock on windows
USE_FFMPEG = False USE_FFMPEG = False # Changed by
SOX_ARGS = [] SOX_ARGS = []
SOX_ARGS += u'silence 1 0.1 0.1% reverse silence 1 0.1 0.1% reverse'.split(u' ') # Remove silence SOX_ARGS += u'silence 1 0.1 0.1% reverse silence 1 0.1 0.1% reverse'.split(u' ') # Remove silence
...@@ -69,13 +69,10 @@ cmds += [( ...@@ -69,13 +69,10 @@ cmds += [(
u'{OUTFILE}') u'{OUTFILE}')
] ]
''' '''
# Was originally going to use OGG. # Was originally going to use OGG, but they ended up being large
#cmds += [('oggenc tmp/VOX-sox-word.wav -o '+oggfile,oggfile)] #cmds += [('oggenc tmp/VOX-sox-word.wav -o '+oggfile,oggfile)]
playlists = [ PLAYLISTS = []
'rock', 'jazz', 'bar', 'endgame', 'shuttle', 'muzak', 'emagged', 'clockwork', 'thunderdome', 'delta', 'beach',
'lobby', 'xmas'
] # Keygen is too fucking big.
sourcefiles = [] sourcefiles = []
deadfiles = [] deadfiles = []
...@@ -89,7 +86,7 @@ revmd5s = {} ...@@ -89,7 +86,7 @@ revmd5s = {}
FILECOUNT=0 FILECOUNT=0
FILEPROGRESS=0 FILEPROGRESS=0
source_dir = u'source' # u'source_test' source_dir = 'source' # u'source_test'
def secondsToStr(t): def secondsToStr(t):
...@@ -98,14 +95,10 @@ def secondsToStr(t): ...@@ -98,14 +95,10 @@ def secondsToStr(t):
[(t * 1000,), 1000, 60, 60]) [(t * 1000,), 1000, 60, 60])
# Try to clean up UTF8 (NEVER WORKS) # Try to clean up UTF8 (NEVER WORKS)
def removeNonAscii(s): def removeNonAscii(s):
return u''.join(i for i in s if ord(i) < 128) return u''.join(i for i in s if ord(i) < 128)
# Remove ampersands, hashes, question marks, and exclamation marks. # Remove ampersands, hashes, question marks, and exclamation marks.
def cleanFilename(s): def cleanFilename(s):
s = s.replace(u'&', u'and') s = s.replace(u'&', u'and')
nwfn = (i for i in s if i not in u"#?!") nwfn = (i for i in s if i not in u"#?!")
...@@ -113,13 +106,13 @@ def cleanFilename(s): ...@@ -113,13 +106,13 @@ def cleanFilename(s):
def move(fromdir, todir, fromexts, toext, op, **op_args): def move(fromdir, todir, fromexts, toext, op, **op_args):
for root, dirs, files in os.walk(fromdir): for root, _, files in os.walk(fromdir):
path = root.split(u'/') #path = root.split('/')
newroot = os.path.join(todir, root[len(fromdir) + 1:]) newroot = os.path.join(todir, root[len(fromdir) + 1:])
for file in files: for file in files:
fromfile = os.path.join(root, file) fromfile = os.path.join(root, file)
title, ext = os.path.splitext(os.path.basename(fromfile)) _, ext = os.path.splitext(os.path.basename(fromfile))
if ext.strip(u'.') not in fromexts: if ext.strip('.') not in fromexts:
#logging.warn(u'Skipping {} ({})'.format(fromfile, ext)) #logging.warn(u'Skipping {} ({})'.format(fromfile, ext))
continue continue
if not os.path.isdir(newroot): if not os.path.isdir(newroot):
...@@ -128,10 +121,10 @@ def move(fromdir, todir, fromexts, toext, op, **op_args): ...@@ -128,10 +121,10 @@ def move(fromdir, todir, fromexts, toext, op, **op_args):
def check(wdir, exts, op, **kwargs): def check(wdir, exts, op, **kwargs):
for root, dirs, files in os.walk(wdir): for root, _, files in os.walk(wdir):
for file in files: for file in files:
fromfile = os.path.join(root, file) fromfile = os.path.join(root, file)
title, ext = os.path.splitext(os.path.basename(fromfile)) _, ext = os.path.splitext(os.path.basename(fromfile))
if len(exts) > 0 and ext.strip(u'.') not in exts: if len(exts) > 0 and ext.strip(u'.') not in exts:
#logging.warn(u'Skipping {} ({})'.format(fromfile, ext)) #logging.warn(u'Skipping {} ({})'.format(fromfile, ext))
continue continue
...@@ -160,7 +153,7 @@ def filename_md5(infile, newroot, args): ...@@ -160,7 +153,7 @@ def filename_md5(infile, newroot, args):
global md5s, revmd5s, config global md5s, revmd5s, config
md5 = md5_file(infile) md5 = md5_file(infile)
playlist = args['playlist'] playlist = args['playlist']
title, ext = os.path.splitext(os.path.basename(infile)) _, ext = os.path.splitext(os.path.basename(infile))
a = md5[0] a = md5[0]
b = md5[1] b = md5[1]
subf = os.path.join(newroot, a, b) subf = os.path.join(newroot, a, b)
...@@ -190,13 +183,13 @@ def filename_md5(infile, newroot, args): ...@@ -190,13 +183,13 @@ def filename_md5(infile, newroot, args):
#logging.warn(u'Skipping {} (exists)'.format(tofile)) #logging.warn(u'Skipping {} (exists)'.format(tofile))
return return
shutil.copy(infile, tofile) shutil.copy(infile, tofile)
logging.info('{1} = {2}'.format(md5, tofile, infile)) logging.info('%s = %s', tofile, infile)
def straight_copy(infile, newroot, args): def straight_copy(infile, newroot, args):
sinfile = removeNonAscii(infile) sinfile = removeNonAscii(infile)
if sinfile != infile: if sinfile != infile:
logging.critical("File {} (stripped) has nonascii filename.".format(sinfile)) logging.critical("File %s (stripped) has nonascii filename.", sinfile)
sys.exit() sys.exit()
base = os.path.basename(infile) base = os.path.basename(infile)
title, ext = os.path.splitext(base) title, ext = os.path.splitext(base)
...@@ -211,7 +204,7 @@ def straight_copy(infile, newroot, args): ...@@ -211,7 +204,7 @@ def straight_copy(infile, newroot, args):
def check_for_dead_files(infile, basedir=OUTPUT_DIR): def check_for_dead_files(infile, basedir=OUTPUT_DIR):
sinfile = removeNonAscii(infile) sinfile = removeNonAscii(infile)
if sinfile != infile: if sinfile != infile:
logging.critical("File {} (stripped) has nonascii filename.".format(sinfile)) logging.critical("File %s (stripped) has nonascii filename.", sinfile)
sys.exit() sys.exit()
global sourcefiles, deadfiles global sourcefiles, deadfiles
...@@ -221,8 +214,8 @@ def check_for_dead_files(infile, basedir=OUTPUT_DIR): ...@@ -221,8 +214,8 @@ def check_for_dead_files(infile, basedir=OUTPUT_DIR):
else: else:
if isinstance(infile, bytes): if isinstance(infile, bytes):
infile = infile.decode('utf-8') infile = infile.decode('utf-8')
title, ext = os.path.splitext(os.path.basename(infile)) title, _ = os.path.splitext(os.path.basename(infile))
playlist = os.path.relpath(os.path.dirname(infile), u'./' + basedir) playlist = os.path.relpath(os.path.dirname(infile), './' + basedir)
sourcefile = os.path.join(playlist, cleanFilename(title)) sourcefile = os.path.join(playlist, cleanFilename(title))
if sourcefile not in sourcefiles: if sourcefile not in sourcefiles:
deadfiles += [infile] deadfiles += [infile]
...@@ -299,7 +292,7 @@ class TimeExecution(object): ...@@ -299,7 +292,7 @@ class TimeExecution(object):
return self return self
def __exit__(self, type, value, traceback): def __exit__(self, type, value, traceback):
logging.info(' Completed in %(diff)ds - %(label)s', {'label': self.label, 'diff': secondsToStr(TIME_SOURCE() - self.start_time)}) logging.info(' Completed in %(diff)ss - %(label)s', {'label': self.label, 'diff': secondsToStr(TIME_SOURCE() - self.start_time)})
return False return False
...@@ -438,9 +431,11 @@ def main(): ...@@ -438,9 +431,11 @@ def main():
sys.exit(1) sys.exit(1)
with open('config.yml', 'r') as f: with open('config.yml', 'r') as f:
config = yaml.load(f) config = yaml.safe_load(f)
# print(repr(config)) # print(repr(config))
PLAYLISTS = list(config['playlists'].keys())
check(u'source',('m4a', 'wav', 'mp3', 'ogg', 'webm', 'oga'),check_count) check(u'source',('m4a', 'wav', 'mp3', 'ogg', 'webm', 'oga'),check_count)
move(source_dir, move(source_dir,
u'tmp_files', u'tmp_files',
...@@ -453,7 +448,7 @@ def main(): ...@@ -453,7 +448,7 @@ def main():
logging.info('Checking converted files...') logging.info('Checking converted files...')
check(u'tmp_files', (OUTPUT_EXT,), check_converted) check(u'tmp_files', (OUTPUT_EXT,), check_converted)
for playlist in playlists: for playlist in PLAYLISTS:
move(os.path.join('tmp_files', playlist), os.path.join(OUTPUT_DIR), [OUTPUT_EXT], OUTPUT_EXT, filename_md5, playlist=playlist) move(os.path.join('tmp_files', playlist), os.path.join(OUTPUT_DIR), [OUTPUT_EXT], OUTPUT_EXT, filename_md5, playlist=playlist)
check(OUTPUT_DIR, ('m4a', 'wav', 'mp3', 'ogg', 'webm', 'oga'), check_md5s) check(OUTPUT_DIR, ('m4a', 'wav', 'mp3', 'ogg', 'webm', 'oga'), check_md5s)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment