# Path: analyzer/utils.py
# def env(name, default=None):
# def window(seq, n=2):
# def block_shaped(image, n_rows, n_cols):
# def flatten(l):
# def camel_to_underscore(name):
# def underscore_to_camel(name):
# def change_dict_naming_convention(d, convert_function):
# 	def as_dict(self, camel=True):
# 	def from_dict(cls, data, from_camel=True):
# 	def from_dicts(cls, data, from_camel=True):
# 	def to_mongo_dict(self):
# def to_mongo_dict(obj):
# def to_dict(obj):
# def props(obj):
# def image_filename(index, file_type="jpg"):
# def extract_filename(path):
# def extract_name(file):
# def basepath(path):
# def extract_index(path):
# def objects_as_dict(objects):
# def slice_paths(paths, limit):
# def derivative(distances):
# def crop_image(image, cx=20, cy=20):
# DEBUG = bool(int(getenv('DEBUG', False)))
# 	T = type(objects[0])
# class Model(object):
# 
# Path: analyzer/timestamp.py
# class Timestamp(object):
# 	def __init__(self, val):
# 		if type(val) is str:
# 			timestamp_pattern = "(?:(?:(?:(\d?\d):)?(\d?\d):)?(\d?\d))?(?:[,.](\d?\d?\d))?"
# 			regex = re.compile(timestamp_pattern)
# 			regex_result = regex.match(val)
# 
# 			if regex_result is not None:
# 				groups = regex_result.groups()
# 				hours = entity_to_int(groups[0])
# 				minutes = entity_to_int(groups[1])
# 				seconds = entity_to_int(groups[2])
# 				milliseconds = entity_to_int(groups[3])
# 
# 				self.millis = (hours_to_millis(hours) +
# 				               minutes_to_millis(minutes) +
# 				               seconds_to_millis(seconds) +
# 				               milliseconds)
# 		elif type(val) is int:
# 			self.millis = val
# 		else:
# 			raise Exception("Timestamp parse failed")
# 
# 	def __str__(self):
# 		return "{}".format(self.millis)
# 
# 	def __repr__(self):
# 		return self.__str__()
# 
# 	def __add__(self, other):
# 		return Timestamp(self.millis + other.millis)
# 
# 	def __sub__(self, other):
# 		return Timestamp(self.millis - other.millis)
# 
# Path: analyzer/utils.py
# def flatten(l):
# 	return [item for sublist in l for item in sublist]
# 
# class Model(object):
# 	def as_dict(self, camel=True):
# 		dictionary = to_dict(self)
# 		if camel:
# 			return change_dict_naming_convention(dictionary, underscore_to_camel)
# 		else:
# 			return dictionary
# 
# 	@classmethod
# 	def from_dict(cls, data, from_camel=True):
# 		if from_camel:
# 			return change_dict_naming_convention(data, camel_to_underscore)
# 		else:
# 			return data
# 
# 	@classmethod
# 	def from_dicts(cls, data, from_camel=True):
# 		return [cls.from_dict(d) for d in data]
# 
# 	def to_mongo_dict(self):
# 		dictionary = self.as_dict()
# 		return to_mongo_dict(dictionary)


import re
from analyzer import utils
from analyzer.timestamp import Timestamp
from analyzer.utils import flatten, Model
#!/usr/bin/python



class Subtitle(Model):
	def __init__(self, t1, t2, text, original_text=None, character=None):
		self.t1 = Timestamp(t1) if (type(t1) == int) else t1
		self.t2 = Timestamp(t2) if (type(t2) == int) else t2
		self.text = text
		self.original_text = text if text is not None else original_text
		self.character = character

	def __str__(self):
		return "t1: {}, t2: {}, text: {}, character: {}".format(self.t1, self.t2, self.text, self.character)

	def __repr__(self):
		return self.__str__()

	def as_dict(self, camel=True):
		d = Model.as_dict(self)
		d["t1"] = self.t1.millis
		d["t2"] = self.t2.millis

		return d

	def to_mongo_dict(self):
		d = self.as_dict()

# Path: analyzer/utils.py
# def env(name, default=None):
# def window(seq, n=2):
# def block_shaped(image, n_rows, n_cols):
# def flatten(l):
# def camel_to_underscore(name):
# def underscore_to_camel(name):
# def change_dict_naming_convention(d, convert_function):
# 	def as_dict(self, camel=True):
# 	def from_dict(cls, data, from_camel=True):
# 	def from_dicts(cls, data, from_camel=True):
# 	def to_mongo_dict(self):
# def to_mongo_dict(obj):
# def to_dict(obj):
# def props(obj):
# def image_filename(index, file_type="jpg"):
# def extract_filename(path):
# def extract_name(file):
# def basepath(path):
# def extract_index(path):
# def objects_as_dict(objects):
# def slice_paths(paths, limit):
# def derivative(distances):
# def crop_image(image, cx=20, cy=20):
# DEBUG = bool(int(getenv('DEBUG', False)))
# 	T = type(objects[0])
# class Model(object):
# 
# Path: analyzer/timestamp.py
# class Timestamp(object):
# 	def __init__(self, val):
# 		if type(val) is str:
# 			timestamp_pattern = "(?:(?:(?:(\d?\d):)?(\d?\d):)?(\d?\d))?(?:[,.](\d?\d?\d))?"
# 			regex = re.compile(timestamp_pattern)
# 			regex_result = regex.match(val)
# 
# 			if regex_result is not None:
# 				groups = regex_result.groups()
# 				hours = entity_to_int(groups[0])
# 				minutes = entity_to_int(groups[1])
# 				seconds = entity_to_int(groups[2])
# 				milliseconds = entity_to_int(groups[3])
# 
# 				self.millis = (hours_to_millis(hours) +
# 				               minutes_to_millis(minutes) +
# 				               seconds_to_millis(seconds) +
# 				               milliseconds)
# 		elif type(val) is int:
# 			self.millis = val
# 		else:
# 			raise Exception("Timestamp parse failed")
# 
# 	def __str__(self):
# 		return "{}".format(self.millis)
# 
# 	def __repr__(self):
# 		return self.__str__()
# 
# 	def __add__(self, other):
# 		return Timestamp(self.millis + other.millis)
# 
# 	def __sub__(self, other):
# 		return Timestamp(self.millis - other.millis)
# 
# Path: analyzer/utils.py
# def flatten(l):
# 	return [item for sublist in l for item in sublist]
# 
# class Model(object):
# 	def as_dict(self, camel=True):
# 		dictionary = to_dict(self)
# 		if camel:
# 			return change_dict_naming_convention(dictionary, underscore_to_camel)
# 		else:
# 			return dictionary
# 
# 	@classmethod
# 	def from_dict(cls, data, from_camel=True):
# 		if from_camel:
# 			return change_dict_naming_convention(data, camel_to_underscore)
# 		else:
# 			return data
# 
# 	@classmethod
# 	def from_dicts(cls, data, from_camel=True):
# 		return [cls.from_dict(d) for d in data]
# 
# 	def to_mongo_dict(self):
# 		dictionary = self.as_dict()
# 		return to_mongo_dict(dictionary)


# Path: analyzer/subtitles_parser.py
import re
from analyzer import utils
from analyzer.timestamp import Timestamp
from analyzer.utils import flatten, Model

#!/usr/bin/python



class Subtitle(Model):
	def __init__(self, t1, t2, text, original_text=None, character=None):
		self.t1 = Timestamp(t1) if (type(t1) == int) else t1
		self.t2 = Timestamp(t2) if (type(t2) == int) else t2
		self.text = text
		self.original_text = text if text is not None else original_text
		self.character = character

	def __str__(self):
		return "t1: {}, t2: {}, text: {}, character: {}".format(self.t1, self.t2, self.text, self.character)

	def __repr__(self):
		return self.__str__()

	def as_dict(self, camel=True):
		d = Model.as_dict(self)
		d["t1"] = self.t1.millis
		d["t2"] = self.t2.millis

		return d

	def to_mongo_dict(self):
		d = self.as_dict()

		return utils.to_mongo_dict(d)