├── youdditProfilePic.png ├── videoDistributer ├── maxClipDuration.py └── distributer.py ├── scraper └── redditScraper.py ├── LICENSE ├── splicer ├── processing.py └── splicer.py ├── .gitignore ├── downloader └── videoDownloader.py ├── README.md └── main.py /youdditProfilePic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CalvinRossSmith/Youddit-Public/HEAD/youdditProfilePic.png -------------------------------------------------------------------------------- /videoDistributer/maxClipDuration.py: -------------------------------------------------------------------------------- 1 | from moviepy.editor import VideoFileClip 2 | 3 | def maxDuration(clips, maxDura): 4 | #maxDura is in seconds 5 | ret = [] 6 | for clip in clips: 7 | try: 8 | vid = VideoFileClip(clip) 9 | if vid.duration <= maxDura: 10 | ret.append({"clip": clip, "duration": vid.duration}) 11 | vid.reader.close() 12 | vid.close() 13 | except: 14 | print ("fail in max") 15 | return ret -------------------------------------------------------------------------------- /scraper/redditScraper.py: -------------------------------------------------------------------------------- 1 | import praw 2 | 3 | reddit = praw.Reddit(client_id='CLIENT_ID', 4 | client_secret='CLIENT_SECRET', 5 | user_agent='USER_AGENT') 6 | 7 | def redditScraper(subReddit, amountOfPosts=None, topOfWhat='week'): 8 | listOfPosts = [] 9 | for submission in reddit.subreddit(subReddit).top(topOfWhat, limit=amountOfPosts): 10 | urlAndTitle = {} 11 | urlAndTitle["url"] = submission.url 12 | urlAndTitle["title"] = submission.title 13 | listOfPosts.append(urlAndTitle) 14 | print ("Grabing " + str(len(listOfPosts)) + " posts from r/" + subReddit) 15 | print ("") 16 | return listOfPosts -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Calvin Smith 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /splicer/processing.py: -------------------------------------------------------------------------------- 1 | from moviepy.editor import CompositeVideoClip, ColorClip 2 | 3 | out_width = 1920 4 | out_height = 1080 5 | out_ratio = out_width / out_height 6 | 7 | def processClip(clip): 8 | """ 9 | Preprocesses a single clip to be concatanted and outputted 10 | """ 11 | clip_width = clip.w 12 | clip_height = clip.h 13 | 14 | front_clip = clip.copy() 15 | if clip_width / clip_height > out_ratio: 16 | front_clip = front_clip.resize(width=out_width) 17 | back_clip = ColorClip((out_width, out_height), (0, 0, 0), duration=clip.duration) 18 | return overlayClips(front_clip, back_clip) 19 | elif clip_width / clip_height < out_ratio: 20 | front_clip = front_clip.resize(height=out_height) 21 | back_clip = ColorClip((out_width, out_height), (0, 0, 0), duration=clip.duration) 22 | return overlayClips(front_clip, back_clip) 23 | else: 24 | return clip.resize((out_width, out_height)) # clip is already the right size, just send it back with no changes 25 | 26 | 27 | def processClips(clips): 28 | """ 29 | Processes a list of clips to be concatanted and outputted 30 | """ 31 | for clip in clips: 32 | yield processClip(clip) 33 | 34 | 35 | def overlayClips(clipTop, clipBottom): 36 | """ 37 | Overlays a one clip on top of another 38 | Used for doing the gauss blur style bars on the video 39 | """ 40 | return CompositeVideoClip([clipBottom.set_pos("center"), clipTop.set_pos("center")], size=(out_width, out_height)) 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /videoDistributer/distributer.py: -------------------------------------------------------------------------------- 1 | from moviepy.editor import VideoFileClip 2 | import random 3 | import time 4 | 5 | def getDuration(clips): 6 | total = 0.0 7 | for clip in clips: 8 | try: 9 | duration = clip["duration"] 10 | total += duration 11 | except: 12 | print("failuer") 13 | return total 14 | 15 | def distabutor(clips, minDur, done=[]): 16 | n = getDuration(clips) // minDur 17 | print(clips) 18 | clips.sort(key=lambda x: x["duration"], reverse=True) 19 | buckets = [] 20 | for x in range(int(n)): 21 | buckets.append([]) 22 | 23 | curBucket = 0 24 | while len(clips) > 0: 25 | clip = clips[0] 26 | if len(buckets) == 0: 27 | break 28 | buckets[curBucket].append(clip) 29 | if getDuration(buckets[curBucket]) > minDur: 30 | done.append(buckets[int(curBucket)]) 31 | del buckets[curBucket] 32 | if(len(buckets) == 0): 33 | break 34 | clips = clips[1:] 35 | curBucket = int((curBucket + 1) % len(buckets)) 36 | 37 | unused = [] 38 | for x in buckets: 39 | for y in x: 40 | unused.append(y) 41 | 42 | unused = unused + clips 43 | 44 | if getDuration(unused) > minDur: 45 | return distabutor(unused, minDur, done) 46 | 47 | 48 | return (done) 49 | 50 | 51 | def splitClips(clips, minDuration): 52 | """ 53 | Splits the clips into sub lists that have at least minDuration seconds of length 54 | """ 55 | doneBuckets = distabutor(clips, minDuration) 56 | 57 | outputa = list(map(lambda x: list(map(lambda y: y["clip"], x)), doneBuckets)) 58 | 59 | return (outputa) 60 | 61 | 62 | if __name__ == "__main__": 63 | outp = splitClips(["../testfiles/clip1.mp4", "../testfiles/clip2.mp4", "../testfiles/clip3.mp4", "../testfiles/clip4.mp4"], 10) 64 | for x in outp: 65 | print(x) -------------------------------------------------------------------------------- /downloader/videoDownloader.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | import youtube_dl 3 | 4 | #used to log errors 5 | class myLogger(object): #myLogger is a class that hold functions and depending on what the log is 6 | #we decide if we want to keep it rn we only print to console an error message if and error occurs 7 | #this just makes it so that console doesn't get bogged down 8 | def debug(self, msg): 9 | pass #personly don't want to clog console 10 | 11 | def warning(self, msg): 12 | pass #personly don't want to clog console 13 | 14 | def error(self, msg): 15 | pass 16 | #print(msg) #We should atleast see the errors 17 | 18 | #used to log copletion of a video being downloaded 19 | def myHook(_done): 20 | #myHook is the close to the same as the logger except it gets passed an array that has different 21 | #stats about the current run 22 | #Right now we are only checking the status stat to see if it is equal to finish and if it is we print to console to 23 | #keep things clean 24 | if _done['status'] == 'finished': 25 | pass 26 | #print('Done downloading, now converting ...') 27 | 28 | 29 | #the function tha uses the youtube downloader options to start downloading 30 | def videoDownload(_url, pathToDownload, _format): #the url should be a list of string urls 31 | 32 | #the options that we want when downloading a video 33 | ydlOpts = { 34 | 'format': ('bestvideo[ext='+_format+']+bestaudio[ext=m4a]/'+_format), #the format that it can be 35 | 'logger': myLogger(), #this is used to log errors and such 36 | 'progress_hooks': [myHook], #says when it's done dont know how useful 37 | 'noplaylist': 'true', #makes it so that if the link is in a youtube playlist it wont download the whole playlist 38 | 'outtmpl': (pathToDownload), #output location and name 39 | 'ignoreerrors': 'true', #if error move one 40 | 'restrictfilenames': 'true' #gets rid of spaces in output name 41 | } 42 | with youtube_dl.YoutubeDL(ydlOpts) as ydl: 43 | ydl.download(_url) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Youddit-Public 2 | 3 | ![Youddit](youdditProfilePic.png) 4 | ## Demo 5 | 6 | [Demo YouTube Channel](https://www.youtube.com/channel/UCTGH8r_5szNZ6riHOWlU0wg "Demo") 7 | 8 | ## Contribuitors 9 | 10 | [Calvin Smith](https://github.com/CalvinRossSmith "Calvin Smith") & 11 | [Owen Anderson](https://github.com/shimmy568 "Owen Anderson") 12 | 13 | 14 | ## Summary 15 | 16 | Youddit is made up of customizable python scripts. These scripts include a reddit web scraper that looks for urls of a selected subreddit. A downloading script is then called that will search each url to look and see if a video is attached to the url, if so the video will be downloaded. Once a whole grouping of videos are downloaded they are randomly compiled into 5 minute compilations. Once the video is created it is uploaded to YouTube. 17 | 18 | ## My YouTube Channel 19 | 20 | [Lamp Board](https://www.youtube.com/channel/UCTGH8r_5szNZ6riHOWlU0wg?view_as=subscriber "Lamp Board") 21 | 22 | ## Quick Start 23 | 24 | 1. Install the required pip packages (moviepy, praw, youtube_dl) 25 | 2. Input your own client id for reddit (https://github.com/reddit-archive/reddit/wiki/oauth2) inside of scraper/redditScraper.py 26 | 3. Go to ./main.py 27 | 4. Decide which subreddits you would like to download videos from and add/remove them from the list “subredditList” 28 | 5. Change what you would like your channel name to be, this will be the name of the directory where the clips are temporarily stored 29 | 6. Add the absolute path for downloading to “pathToDownload” 30 | 7. Add the absolute path for your final save location “finalSave” 31 | 8. Create a directory at root called “copyrightFreeMusic” 32 | 9. Move your copyright free music into the directory from above 33 | 10. Type python3 ./main.py into termal to start 34 | 35 | ## ToDo 36 | - [x] Video Downloader 37 | - [x] Scrape reddit for videos to download 38 | - [x] Resizing tool for videos 39 | - [x] Create a distrubutor to organize videos into 5 minute montages 40 | - [x] Discard clips over a certian length 41 | - [x] Compile the videos together 42 | - [x] Overlay music to videos 43 | - [x] Stress test it to make sure it can handle 5000+ clips compiling down to 150+ videos 44 | - [ ] Finish a youtube uploader 45 | - [ ] Create a config file tool so that a user can quickly switch between subreddits and youtube channels 46 | 47 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | 2 | from scraper import redditScraper 3 | from downloader import videoDownloader 4 | from splicer import splicer 5 | from videoDistributer import distributer 6 | from videoDistributer import maxClipDuration 7 | import random 8 | import ntpath 9 | import os 10 | import shutil 11 | import gc 12 | 13 | def randomName (__paths): 14 | return (ntpath.basename(random.choice(__paths))) 15 | 16 | def mainYoudit(): 17 | channel = 'CHANNEL NAME' 18 | subredditList = ['SUBREDDIT1', 'SUBREDDIT2', 'SUBREDDIT3', 'SUBREDDIT4', 'SUBREDDIT5', 'SUBREDDIT6', 'SUBREDDIT7', 'SUBREDDIT8'] 19 | pathToDownload = ('/ABSOLUTEPATH/'+channel+'/') 20 | format = 'mp4' 21 | finalSave = ('/ABSOLUTEPATH/'+channel+'/') 22 | 23 | for subreddit in subredditList: 24 | listOfPosts = redditScraper.redditScraper(subreddit, amountOfPosts=None,topOfWhat='all') 25 | for post in listOfPosts: 26 | path = (pathToDownload + post["title"] + "." + format) 27 | videoDownloader.videoDownload([post["url"]], path, format) 28 | listOfPaths = ([(pathToDownload+f) for f in os.listdir(pathToDownload) if os.path.isfile(os.path.join(pathToDownload, f))]) 29 | 30 | print("") 31 | print("Sorting by max duration") 32 | listWithDurMax = maxClipDuration.maxDuration(listOfPaths, 45) 33 | listOfPaths = None 34 | print("") 35 | print("Sorting into buckets") 36 | bucketListPaths = distributer.splitClips(listWithDurMax, 300) 37 | print("") 38 | print("Grabing Music") 39 | listMusicPath = ([('./copyrightFreeMusic/'+f) for f in os.listdir('./copyrightFreeMusic/') if os.path.isfile(os.path.join('./copyrightFreeMusic/', f))]) 40 | if not os.path.exists(finalSave): 41 | os.makedirs(finalSave) 42 | vidNum = 1 43 | for pathLists in bucketListPaths: 44 | gc.collect() 45 | print("") 46 | print("Making video # "+str(vidNum)+"/"+str(len(bucketListPaths))) 47 | titleName = randomName(pathLists) 48 | try: 49 | splicer.fullVideoSplicer(pathLists, finalSave+titleName, pathToMusic=listMusicPath) 50 | except: 51 | print ("failed during making a video") 52 | print("") 53 | vidNum += 1 54 | gc.collect() 55 | print("") 56 | print("Removing the cached clips") 57 | shutil.rmtree(pathToDownload) 58 | 59 | if __name__ == "__main__": 60 | mainYoudit() 61 | -------------------------------------------------------------------------------- /splicer/splicer.py: -------------------------------------------------------------------------------- 1 | from moviepy.editor import concatenate_videoclips, VideoFileClip, CompositeAudioClip, AudioFileClip, afx 2 | from splicer import processing as pros 3 | from random import shuffle 4 | import gc 5 | 6 | def loadVideos(paths): 7 | clips = [] 8 | for path in paths: 9 | vid = VideoFileClip(path) 10 | clips.append(vid) 11 | return clips 12 | 13 | def interlaceClips(clips, clip): 14 | outputClips = [] 15 | 16 | for x in clips: 17 | outputClips.append(x) 18 | outputClips.append(clip) 19 | 20 | outputClips = outputClips[:-1] 21 | 22 | return outputClips 23 | 24 | def spliceVideos(paths, interlace=None, startClip=None, endClip=None): 25 | if startClip != None: 26 | clips = [startClip] 27 | else: 28 | clips = [] 29 | 30 | clips = loadVideos(paths) 31 | 32 | clips = list(pros.processClips(clips)) 33 | 34 | if interlace != None: 35 | clips = interlaceClips(clips, interlace) 36 | 37 | if endClip != None: 38 | clips.append(endClip) 39 | vid = concatenate_videoclips(clips, method="compose") 40 | return vid , clips 41 | 42 | def overlayMusic (video, musicPath): 43 | videoLen = video.duration 44 | if not musicPath == None: 45 | shuffle(musicPath) 46 | try: 47 | music = AudioFileClip(musicPath[0]) 48 | except: 49 | shuffle(musicPath) 50 | music = AudioFileClip(musicPath[0]) 51 | musicLooped = afx.audio_loop(music, duration=videoLen) 52 | if musicLooped.duration > videoLen: 53 | musicLooped.set_duration(videoLen) 54 | try: 55 | vidAud = video.audio.volumex(1) 56 | except: 57 | vidAud = video.audio 58 | finAud = CompositeAudioClip([musicLooped.volumex(0.1),vidAud]) 59 | return finAud, music, musicLooped 60 | else: 61 | return video.audio 62 | 63 | def fullVideoSplicer(paths, saveTo, interlace=None, startClip=None, endClip=None, pathToMusic=None): 64 | if not startClip == None: 65 | startClip = VideoFileClip(startClip) 66 | if not interlace == None: 67 | interlace = VideoFileClip(interlace) 68 | if not endClip == None: 69 | endClip = VideoFileClip(endClip) 70 | final, clips = spliceVideos(paths, interlace=interlace, startClip=startClip, endClip=endClip) 71 | final.audio, music, musicLooped = overlayMusic(final, pathToMusic) 72 | print (final.duration) 73 | final.write_videofile(saveTo, codec='libx265', preset='ultrafast') 74 | for clip in clips: 75 | clip.close() 76 | musicLooped.close() 77 | music.close() 78 | final.close() 79 | gc.collect() 80 | 81 | 82 | 83 | if __name__ == "__main__": 84 | final, clips = spliceVideos(["../testfiles/clip1.mp4", "../testfiles/clip2.mp4", "../testfiles/clip3.mp4", "../testfiles/clip4.mp4"], interlace=VideoFileClip("../testfiles/interlace.mp4"), startClip=VideoFileClip("../testfiles/end.mp4"), endClip=VideoFileClip("../testfiles/end.mp4")) 85 | #final = spliceVideos(["../testfiles/clip3.mp4"]) 86 | #final = pros.processClip(VideoFileClip("../testfiles/clip4.mp4")) 87 | #final.preview() 88 | final.write_videofile("outputfile.mp4", fps=30, codec='libx265', bitrate='8000k', preset='ultrafast', threads=4) --------------------------------------------------------------------------------