let's say I created a basic web for converting youtube videos to gifs
this is my views in django code
from django.shortcuts import render
from django.http import HttpResponse
from django.template import RequestContext
from django.shortcuts import render_to_response
import pafy
from PIL import Image
from moviepy.editor import *
import os
context = RequestContext(request)
if request.GET:
link = request.GET.get('link','')
url = link
try:
video = pafy.new(url)
except:
return render_to_response("generated/invalid.html", context)
video = video.getbest()
if os.path.isfile(os.getcwd()+'\\static\\'+video.title+'.gif')==True:
gifpath=video.title+'.gif'
context_dict = {'staticpath':gifpath}
return render_to_response("generated/generated.html", context_dict, context)
video.download(quiet=True)
clip = (VideoFileClip(os.getcwd()+"\\"+video.title+'.'+video.extension).resize(0.4))
clip.write_gif(os.getcwd()+'\\static\\'+video.title+'.gif', fps=9, opt='optimizeplus', loop=0)
gifpath=video.title+'.gif'
context_dict = {'staticpath':gifpath}
return render_to_response("generated/generated.html", context_dict, context)
it works fine, but after I convert 2-5 videos (it's random) it gives me this error,
from the looks of it, the cause is in the VideoFileClip method AttributeError
It will works again if I restart the django server, strange!!!
in the django debugger, the exception is [WinError 6] The handle is invalid
Tried it with windows 8.1 64 bit and windows 7 32 bit
UPDATE, I think it's the gif converter causing this, after I turned on the downloading status pafy confirmed I downloaded the video (look at uppest and lowest request)
but what makes it strange is that, the error pops out after running it random times. Do you think it's my code's fault or the lib?