def do_process_video_task(question): url = question.kq.video try: tempdir = tempfile.mkdtemp() frame = process_video(tempdir, url) if frame is not None: video_id = extract_YT_video_id(url) if video_id == u'': raise NotFound(url) question.last_frame.save("%s.png" % video_id, File(open(frame))) except IOError: logger.error('Video %s could not be downloaded or processed. Probably the codec is not supported, please try again with a newer YouTube video.' % url) except NotFound: logger.error('Video %s not found' % url) finally: shutil.rmtree(tempdir)
def do_process_video_task(question_id): from moocng.courses.models import Question question = Question.objects.get(id=question_id) url = question.kq.video try: tempdir = tempfile.mkdtemp() frame = process_video(tempdir, url) if frame is not None: video_id = extract_YT_video_id(url) if video_id == u'': raise NotFound(url) question.last_frame.save("%s.png" % video_id, File(open(frame))) except IOError: logger.error('Video %s could not be downloaded or processed. Probably the codec is not supported, please try again with a newer YouTube video.' % url) except NotFound: logger.error('Video %s not found' % url) finally: shutil.rmtree(tempdir)
def get_last_frame(self, content_id, tmpdir): return process_video(tmpdir, "http://youtu.be/%s" % content_id)