<commit_before>#!/usr/bin/env python3
# encoding: utf-8
# 
# © 2017 <NAME>
# https://bmintz.mit-license.org/@2017
#

"""
techmeme.py: CLI app to turn videos into dank technical may-mays
"""

from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.fx.speedx import speedx

from config import TechnicalMemeConfig


class TechnicalMeme(CompositeVideoClip):
	def __init__(self, *, source_filename, config):
		self.source_video = VideoFileClip(source_filename)
		self.config = config
		self._fix_up_timestamps()
		
		# write em up
		self._write_all_subclips()
	
	
	def _fix_up_timestamps(self):
		self.config.timestamps = [0] + self.config.timestamps + [self.source_video.end]
	
	
	def _get_subclip(self, timestamp_number):
		"""get a subclip at the timestamp given by self.config.timestamps[timestamp_number]"""
		
		if timestamp_number < len(self.config.timestamps):
			return self.source_video.subclip(*self.config.timestamps[timestamp_number:timestamp_number+2])
		else:
			raise ValueError("timestamp number too large")
	
	
	def _get_sped_up_subclip(self, timestamp_number):
		try:
			return self._get_subclip(timestamp_number)\
				.speedx(self.config.multiplier**timestamp_number)
		except ValueError:
			raise
	
	
	def _write_subclip(self, timestamp_number):
		try:
			self._get_sped_up_subclip(timestamp_number)\
				.write_videofile("TMP_techmeme_{}.mp4"
					.format(timestamp_number))
		except ValueError:
			raise
	
	def _write_all_subclips(self):
		for timestamp_number in range(len(self.config.timestamps)):
			try:
				self._write_subclip(timestamp_number)
			except ValueError:
				raise

<commit_msg>TechMeme: clarify module docstring<commit_after>#!/usr/bin/env python3
# encoding: utf-8
# 
# © 2017 <NAME>
# https://bmintz.mit-license.org/@2017
#

"""
techmeme.py: class that turns videos into dank technical may-mays
"""

from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.fx.speedx import speedx

from config import TechnicalMemeConfig


class TechnicalMeme(CompositeVideoClip):
	def __init__(self, *, source_filename, config):
		self.source_video = VideoFileClip(source_filename)
		self.config = config
		self._fix_up_timestamps()
		
		# write em up
		self._write_all_subclips()
	
	
	def _fix_up_timestamps(self):
		self.config.timestamps = [0] + self.config.timestamps + [self.source_video.end]
	
	
	def _get_subclip(self, timestamp_number):
		"""get a subclip at the timestamp given by self.config.timestamps[timestamp_number]"""
		
		if timestamp_number < len(self.config.timestamps):
			return self.source_video.subclip(*self.config.timestamps[timestamp_number:timestamp_number+2])
		else:
			raise ValueError("timestamp number too large")
	
	
	def _get_sped_up_subclip(self, timestamp_number):
		try:
			return self._get_subclip(timestamp_number)\
				.speedx(self.config.multiplier**timestamp_number)
		except ValueError:
			raise
	
	
	def _write_subclip(self, timestamp_number):
		try:
			self._get_sped_up_subclip(timestamp_number)\
				.write_videofile("TMP_techmeme_{}.mp4"
					.format(timestamp_number))
		except ValueError:
			raise
	
	def _write_all_subclips(self):
		for timestamp_number in range(len(self.config.timestamps)):
			try:
				self._write_subclip(timestamp_number)
			except ValueError:
				raise
{'fraction_non_alphanumeric': 0.10034904013961606, 'fraction_numerical': 0.0075625363583478765, 'mean_word_length': 5.00174520069808, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1737779', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1142, 'n_words': 220}