def _get_rendered_image_from_comment(self, index, comment): rendered_template_filepath = self._get_rendered_template_from_comment( index, comment ) rendered_image_filepath = ( f"{self.working_dir}/{COMMENT_IMG_FILEPATH_TEMPLATE.format(index=index)}" ) _, stderr = get_image_from_html( rendered_template_filepath, rendered_image_filepath ) if not stderr: debug(f"Rendering of comment: {comment.id} successful.") return rendered_image_filepath
def scrape_hottest_from_subreddit( self, subreddit, render_images=True, render_tts=True ): already_scraped = self._get_already_scraped() for submission in self.reddit.subreddit(subreddit).hot(): if submission.id not in already_scraped and not submission.stickied: debug(f"Scraping submission: {submission.id}.") out = self._scrape( submission, render_images=render_images, render_tts=render_tts ) self._write_submission_into_scraped_file(submission) return out else: debug(f"Skipping submission: {submission.id}.")
def get_generated_tts_from_comments(self, comments): tts = TTS(self.cfg) generated_tts = [] debug(f"Rendering text-to-speech files.") for index, comment in tqdm(enumerate(comments)): generated_tts.append( tts.get_mp3_from_text( text=comment.body, mp3_path=f"{self.working_dir}/{COMMENTS_TTS_FILEPATH_TEMPLATE.format(index=index)}", use_paid_tts=bool(self.cfg.reddit.get("use_paid_tts", False)), voice_id=comment.author, ) ) return generated_tts
def get_rendered_comments(self, render_images=True, render_tts=True): Path(self.working_dir).mkdir(exist_ok=True, parents=True) self.comments = self.get_interesting_comments_from_submission() debug( f"Found {len(self.comments)} interesting comments for submission: {self.submission.id}" ) self.rendered_images = ( self.get_rendered_images_from_comments(self.comments) if render_images else [] ) self.rendered_tts = ( self.get_generated_tts_from_comments(self.comments) if render_tts else [] ) return self
def concat_videos_complex( self, videos, output_path, transition=None, ): """Slower, but capable of concacting videos with different attibutes.""" if transition: videos = self._add_transitions_to_videos(transition, videos) debug( f"Concacting videos: {videos[0]} {'...' if len(videos) > 2 else ''} {videos[-1]}" ) _concat_videos_with_melt(videos, output_path) debug(f"Concacted video ready at: {output_path}") return output_path
def concat_videos_simple(self, videos, output_path): """Only use to concat videos with the same attributes (codec, resolution, fps...)""" ffmpeg_concat_file = self._get_concat_file(videos) args = [ self.cfg.video.ffmpeg_path, "-f", "concat", "-safe", "0", "-i", ffmpeg_concat_file, "-c", "copy", "-y", output_path, ] try: run_subprocess(args) debug(f"Concacted video ready at: {output_path}") finally: os.remove(ffmpeg_concat_file) return output_path
def get_rendered_images_from_comments(self, comments): rendered_comments = [] debug(f"Rendering images.") for i, comment in tqdm(enumerate(comments)): rendered_comments.append(self._get_rendered_image_from_comment(i, comment)) return rendered_comments