Apr-18-2022, 06:39 PM
(This post was last modified: Apr-18-2022, 06:39 PM by jttolleson.)
Hi all, i have lightened up used flask, well drilled w flask and now IT WORKS GREAT!!! the console works and the youtube smash up script work, together also.....so ......here they are the python3 scripts with flask and ffmpeg and yt dlp.
input-console.py
input-console.py
#!/usr/bin/env python3 # -*- coding: UTF-8 -*- import subprocess from subprocess import Popen, PIPE, STDOUT from flask import Flask, Response, request, render_template, redirect, url_for import time app = Flask(__name__) @app.route('/out/<searchterms>/<number>') def out(searchterms, number): def output(): yield """<html><body style='color:MediumSeaGreen;'><h1><div id='data' style='text-align: center;'>nothing received yet...for </div></h1><script>var div = document.getElementById('data');</script></body></html>""" p = subprocess.Popen('sudo python3 /var/video/cgi-bin/ytsmash.py '+str(searchterms)+' '+str(number), shell=True, stdout=subprocess.PIPE, stderr=STDOUT) while True: out = ((p.stdout.readline()).strip()) out =str(out) if out != "b''": print (out) yield """<html><body><h1><script>div.innerHTML = "OUTPUT: """+out+""" " ;</script></h1></body></html>""" time.sleep(.27) else: yield """<html><body><h3>Watch Movie After Output is done...</h3><form action='https://lftr.biz:8080/movies/output2.mp4'> <input type="submit" value="Watch Movie!!!"></form></body></html>""" return Response(output()) @app.route('/ytsmash',methods = ['POST', 'GET']) def searchterms(): if request.method == 'POST': searchterms = request.form['searchterms'] number = request.form['number'] return redirect(url_for('out',searchterms = searchterms, number = number)) else: searchterms = request.args.get('searchterms') number = request.args.get('number') return """<html><style>body {background: #1339de;} #data { text-align: center; }</style><body> <form method ='POST'> Search Terms: <input type="text" name="searchterms" id="searchterms"> Query Length: <input type="number" name="number" id="number" value="4"> <input type="submit" value="Make a YouTube SmashUp!!!"> </form></body></html>""" if __name__ == "__main__": app.run(host='0.0.0.0', debug=True, ssl_context=('/var/security/lftr.biz.crt', '/var/security/lftr.biz.key'), port=8000)ytsmash.py
#!/usr/bin/env python # -*- coding: UTF-8 -*- import os import subprocess from subprocess import Popen, PIPE, STDOUT from pytube import YouTube from youtube_search import YoutubeSearch import sys #python programming searchterms = str(sys.argv[1]) number = int(sys.argv[2]) videos = [] videos = YoutubeSearch(searchterms, max_results=number).to_dict() remove = ('cd /var/video/ && sudo rm -r videos && sudo rm -r videos2') make = ('cd /var/video && sudo mkdir videos && sudo mkdir videos2') subprocess.call(remove, shell=True, stderr=subprocess.STDOUT) subprocess.call(make, shell=True, stderr=subprocess.STDOUT) #download yt vids for v in videos: url_suffix = v['url_suffix'] link = 'https://youtube.com'+(str(url_suffix)) try: dl = ('cd /var/video/videos && sudo yt-dlp -f 135 %s')%(link) subprocess.call(dl, shell=True, stderr=subprocess.STDOUT) # YouTube(link).streams.filter(res="720p",file_extension='mp4').first().download('/var/video/videos') except: print ('1 dload failed!') print ('Download Completed!') print ('Download Task Completed!') #slice up video os.chdir('/var/video/videos') for count, f in enumerate(os.listdir()): f_name, f_ext = os.path.splitext(f) f_name = str(count) new_name = f'{f_name}{f_ext}' os.rename(f, new_name) list = os.listdir('/var/video/videos/') print (list) f= open("/var/video/videos2/vidslist.txt","w+") for l in list: intro = ('sudo ffmpeg -ss 0:00 -i /var/video/videos/'+str(l)+' -t 7.0 -c copy -y /var/video/videos2/intro'+str(l)) subprocess.call(intro, shell=True, stderr=subprocess.STDOUT) f.write("file intro'%s'\r\n" % l) for l in list: middle1 = ('sudo ffmpeg -ss 0:08 -i /var/video/videos/'+str(l)+' -t 22.0 -c copy -y /var/video/videos2/middle1'+str(l)) subprocess.call(middle1, shell=True, stderr=subprocess.STDOUT) f.write("file middle1'%s'\r\n" % l) for l in list: middle2 = ('sudo ffmpeg -ss 0:28 -i /var/video/videos/'+str(l)+' -t 12.0 -c copy -y /var/video/videos2/middle2'+str(l)) subprocess.call(middle2, shell=True, stderr=subprocess.STDOUT) f.write("file middle2'%s'\r\n" % l) for l in list: middle3 = ('sudo ffmpeg -ss 0:45 -i /var/video/videos/'+str(l)+' -t 25.0 -c copy -y /var/video/videos2/middle3'+str(l)) subprocess.call(middle3, shell=True, stderr=subprocess.STDOUT) f.write("file middle3'%s'\r\n" % l) for l in list: middle4 = ('sudo ffmpeg -ss 1:00 -i /var/video/videos/'+str(l)+' -t 7.0 -c copy -y /var/video/videos2/middle4'+str(l)) subprocess.call(middle4, shell=True, stderr=subprocess.STDOUT) f.write("file middle4'%s'\r\n" % l) for l in list: end = ('sudo ffmpeg -ss 1:24 -i /var/video/videos/'+str(l)+' -t 6.0 -c copy -y /var/video/videos2/end'+str(l)) subprocess.call(end, shell=True, stderr=subprocess.STDOUT) f.write("file end'%s'\r\n" % l) f.close() print ('finished slicing videos') print ('Starting FFMPEG...') #make smashup video and serve it ffmpeg = ('''cd /var/video/videos2/ && sudo ffmpeg -f concat -i /var/video/videos2/vidslist.txt -c copy -y /var/video/movies/input.mp4 && sudo ffmpeg -i /var/video/movies/input.mp4 -map 0:v -c:v copy -bsf:v h264_mp4toannexb -y /var/video/movies/raw.h264 && sudo ffmpeg -fflags +genpts -r 120 -i /var/video/movies/raw.h264 -i /var/video/movies/input.mp4 -map 0:v -c:v copy -map 1:a -af atempo=2 -movflags faststart -y /var/video/movies/output.mp4 && sudo ffmpeg -i /var/video/movies/output.mp4 -vf mpdecimate,setpts=N/FRAME_RATE/TB -y /var/video/movies/output2.mp4 && cd /var/video/movies && sudo cp output2.mp4 '''+str(searchterms).replace(' ',',').replace('/',',')+'''.mp4''') proc = subprocess.Popen(ffmpeg, shell=True, stdout=subprocess.PIPE) #proc = subprocess.Popen('npx kill-port 8000', shell=True, stdout=subprocess.STDOUT)