2

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, enter image description here 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 2

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) enter image description here

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?

Anil_M
  • 10,893
  • 6
  • 47
  • 74
  • 1
    hmmm ok, previous comments don't apply then, deleted. It's interesting that the error is in the VideoFileClip.__del__ function. To me that would indicate that the library has a problem, but then it's Python and very easy for us as developers to manipulate an object to cause an error so without all your code I couldn't say for sure. – Endophage Sep 29 '14 at 23:45
  • @Endophage thanks, I'm contacting the library dev now. But what makes it strange is that it will only works after I restart the django server. Sorry, what do you mean all of my code? I only have 2 django apps and they are not sharing var or connected by any means – Abirafdi Raditya Putra Sep 29 '14 at 23:51
  • 2
    If you have some logic path that ends up doing something with the reader attribute on the VideoFileClip instance it could cause this error. What I meant was without crawling through all your code I couldn't tell you whether that's the problem. Note it also says `Exception ignored`. Have a read of the \_\_del__ docs, especially the red box https://docs.python.org/2/reference/datamodel.html#object.__del__ – Endophage Sep 30 '14 at 00:06

0 Answers0