Ejemplo n.º 1
0
    def save(self, commit=True, *args, **kwargs):
        old_dir = ""
        new_dir = ""
        if hasattr(self, 'change_user') and self.change_user is True:
            # create new video file
            storage_path = get_storage_path_video(
                self.instance,
                os.path.basename(self.cleaned_data['video'].name))
            dt = str(datetime.datetime.now()).replace(":", "-")
            nom, ext = os.path.splitext(
                os.path.basename(self.cleaned_data['video'].name))
            ext = ext.lower()
            new_path = os.path.join(
                os.path.dirname(storage_path),
                nom + "_" + dt.replace(" ", "_") + ext)
            if self.instance.overview:
                old_dir = os.path.dirname(self.instance.overview.name)
            else:
                old_dir = os.path.dirname(os.path.join(
                    self.cleaned_data['video'].name,
                    "%04d" % self.instance.id))
            new_dir = os.path.join(
                os.path.dirname(new_path), "%04d" % self.instance.id)
            self.move_video_source_file(new_path, new_dir, old_dir)

        video = super(VideoForm, self).save(commit, *args, **kwargs)

        if hasattr(self, 'change_user') and self.change_user is True:
            self.change_encoded_path(video, new_dir, old_dir)

        if hasattr(self, 'launch_encode'):
            video.launch_encode = self.launch_encode
        return video
Ejemplo n.º 2
0
def encode_recording(recording):
    recorder = recording.recorder
    video = Video()
    video.title = recording.title
    video.owner = recording.user
    video.type = recorder.type
    # gestion de la video
    storage_path = get_storage_path_video(
        video, os.path.basename(recording.source_file))
    dt = str(datetime.datetime.now()).replace(":", "-")
    nom, ext = os.path.splitext(os.path.basename(recording.source_file))
    ext = ext.lower()
    video.video = os.path.join(os.path.dirname(storage_path),
                               nom + "_" + dt.replace(" ", "_") + ext)
    # deplacement du fichier source vers destination
    os.makedirs(os.path.dirname(video.video.path), exist_ok=True)
    os.rename(recording.source_file, video.video.path)
    video.save()
    # on ajoute d'eventuels propriétaires additionnels
    video.additional_owners.add(*recorder.additional_users.all())
    # acces privé (mode brouillon)
    video.is_draft = recorder.is_draft
    # Accès restreint (eventuellement à des groupes ou par mot de passe)
    video.is_restricted = recorder.is_restricted
    video.restrict_access_to_groups.add(
        *recorder.restrict_access_to_groups.all())
    video.password = recorder.password
    # on ajoute les eventuelles chaines
    video.channel.add(*recorder.channel.all())
    # on ajoute les eventuels theme
    video.theme.add(*recorder.theme.all())
    # on ajoute les eventuelles disciplines
    video.discipline.add(*recorder.discipline.all())
    # Choix de la langue
    video.main_lang = recorder.main_lang
    # Choix des cursus
    video.cursus = recorder.cursus
    # mot clefs
    video.tags = recorder.tags
    # transcript
    if getattr(settings, "USE_TRANSCRIPTION", False):
        video.transcript = recorder.transcript
    # Licence
    video.licence = recorder.licence
    # Allow downloading
    video.allow_downloading = recorder.allow_downloading
    # Is_360
    video.is_360 = recorder.is_360
    # Désactiver les commentaires
    video.disable_comment = recorder.disable_comment
    # add sites
    video.sites.add(*recorder.sites.all())
    video.save()

    encode_video = getattr(encode, ENCODE_VIDEO)
    encode_video(video.id)
Ejemplo n.º 3
0
def encode_recording(recording):
    video = Video()
    video.title = recording.title
    video.owner = recording.user
    video.type = Type.objects.get(id=DEFAULT_RECORDER_TYPE_ID)
    # gestion de la video
    storage_path = get_storage_path_video(
        video, os.path.basename(recording.source_file))
    dt = str(datetime.datetime.now()).replace(":", "-")
    nom, ext = os.path.splitext(os.path.basename(recording.source_file))
    ext = ext.lower()
    video.video = os.path.join(os.path.dirname(storage_path),
                               nom + "_" + dt.replace(" ", "_") + ext)
    # deplacement du fichier source vers destination
    os.makedirs(os.path.dirname(video.video.path), exist_ok=True)
    os.rename(recording.source_file, video.video.path)
    video.save()
    ENCODE_VIDEO(video.id)
Ejemplo n.º 4
0
def encode_file_exist(filename, extension, message_error, html_message_error):
    # A video file exist in the BBB directory : encode it
    print_if_debug(" - Encode BBB video file : " + filename)
    # Absolute path of the video
    source_file = os.path.join(DEFAULT_BBB_PATH, filename)

    # Filename corresponds to : internal_meeting_id.webm
    internalMeetingId = filename.replace("." + extension, "")
    # Check if the meeting already exists in Pod database
    oMeeting = Meeting.objects.filter(
        internal_meeting_id=internalMeetingId).first()
    if oMeeting:
        # Set video properties with meetng informations
        video = Video()
        video.title = oMeeting.meeting_name
        if oMeeting.encoded_by_id:
            video.owner = User.objects.get(id=oMeeting.encoded_by_id)
        video.type = Type.objects.get(id=DEFAULT_BBB_TYPE_ID)
        video.date_evt = oMeeting.session_date
        # Video management
        storage_path = get_storage_path_video(video,
                                              os.path.basename(source_file))
        dt = str(datetime.datetime.now()).replace(":", "-")
        nom, ext = os.path.splitext(os.path.basename(source_file))
        ext = ext.lower()
        # Video name
        video_name = nom + "_" + dt.replace(" ", "_") + ext
        video.video = os.path.join(os.path.dirname(storage_path), video_name)
        # Move source file to destination
        os.makedirs(os.path.dirname(video.video.path), exist_ok=True)
        os.rename(source_file, video.video.path)
        video.save()
        # Encode
        encode_video = getattr(encode, ENCODE_VIDEO)
        encode_video(video.id)
    else:
        # Meeting was certainly deleted in Pod database
        print_if_debug(" - WARNING : It seems that this meeting was deleted "
                       "from Pod database. "
                       "internal_meeting_id : " + internalMeetingId)

    return html_message_error, message_error
Ejemplo n.º 5
0
def case_studio_recording(
    html_message_error, message_error, recorder, source_file, filename
):
    # A video file exists in the Studio directory: encode it
    print_if_debug(" - Encode video file generated by Studio : " + filename)

    # Search the video infos from corresponding recording
    source_xml_file = source_file.replace(".mp4", ".xml")
    recording = Recording.objects.filter(source_file=source_xml_file).first()
    if recording:
        # Set video properties
        video = Video()
        # Video title corresponds to recording title
        video.title = recording.title
        video.owner = recording.user
        video.type = recorder.type
        video.date_evt = datetime.datetime.now()
        # Video management
        storage_path = get_storage_path_video(video, os.path.basename(source_file))
        dt = str(datetime.datetime.now()).replace(":", "-")
        name, ext = os.path.splitext(os.path.basename(source_file))
        ext = ext.lower()
        # Video name
        video_name = name + "_" + dt.replace(" ", "_") + ext
        video.video = os.path.join(os.path.dirname(storage_path), video_name)
        # Move source file to destination
        os.makedirs(os.path.dirname(video.video.path), exist_ok=True)
        os.rename(source_file, video.video.path)
        video.save()

        # Add infos from recorder (see RECORDER_ADDITIONAL_FIELDS)
        # Add any additional owners
        video.additional_owners.add(*recorder.additional_users.all())
        # Private access (draft mode)
        video.is_draft = recorder.is_draft
        # Restricted access (possibly to groups or by password)
        video.is_restricted = recorder.is_restricted
        video.restrict_access_to_groups.add(*recorder.restrict_access_to_groups.all())
        video.password = recorder.password
        # Add the possible channels
        video.channel.add(*recorder.channel.all())
        # Add the possible themes
        video.theme.add(*recorder.theme.all())
        # Add any disciplines
        video.discipline.add(*recorder.discipline.all())
        # Language choice
        video.main_lang = recorder.main_lang
        # Cursus
        video.cursus = recorder.cursus
        # Tags
        video.tags = recorder.tags
        # Transcription
        if getattr(settings, "USE_TRANSCRIPTION", False):
            video.transcript = recorder.transcript
        # Licence
        video.licence = recorder.licence
        # Allow downloading
        video.allow_downloading = recorder.allow_downloading
        # Is 360
        video.is_360 = recorder.is_360
        # Disable comments
        video.disable_comment = recorder.disable_comment
        # Add sites
        video.sites.add(*recorder.sites.all())
        # Finally save
        video.save()

        msg = "\n--\n\n"
        msg += "Start encoding file %s at %s\n--\n" % (filename, datetime.datetime.now())
        add_comment(recording.id, msg)

        # Encode
        encode_video = getattr(encode, ENCODE_VIDEO)
        encode_video(video.id)
    else:
        # Data seems to be deleted from Pod database
        print_if_debug(
            " - WARNING: It seems that this recording was deleted "
            "from Pod database. "
            "source_file: " + source_xml_file
        )

    return html_message_error, message_error
Ejemplo n.º 6
0
def save_basic_video(recording, video_src):
    # Save & encode one video corresponding to the recording without cut
    # We don't generate an intermediate video
    recorder = recording.recorder
    video = Video()
    # Video title corresponds to recording title
    video.title = recording.title
    video.owner = recording.user
    # Video type
    video.type = recorder.type
    # Video management
    storage_path = get_storage_path_video(video, os.path.basename(video_src))
    dt = str(datetime.datetime.now()).replace(":", "-")
    name, ext = os.path.splitext(os.path.basename(video_src))
    ext = ext.lower()
    video.video = os.path.join(
        os.path.dirname(storage_path),
        slugify(name) + "_" + dt.replace(" ", "_") + ext)
    # Move source file to destination
    os.makedirs(os.path.dirname(video.video.path), exist_ok=True)
    os.rename(video_src, video.video.path)
    video.save()

    # Add any additional owners
    video.additional_owners.add(*recorder.additional_users.all())
    # Private access (draft mode)
    video.is_draft = recorder.is_draft
    # Restricted access (possibly to groups or by password)
    video.is_restricted = recorder.is_restricted
    video.restrict_access_to_groups.add(
        *recorder.restrict_access_to_groups.all())
    video.password = recorder.password
    # Add the possible channels
    video.channel.add(*recorder.channel.all())
    # Add the possible themes
    video.theme.add(*recorder.theme.all())
    # Add any disciplines
    video.discipline.add(*recorder.discipline.all())
    # Language choice
    video.main_lang = recorder.main_lang
    # Cursus
    video.cursus = recorder.cursus
    # Tags
    video.tags = recorder.tags
    # Transcription
    if getattr(settings, "USE_TRANSCRIPTION", False):
        video.transcript = recorder.transcript
    # Licence
    video.licence = recorder.licence
    # Allow downloading
    video.allow_downloading = recorder.allow_downloading
    # Is 360
    video.is_360 = recorder.is_360
    # Disable comments
    video.disable_comment = recorder.disable_comment
    # Add sites
    video.sites.add(*recorder.sites.all())
    # Finally save
    video.save()

    # Rename the XML file
    # os.rename(recording.source_file, recording.source_file + "_treated")

    studio_clean_old_files()

    return video