示例#1
0
        public ActionResult Upload()
        {
            if (Request.Files.Count > 0)
            {
                var file = Request.Files[0];

                string path = SaveFileInFolder(file);
                // On recupere le format de base de la video
                int    indexOf    = file.ContentType.LastIndexOf('/') + 1;
                string format     = file.ContentType.Substring(indexOf);
                var    formatBase = new FORMAT_Service().GetFormatByName(format);
                // On recupere les infos de la video
                VideoFile videoFile = new VideoFile(path);

                double VideoDuration = videoFile.Duration.TotalMinutes;
                // On génére le prix en fonction de la durée
                double price = PriceGeneratorUtil.GetPriceByDuration(VideoDuration);

                // Si le format a été trouvé dans nos bases on va proposer les conversions liées possibles.
                if (formatBase != null)
                {
                    var listFormatTypes = new FORMAT_TYPE_Service().GetSelectListFormatTypeByFormat((int)formatBase.FK_ID_FORMAT_TYPE);

                    return(Json(new { success = "true", fileUrl = path, fileLength = file.ContentLength, fileName = file.FileName, fileFormatBase = formatBase.PK_ID_FORMAT,
                                      listFormatType = new SelectList(listFormatTypes, "Value", "Text"), fileDuration = VideoDuration.ToString(), filePrice = price.ToString() }));
                }
                else
                {
                    return(Json(new { success = "false" }));
                }
            }
            return(Json(new { success = "false" }));
        }
示例#2
0
        public static bool DoFFmpegConversion(TASK Task)
        {
            InitWorkspace();
            FORMAT formatToConvert = new FORMAT_Service().GetFormatById((int)Task.FK_ID_FORMAT_TO_CONVERT);

            try
            {
                if (Task.STATUS == (int)EnumManager.PARAM_TASK_STATUS.A_REASSEMBLER)
                {
                    Task.STATUS = (int)EnumManager.PARAM_TASK_STATUS.EN_COURS;
                    new TASK_Service().AddOrUpdateTask(Task);

                    List <TASK> listOfSubTaskByParent = new TASK_Service().GetSubTaskByMotherTask(Task.PK_ID_TASK);
                    bool        isMerged = FFmpegMergeSplits(Task, listOfSubTaskByParent);

                    if (isMerged)
                    {
                        Task.DATE_END_CONVERSION = DateTime.Now;
                        Task.STATUS = (int)EnumManager.PARAM_TASK_STATUS.EFFECTUE;
                    }
                }
                else
                if (!GetTaskAndSetIfTaskIsSplitted(Task, formatToConvert))
                {
                    Task.STATUS = (int)EnumManager.PARAM_TASK_STATUS.EN_COURS;
                    new TASK_Service().AddOrUpdateTask(Task);
                    FFMpegService.Execute(Task.FILE_URL_TEMP, formatToConvert.FORMAT_FFMPEG_VALUE, Task.FILE_URL_DESTINATION);
                    Task.DATE_END_CONVERSION = DateTime.Now;
                    Task.STATUS = (int)EnumManager.PARAM_TASK_STATUS.EFFECTUE;
                    // Verification si c'est une sous tache
                    // On vérifie si les sous taches ont été effectué ou pas.
                    if (Task.FK_ID_PARENT_TASK != null)
                    {
                        List <TASK> listOfSubTaskByParent = new TASK_Service().GetSubTaskByMotherTask((int)Task.FK_ID_PARENT_TASK);
                        int         totalEffectue         = listOfSubTaskByParent.Count(x => x.STATUS == (int)EnumManager.PARAM_TASK_STATUS.EFFECTUE);
                        if (totalEffectue.Equals(listOfSubTaskByParent.Count))
                        {
                            TASK MotherTask = new TASK_Service().GetTaskById((int)Task.FK_ID_PARENT_TASK);
                            MotherTask.STATUS = (int)EnumManager.PARAM_TASK_STATUS.A_REASSEMBLER;
                            new TASK_Service().AddOrUpdateTask(MotherTask);
                        }
                    }
                }

                new TASK_Service().AddOrUpdateTask(Task);
                return(true);
            }
            catch (Exception e)
            {
                Task.DATE_END_CONVERSION = DateTime.Now;
                Task.STATUS = (int)EnumManager.PARAM_TASK_STATUS.ERREUR;
                new TASK_Service().AddOrUpdateTask(Task);

                TRACE Trace = new TRACE {
                    FK_ID_TASK = Task.PK_ID_TASK, FK_ID_SERVER = 1, DATE_TRACE = DateTime.Now, NOM_SERVER = System.Environment.MachineName, DESCRIPTION = e.Message, METHOD = "CONVERSION FFMPEG", TYPE = "ERROR"
                };
                new TRACE_Service().AddTrace(Trace);
                return(false);
            }
        }
示例#3
0
        public JsonResult GetFormatByFormatTypeAndFormatBase(string formatTypeId, string fileFormatBase)
        {
            int FormatTypeId = 0;
            int FileFormat   = 0;

            int.TryParse(formatTypeId, out FormatTypeId);
            int.TryParse(fileFormatBase, out FileFormat);
            List <SelectListItem> slFormat = new FORMAT_Service().GetSelectListFormatByFormatTypeIdAndFormatBase(FormatTypeId, FileFormat);

            return(Json(new { listFormats = new SelectList(slFormat, "Value", "Text") }, JsonRequestBehavior.AllowGet));
        }
示例#4
0
        public ActionResult UploadFromUrl(string url)
        {
            var client = new System.Net.WebClient();

            try
            {
                var    localPath = new CONFIG_Service().GetConfigValueByName("FilesFromClientPath");
                string path      = localPath + url.Substring(url.LastIndexOf('/') + 1);
                client.DownloadFile(url, path);
                FileInfo  fileInfo  = new FileInfo(path);
                VideoFile videoFile = new VideoFile(path);

                double VideoDuration = videoFile.Duration.TotalMinutes;
                // On génére le prix en fonction de la durée
                double price = PriceGeneratorUtil.GetPriceByDuration(VideoDuration);
                // On recupere le format de base de la video
                string format     = fileInfo.Extension.Substring(fileInfo.Extension.LastIndexOf('.') + 1);
                var    formatBase = new FORMAT_Service().GetFormatByName(format);


                // Si le format a été trouvé dans nos bases on va proposer les conversions liées possibles.
                if (formatBase != null)
                {
                    var listFormatTypes = new FORMAT_TYPE_Service().GetSelectListFormatTypeByFormat((int)formatBase.FK_ID_FORMAT_TYPE);

                    return(Json(new
                    {
                        success = "true",
                        fileUrl = path,
                        fileLength = fileInfo.Length,
                        fileName = fileInfo.Name,
                        fileFormatBase = formatBase.PK_ID_FORMAT,
                        listFormatType = new SelectList(listFormatTypes, "Value", "Text"),
                        fileDuration = VideoDuration.ToString(),
                        filePrice = price.ToString()
                    }));
                }
                else
                {
                    return(Json(new { success = "false" }));
                }
            }
            catch (Exception e)
            {
                return(Json(new { success = "false" }));
            }
        }
        //ConfigurationManager.AppSettings["TranscoderTempRootDestination"];

        public static bool DoFFmpegConversion(TASK Task)
        {
            InitWorkspace();
            // on récupère le format de conversion de la tache
            FORMAT formatToConvert = new FORMAT_Service().GetFormatById((int)Task.FK_ID_FORMAT_TO_CONVERT);
            FORMAT formatBase      = new FORMAT_Service().GetFormatById((int)Task.FK_ID_FORMAT_BASE);
            var    formatTypeBase  = new FORMAT_TYPE_Service().findById((int)formatBase.FK_ID_FORMAT_TYPE);

            FORMAT_TYPE formatTypeDestination = new FORMAT_TYPE_Service().findById((int)Task.FORMAT.FK_ID_FORMAT_TYPE);

            // S'il s'agit d'une extraction audio
            if (formatTypeDestination != null && formatTypeBase.PK_ID_FORMAT_TYPE == (int)EnumManager.FORMAT_TYPE.VIDEO && formatTypeDestination.PK_ID_FORMAT_TYPE == (int)EnumManager.FORMAT_TYPE.AUDIO)
            {
                return(ExtractAudioSegment(Task));
            }
            try
            {  // On vérifie si la tache est à reassembler ou pas
                if (Task.STATUS == (int)EnumManager.PARAM_TASK_STATUS.A_REASSEMBLER)
                {
                    // On met le statut en cours
                    Task.STATUS = (int)EnumManager.PARAM_TASK_STATUS.EN_COURS;
                    new TASK_Service().UpdateTask(Task);

                    // On liste les sous taches
                    List <TASK> listOfSubTaskByParent = new TASK_Service().GetSubTaskByMotherTask(Task.PK_ID_TASK);
                    // On va merge les sous taches pour renvoyer la conversion complete
                    bool isMerged = FFmpegMergeSplits(Task, listOfSubTaskByParent);
                    // si le merge s'est bien passé on change le statut de notre Tache.
                    if (isMerged)
                    {
                        Task.DATE_END_CONVERSION = DateTime.Now;
                        Task.STATUS = (int)EnumManager.PARAM_TASK_STATUS.EFFECTUE;
                        // On envoie la notification par mail
                        MailUtil.SendMail(StringManager.CONVERSION_TERMINEE, Task);
                    }
                }
                else
                // Dans le cas ou la tache n'a pas besoin d'etre splitté, on fait le traitement habituel.
                if (!GetTaskAndSetIfTaskIsSplitted(Task, formatToConvert))
                {
                    // On lance la conversion
                    ConvertTask(Task, formatToConvert);

                    // Verification si c'est une sous tache
                    // On vérifie si les sous taches ont été effectuées ou pas.
                    if (Task.FK_ID_PARENT_TASK != null)
                    {
                        List <TASK> listOfSubTaskByParent = new TASK_Service().GetSubTaskByMotherTask((int)Task.FK_ID_PARENT_TASK);
                        int         totalEffectue         = listOfSubTaskByParent.Count(x => x.STATUS == (int)EnumManager.PARAM_TASK_STATUS.EFFECTUE);
                        if (totalEffectue.Equals(listOfSubTaskByParent.Count))
                        {
                            TASK MotherTask = new TASK_Service().GetTaskById((int)Task.FK_ID_PARENT_TASK);
                            MotherTask.STATUS = (int)EnumManager.PARAM_TASK_STATUS.A_REASSEMBLER;
                            new TASK_Service().UpdateTask(MotherTask);
                        }
                    }
                    if (Task.STATUS == (int)EnumManager.PARAM_TASK_STATUS.EFFECTUE && Task.FK_ID_PARENT_TASK == null)
                    {
                        // On envoie la notification par mail
                        MailUtil.SendMail(StringManager.CONVERSION_TERMINEE, Task);
                    }
                }
                new TASK_Service().UpdateTask(Task);
                return(true);
            }
            catch (Exception e)
            {
                Task.DATE_END_CONVERSION = DateTime.Now;
                Task.STATUS = (int)EnumManager.PARAM_TASK_STATUS.ERREUR;
                new TASK_Service().UpdateTask(Task);

                TRACE Trace = new TRACE {
                    FK_ID_TASK = Task.PK_ID_TASK, DATE_TRACE = DateTime.Now, NOM_SERVER = System.Environment.MachineName, FK_ID_SERVER = 1, DESCRIPTION = e.Message + " " + e.InnerException, METHOD = "CONVERSION FFMPEG", TYPE = "ERROR"
                };
                new TRACE_Service().AddTrace(Trace);
                return(false);
            }
        }