Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: Vultaire/r21buddy
base: 1cd76043c7
...
head fork: Vultaire/r21buddy
compare: 828c8854b6
  • 5 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
0  r21buddy/__init__.py
No changes.
View
0  crc.py → r21buddy/crc.py
File renamed without changes
View
81 r21buddy.py → r21buddy/oggpatch.py
@@ -41,9 +41,14 @@
"""
+from __future__ import absolute_import
+
+
+TARGET_LENGTH = 105 # Default length to patch
+
import sys, argparse
from cStringIO import StringIO
-import crc
+from r21buddy import crc
def _int(lsb_str):
# Not sure how to handle bytes in MSB order...
@@ -411,20 +416,24 @@ def __str__(self):
return "<SetupHeader raw:%s>" % (repr(self.raw),)
-def get_pages(infile):
+def _get_pages(infile):
while True:
try:
yield OggPage(infile)
except NoMorePages:
break
-def get_bitstreams(pages):
+def _get_bitstreams(pages):
while True:
try:
yield VorbisBitStream(pages)
except NoMoreBitstreams:
break
+def get_bitstreams(infile):
+ page_gen = _get_pages(infile)
+ return _get_bitstreams(page_gen)
+
def parse_args():
ap = argparse.ArgumentParser()
ap.add_argument("input_file", help="Input file.")
@@ -434,7 +443,7 @@ def parse_args():
help="Check length only; do not modify file")
ap.add_argument("-v", "--verbose", action="store_true",
help="Verbose output")
- ap.add_argument("-l", "--length", default=105,
+ ap.add_argument("-l", "--length", default=TARGET_LENGTH,
help="Desired max length to patch into the input file. (Default: %(default)s)")
return ap.parse_args()
@@ -445,38 +454,56 @@ def pprint_time(t):
return "{0:d}:{1:05.2f}".format(int(mins), secs)
-def main():
- options = parse_args()
+def patch_file(input_file, target_length=TARGET_LENGTH,
+ output_file=None, verbose=True):
patched = False
- with open(options.input_file, "rb") as infile:
- page_gen = get_pages(infile)
- bitstreams = list(get_bitstreams(page_gen))
+ with open(input_file, "rb") as infile:
+ bitstreams = list(get_bitstreams(infile))
for bitstream in bitstreams:
length = bitstream.get_length()
- if options.verbose:
- print "Current file length: {0}".format(pprint_time(length))
- print "Target file length: {0}".format(pprint_time(options.length))
- if options.check:
- if length > options.length:
- print >> sys.stderr, "File exceeds {0}. Length: {1}".format(
- pprint_time(options.length), pprint_time(length))
- return 1
- continue
- if length > options.length:
- patched = True
- bitstream.patch_length(options.length, verbose=options.verbose)
+ if verbose:
+ print "Current file length: {0}".format(pprint_time(length))
+ print "Target file length: {0}".format(pprint_time(target_length))
+ if length > target_length:
+ patched = True
+ bitstream.patch_length(target_length, verbose=verbose)
if patched:
- output_file = options.input_file
- if options.output_file is not None:
- output_file = options.output_file
- if options.verbose:
+ output_file = input_file
+ if output_file is not None:
+ output_file = output_file
+ if verbose:
print "Writing patched file to", output_file
with open(sys.argv[1], "wb") as outfile:
for bitstream in bitstreams:
bitstream.write_to_file(outfile)
- elif options.verbose:
+ elif verbose:
print "Not patching file; file already appears to be {0} or shorter.".format(
- pprint_time(options.length))
+ pprint_time(target_length))
+
+def check_file(input_file, target_length, verbose=True):
+ with open(input_file, "rb") as infile:
+ bitstreams = list(get_bitstreams(infile))
+ for bitstream in bitstreams:
+ length = bitstream.get_length()
+ if verbose:
+ print "Current file length: {0}".format(pprint_time(length))
+ print "Target file length: {0}".format(pprint_time(target_length))
+
+ if length > target_length:
+ print >> sys.stderr, "File exceeds {0}. Length: {1}".format(
+ pprint_time(target_length), pprint_time(length))
+ return False
+ continue
+
+ return True
+
+def main():
+ options = parse_args()
+ if options.check:
+ check_file(options.input_file, options.length, verbose=options.verbose)
+ else:
+ patch_file(options.input_file, options.length, output_file=options.output_file, verbose=options.verbose)
+
return 0
View
67 r21buddy/r21buddy.py
@@ -0,0 +1,67 @@
+"""Script to generate a R21-compatible song directory.
+
+This is the console version; a GUI version is intended eventually.
+
+"""
+
+import os, sys, argparse
+
+def parse_args():
+ ap = argparse.ArgumentParser()
+ ap.add_argument(
+ "target_dir",
+ help=("Output directory. NOTE: An ITG2-compatible directory "
+ "structure will be created *within* this directory."))
+ ap.add_argument(
+ "-i", "--input-path", default=[], nargs="*",
+ help=("Input path(s) to extract songs from."))
+ ap.add_argument(
+ "-n", "--no-length-patch", dest="length_patch",
+ action="store_false", default=True,
+ help="Skip patching of .ogg files.")
+ ap.add_argument("-v", "--verbose", action="store_true")
+ return ap.parse_args()
+
+def create_target_dir_structure(target_dir, verbose=False):
+ song_dir = os.path.join(target_dir, "In The Groove 2", "Songs")
+ if not os.path.exists(song_dir):
+ os.makedirs(os.path.join(target_dir, "In The Groove 2", "Songs"))
+ if verbose:
+ print "Created directory:", song_dir
+ elif not os.path.isdir(song_dir):
+ raise Exception("Target path is not a directory", song_dir)
+ else:
+ if verbose:
+ print "Directory already exists:", song_dir
+
+def copy_songs(input_path, target_dir, verbose=False):
+ pass
+
+def patch_length(target_dir, verbose=False):
+ song_dir = os.path.join(target_dir, "In The Groove 2", "Songs")
+ all_files = (os.path.join(song_dir, f) for f in os.listdir(song_dir))
+ dirs = (d for d in all_files if os.path.isdir(d))
+ for song_dir in dirs:
+ song_files = (os.path.join(os.listdir(song_dir), f)
+ for f in os.listdir(song_dir))
+ ogg_files = (f for f in song_files if f.endswith(".ogg"))
+ for ogg_file in ogg_files:
+ oggpatch.patch_file(ogg_file, verbose=verbose)
+
+def main():
+ options = parse_args()
+
+ create_target_dir_structure(options.target_dir, verbose=options.verbose)
+
+ for input_path in options.input_path:
+ copy_songs(input_path, options.target_dir, verbose=True)
+
+ # *NOTE:* If no input paths are specified, this tool can be used
+ # to patch the length on existing ogg files in the target dir.
+ if options.length_patch:
+ patch_length(options.target_dir, verbose=True)
+
+ return 0
+
+if __name__ == "__main__":
+ sys.exit(main())

No commit comments for this range

Something went wrong with that request. Please try again.