Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now on ClarityCoders' autotube fork #1

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .env_sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# reddit credentials
REDDIT_CLIENT_SECRET=""
REDDIT_CLIENT_ID=""
REDDIT_USER_AGENT=""

# Magick binaries path
# Change it, it may be different
IMAGEMAGICK_BINARY="C:\Program Files\ImageMagick-7.1.0-Q16-HDRI\magick.exe"

# Google
GOOGLE_CLIENT_ID=""
GOOGLE_CLIENT_SECRET=""
249 changes: 242 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,243 @@
/env

# Created by https://www.toptal.com/developers/gitignore/api/pycharm+all,python
# Edit at https://www.toptal.com/developers/gitignore?templates=pycharm+all,python

### PyCharm+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### PyCharm+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360

.idea/

# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023

*.iml
modules.xml
.idea/misc.xml
*.ipr

# Sonarlint plugin
.idea/sonarlint

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
/data
__pycache__
client_secrets.json
*.json
*.mp4
video.mp4
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# specific to project
data/
moviepy-master/
videos/
dump.txt
main.py-oauth2.json
# End of https://www.toptal.com/developers/gitignore/api/pycharm+all,python
111 changes: 111 additions & 0 deletions MovieMaker/MovieMaker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import os.path
import platform
import random
from pathlib import Path
from secrets import token_hex
from typing import List

from environs import Env
from moviepy.audio.AudioClip import CompositeAudioClip
from moviepy.editor import ImageSequenceClip, VideoFileClip, concatenate_videoclips, TextClip, AudioFileClip
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip

from RedditDownloaderExceptions import MissingImageMagickBinariesException, MissingMP3FilesInMusicsDir
from .utils import Utils


class CreateMovie(Utils):
def __init__(self, env: Env, base_path: str):
Utils.__init__(self)
self.__env = env
self.__path = base_path
self.__music_path = os.path.join(self.__path, "musics\\")
self.__video_path = os.path.join(self.__path, "videos\\")
if not os.path.isdir(self.__video_path):
os.mkdir(self.__video_path)

if not os.path.isdir(self.__music_path):
os.mkdir(self.__music_path)

def _create_video(self, submission_data: List[dict]) -> str:

# check if magick binaries exists if on windows
if platform.system() == "Windows" and (
not self.__env("IMAGEMAGICK_BINARY") or not os.path.isfile(self.__env("IMAGEMAGICK_BINARY"))):
raise MissingImageMagickBinariesException(self.__env("IMAGEMAGICK_BINARY"))

# check if there's music inside the musics dir
if not list(Path(self.__music_path).rglob("*.mp3")):
raise MissingMP3FilesInMusicsDir(self.__music_path)

clips = []
for submission in submission_data:
if "gif" not in submission["image_path"][-3:]:
clip = ImageSequenceClip([submission["image_path"]], durations=[12])
clips.append(clip)
continue
clip_lengthener = [VideoFileClip(submission["image_path"])] * 60
clip = concatenate_videoclips(clip_lengthener).subclip(0, 12)
clips.append(clip)

clip = concatenate_videoclips(clips).subclip(0, 60)
colors = ['yellow', 'LightGreen', 'LightSkyBlue', 'LightPink4', 'SkyBlue2', 'MintCream', 'LimeGreen',
'WhiteSmoke', 'HotPink4', 'PeachPuff3', 'OrangeRed3', 'silver']
random.shuffle(colors)

text_clips = []
notification_sounds = []

for i, post in enumerate(submission_data):
return_comment, return_count = self._add_return_comment(post['Best_comment'])

txt = TextClip(return_comment, font='Courier',
fontsize=38, color=colors.pop(), bg_color='black')
txt = txt.on_color(col_opacity=.3)
txt = txt.set_position((5, 500))
txt = txt.set_start((0, 3 + (i * 12))) # (min, s)
txt = txt.set_duration(7)
txt = txt.crossfadein(0.5)
txt = txt.crossfadeout(0.5)
text_clips.append(txt)

return_comment, _ = self._add_return_comment(post['best_reply'])

txt = TextClip(return_comment, font='Courier',
fontsize=38, color=colors.pop(), bg_color='black')
txt = txt.on_color(col_opacity=.3)
txt = txt.set_position((15, 585 + (return_count * 50)))
txt = txt.set_start((0, 5 + (i * 12))) # (min, s)
txt = txt.set_duration(7)
txt = txt.crossfadein(0.5)
txt = txt.crossfadeout(0.5)
text_clips.append(txt)

notification = AudioFileClip(os.path.join(self.__music_path, f"notification.mp3"))
notification = notification.set_start((0, 3 + (i * 12)))
notification_sounds.append(notification)
notification = AudioFileClip(os.path.join(self.__music_path, f"notification.mp3"))
notification = notification.set_start((0, 5 + (i * 12)))
notification_sounds.append(notification)

music_file = os.path.join(self.__music_path, f"music{random.randint(0, 4)}.mp3")
music = AudioFileClip(music_file)
music = music.set_start((0, 0))
music = music.volumex(.4)
music = music.set_duration(59)

new_audioclip = CompositeAudioClip([music] + notification_sounds)
filename = token_hex(4)
filename_clips = filename + "_clips.mp4"
filename += ".mp4"
clip.write_videofile(f"{self.__video_path}{filename_clips}", fps=24)

clip = VideoFileClip(f"{self.__video_path}{filename_clips}", audio=False)
clip = CompositeVideoClip([clip] + text_clips)
clip.audio = new_audioclip
clip.write_videofile(f"{self.__video_path}{filename}", fps=24)

if os.path.exists(os.path.join(self.__video_path, f"{filename_clips}")):
os.remove(os.path.join(self.__video_path, f"{filename_clips}"))

return self.__video_path + filename
1 change: 1 addition & 0 deletions MovieMaker/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .MovieMaker import CreateMovie
Loading