def forwards(self, orm):
        "Write your forwards methods here."
        for course in orm['courses.Course'].objects.all():
            course.promotion_media_content_id = extract_YT_video_id(course.promotion_video)
            course.promotion_media_content_type = "youtube"
            course.save()

        for knowledgequantum in orm['courses.KnowledgeQuantum'].objects.all():
            knowledgequantum.media_content_id = extract_YT_video_id(knowledgequantum.video)
            knowledgequantum.media_content_type = "youtube"
            knowledgequantum.save()

        for question in orm['courses.Question'].objects.all():
            question.solution_media_content_id = extract_YT_video_id(question.solution_video)
            question.solution_media_content_type = "youtube"
            question.save()
예제 #2
0
 def dehydrate_solutionID(self, bundle):
     # Only return solution if the deadline has been reached, or there is
     # no deadline
     unit = bundle.obj.kq.unit
     if unit.unittype != 'n' and unit.deadline > datetime.now(unit.deadline.tzinfo):
         return None
     return extract_YT_video_id(bundle.obj.solution_video)
    def forwards(self, orm):
        "Write your forwards methods here."
        for course in orm['courses.Course'].objects.all():
            course.promotion_media_content_id = extract_YT_video_id(course.promotion_video)
            course.promotion_media_content_type = "youtube"
            course.save()

        for knowledgequantum in orm['courses.KnowledgeQuantum'].objects.all():
            knowledgequantum.media_content_id = extract_YT_video_id(knowledgequantum.video)
            knowledgequantum.media_content_type = "youtube"
            knowledgequantum.save()

        for question in orm['courses.Question'].objects.all():
            question.solution_media_content_id = extract_YT_video_id(question.solution_video)
            question.solution_media_content_type = "youtube"
            question.save()
예제 #4
0
 def dehydrate_solutionID(self, bundle):
     # Only return solution if the deadline has been reached, or there is
     # no deadline
     unit = bundle.obj.kq.unit
     if unit.unittype != 'n' and unit.deadline > datetime.now(unit.deadline.tzinfo):
         return None
     return extract_YT_video_id(bundle.obj.solution)
예제 #5
0
파일: tasks.py 프로젝트: abdoullahi/moocng
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)
예제 #6
0
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)
예제 #7
0
def process_video(tempdir, url):
    """Download the youtube video associated with the KQ of this question
    and extract the last frame of such video."""

    video_id = extract_YT_video_id(url)
    if video_id == u'':
        raise NotFound(url)
    url = "http://www.youtube.com/watch?v=%s" % video_id

    logger.info('Downloading video %s' % url)

    try:
        filename = download(url, tempdir)
        filename = path.join(tempdir, filename)
    except urllib2.HTTPError as e:
        logger.error('Error downloading video %s: %s' % (url, e))
        return None
    except:
        raise

    try:
        time = duration(filename)
        logger.info('The downloaded video %s has a duration of %s'
                    % (filename, time))
    except:
        raise

    try:
        # Get the time position of the last second of the video
        time = time.split(':')
        dt = datetime.datetime(2012, 01, 01, int(time[0]), int(time[1]),
                               int(time[2]))
        dt = dt - second
        time = "%s.900" % dt.strftime("%H:%M:%S")
        logger.info('Getting the last frame at %s' % time)
        frame = last_frame(filename, time)
    except:
        raise

    return frame
예제 #8
0
def process_video(tempdir, url):
    """Download the youtube video associated with the KQ of this question
    and extract the last frame of such video."""

    video_id = extract_YT_video_id(url)
    if video_id == u'':
        raise NotFound(url)
    url2download = "http://www.youtube.com/watch?v=%s" % video_id

    logger.info('Downloading video %s' % url2download)

    try:
        filename = download(url2download, tempdir)
        filename = path.join(tempdir, filename)
    except urllib2.HTTPError as e:
        logger.error('Error downloading video %s: %s' % (url2download, e))
        return None
    except:
        raise

    try:
        time = duration(filename)
        logger.info('The downloaded video %s has a duration of %s' %
                    (filename, time))
    except:
        raise

    try:
        # Get the time position of the last second of the video
        dt = datetime.datetime.strptime(time, "%H:%M:%S.%f")
        dt = dt - second
        fototime = dt.strftime("%H:%M:%S.%f")
        logger.info('Getting the last frame at %s' % fototime)
        frame = last_frame(filename, fototime)
    except:
        raise

    return frame
예제 #9
0
 def dehydrate_solutionID(self, bundle):
     return extract_YT_video_id(bundle.obj.solution_video)
예제 #10
0
 def dehydrate_videoID(self, bundle):
     return extract_YT_video_id(bundle.obj.video)
예제 #11
0
파일: models.py 프로젝트: minipunk/moocng
 def get_embeded_code_for_promotion_video(self):
     if self.promotion_video:
         return extract_YT_video_id(self.promotion_video)
예제 #12
0
 def get_embeded_code_for_promotion_video(self):
     if self.promotion_video:
         return extract_YT_video_id(self.promotion_video)
예제 #13
0
 def dehydrate_solutionID(self, bundle):
     return extract_YT_video_id(bundle.obj.solution)
예제 #14
0
 def dehydrate_videoID(self, bundle):
     return extract_YT_video_id(bundle.obj.video)