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()
Ejemplo n.º 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()
Ejemplo n.º 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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 9
0
 def dehydrate_solutionID(self, bundle):
     return extract_YT_video_id(bundle.obj.solution_video)
Ejemplo n.º 10
0
 def dehydrate_videoID(self, bundle):
     return extract_YT_video_id(bundle.obj.video)
Ejemplo n.º 11
0
 def get_embeded_code_for_promotion_video(self):
     if self.promotion_video:
         return extract_YT_video_id(self.promotion_video)
Ejemplo n.º 12
0
 def get_embeded_code_for_promotion_video(self):
     if self.promotion_video:
         return extract_YT_video_id(self.promotion_video)
Ejemplo n.º 13
0
 def dehydrate_solutionID(self, bundle):
     return extract_YT_video_id(bundle.obj.solution)
Ejemplo n.º 14
0
 def dehydrate_videoID(self, bundle):
     return extract_YT_video_id(bundle.obj.video)