Commits

Jason R. Coombs committed 47ad828

Moved adjust-sub script into the project

Comments (0)

Files changed (3)

jaraco/media/srt.py

 
 import datetime
 import itertools
+import argparse
+import sys
 
 _sample_srt_entries = """
 1
 	def adjust_entries(entries, adjustment):
 		for entry in entries:
 			yield entry + adjustment
+
+class AdjustCommand(object):
+	@classmethod
+	def get_args(cls):
+		parser = argparse.ArgumentParser()
+		parser.add_argument('delta',
+			type=lambda s: datetime.timedelta(seconds=float(s)))
+		parser.add_argument('-s', '--start-entry', default=0, type=int)
+		parser.add_argument('-e', '--end-entry', type=int)
+		return parser.parse_args()
+
+	@classmethod
+	def run(cls):
+		args = cls.get_args()
+		entries = SubEntry.get_entries(sys.stdin)
+		start_entries = itertools.islice(entries, args.start_entry)
+		if args.end_entry:
+			# since start_entries may already have been consumed, adjust the
+			#  end to account for those items.
+			args.end_entry = args.end_entry - args.start_entry
+		adjust_entries = itertools.islice(entries, args.end_entry)
+		adjust_entries = (entry + args.delta for entry in adjust_entries)
+		rest = entries
+
+		adjusted_entries = itertools.chain(start_entries, adjust_entries, rest)
+
+		SubEntry.write_entries(sys.stdout, adjusted_entries)

scripts/adjust-sub.py

-import datetime
-import sys
-import argparse
-import itertools
-
-from jaraco.media.srt import SubEntry
-
-def get_args():
-	parser = argparse.ArgumentParser()
-	parser.add_argument('delta',
-		type=lambda s: datetime.timedelta(seconds=float(s)))
-	parser.add_argument('-s', '--start-entry', default=0, type=int)
-	parser.add_argument('-e', '--end-entry', type=int)
-	return parser.parse_args()
-
-def main():
-	args = get_args()
-	entries = SubEntry.get_entries(sys.stdin)
-	start_entries = itertools.islice(entries, args.start_entry)
-	if args.end_entry:
-		# since start_entries may already have been consumed, adjust the
-		#  end to account for those items.
-		args.end_entry = args.end_entry - args.start_entry
-	adjust_entries = itertools.islice(entries, args.end_entry)
-	adjust_entries = (entry + args.delta for entry in adjust_entries)
-	rest = entries
-
-	adjusted_entries = itertools.chain(start_entries, adjust_entries, rest)
-
-	SubEntry.write_entries(sys.stdout, adjusted_entries)
-
-if __name__ == '__main__':
-	main()
 			'multibrake = jaraco.media.handbrake:multibrake',
 			'quick-brake = jaraco.media.handbrake:quick_brake',
 			'mkv-to-mp4 = jaraco.media.matroska:handle_command_line',
+			'adjust-sub = jaraco.media.srt:AdjustCommand.run',
 			],
 	},
 	install_requires=[