Ejemplo n.º 1
0
        public static async Task <object> ffmpeg_proc(ApplicationDbContext context, List <SaveVideoInfo> data)
        {
            foreach (var _rec in data)
            {
                var _ref_filename  = "";
                var _SelectedIndex = "";
                foreach (var thumb in _rec.video_thumbs)
                {
                    if (thumb.selected)
                    {
                        if (Jugnoon.Settings.Configs.AwsSettings.enable)
                        {
                            _rec.thumbfilename = Path.GetFileName(thumb.filename).Remove(Path.GetFileName(thumb.filename).LastIndexOf("_")) + "/img" + thumb.filename.Remove(0, thumb.filename.LastIndexOf("_"));
                            // _rec.thumbfilename = Path.GetFileNameWithoutExtension(thumb.filename) + "/img_" + thumb.filename.Remove(0, thumb.filename.LastIndexOf("_"));
                        }
                        else
                        {
                            _rec.thumbfilename = Path.GetFileName(thumb.filename);
                        }
                        _ref_filename = Path.GetFileName(thumb.filename);

                        _SelectedIndex = thumb.fileIndex;
                        _rec.thumb_url = thumb.filename;
                    }
                }
                var _thumbFile = "";
                var PubPrefix  = Guid.NewGuid().ToString().Substring(0, 12) + "-"; // avoid duplication in cloud
                try
                {
                    if (Jugnoon.Settings.Configs.AwsSettings.enable)
                    {
                        if (Configs.AwsSettings.bucket != "")
                        {
                            var SourcePath      = VideoUrlConfig.Source_Video_Path(_rec.userid);
                            var publishedPath   = VideoUrlConfig.Published_Video_Path(_rec.userid);
                            var thumbsPath      = VideoUrlConfig.Thumbs_Path(_rec.userid);
                            var previewVideoUrl = ""; // not yet added in this version
                            var _arr            = new ArrayList();
                            _arr.Add(_rec.pf);
                            var _thumbFileName = _ref_filename;
                            if (_thumbFileName.Contains("_"))
                            {
                                _thumbFileName = _thumbFileName.Remove(_thumbFileName.LastIndexOf("_"));
                            }
                            else
                            {
                                _thumbFileName = _thumbFileName.Replace(".jpg", "");
                            }

                            // add key to avoid duplication
                            thumbsPath = thumbsPath + "\\" + _thumbFileName + "_";

                            _thumbFileName = PubPrefix + "-" + _thumbFileName;
                            var ext = Path.GetExtension(_ref_filename);
                            _thumbFile = _thumbFileName + "/" + _SelectedIndex + ext; // "img_008" + ext;
                            string status = MediaCloudStorage.UploadMediaFiles(SourcePath, _rec.sf, publishedPath, _arr, PubPrefix, thumbsPath, _thumbFileName, 15, previewVideoUrl, _rec.userid, Path.GetExtension(ext));
                            if (status == "PubFailed" || status == "ThumbFailed")
                            {
                                ErrorLgBLL.Add(context, "Error Uploading to Cloud", "", "Error Code 1009, message: storing content to cloud failed");
                            }
                        }
                        else
                        {
                            ErrorLgBLL.Add(context, "Error Uploading to Cloud", "", "Cloud Storage Enabled But No Cloud Storage Settings Available");
                        }
                    }
                }
                catch (Exception ex)
                {
                    var err = ex.Message;
                }

                var cloud_url = Url.prepareUrl(_rec.userid);

                // update entity values
                _rec.videofilename         = _rec.pf;
                _rec.thumbfilename         = Path.GetFileName(_rec.tfile);
                _rec.originalvideofilename = _rec.sf;
                _rec.pub_url      = cloud_url.publish_filename + PubPrefix + _rec.pf;
                _rec.thumb_url    = cloud_url.thumb_filename + _thumbFile;
                _rec.org_url      = cloud_url.publish_filename + _rec.sf;
                _rec.preview_url  = "";
                _rec.isexternal   = 0;
                _rec.youtubeid    = "";
                _rec.ispublished  = 1;
                _rec.embed_script = "";

                await VideoBLL.AddVideo(context, _rec);
            }
            return(new { status = "success", message = "Record processed successfully" });
        }
Ejemplo n.º 2
0
        public static async Task <object> direct_proc(ApplicationDbContext context, List <SaveVideoInfo> data)
        {
            foreach (var _rec in data)
            {
                var _counter = 1;
                foreach (var thumb in _rec.video_thumbs)
                {
                    var _prefix = "00";
                    if (_counter <= 9)
                    {
                        _prefix = "00";
                    }
                    else if (_counter <= 99)
                    {
                        _prefix = "0";
                    }
                    else
                    {
                        _prefix = "";
                    }

                    /* save base64 image in physical path */
                    byte[] image         = Convert.FromBase64String(thumb.filename.Replace("data:image/png;base64,", ""));
                    string thumbFileName = _rec.videofilename.Remove(_rec.videofilename.LastIndexOf(".")) + "_" + _prefix + "" + _counter + ".png";
                    _counter++;
                    string path = VideoUrlConfig.Thumbs_Path(_rec.userid) + "/" + thumbFileName;
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    File.WriteAllBytes(path, image);

                    if (thumb.selected)
                    {
                        _rec.thumbfilename = thumbFileName;
                    }

                    _rec.tfile = _rec.thumbfilename;
                }
                var PubPrefix = Guid.NewGuid().ToString().Substring(0, 12) + "-"; // avoid duplication in cloud
                try
                {
                    // in case of direct uploader, there is no published video, source video is published.
                    // shift source video to published directory
                    var SourcePath    = VideoUrlConfig.Source_Video_Path(_rec.userid); // no source video there
                    var publishedPath = VideoUrlConfig.Published_Video_Path(_rec.userid);
                    var thumbsPath    = VideoUrlConfig.Thumbs_Path(_rec.userid);
                    if (File.Exists(publishedPath + "/" + _rec.videofilename))
                    {
                        File.Delete(publishedPath + "/" + _rec.videofilename);
                    }

                    File.Move(SourcePath + "/" + _rec.videofilename, publishedPath + "/" + _rec.videofilename);
                    if (Jugnoon.Settings.Configs.AwsSettings.enable)
                    {
                        if (Configs.AwsSettings.bucket != "")
                        {
                            //var previewVideoUrl = ""; // not yet added in this version
                            var _arr = new ArrayList();
                            _arr.Add(_rec.videofilename);

                            if (_rec.thumbfilename != null)
                            {
                                var _thumbFileName = _rec.thumbfilename;
                                if (_thumbFileName.Contains("_"))
                                {
                                    _thumbFileName = _thumbFileName.Remove(_thumbFileName.LastIndexOf("_"));
                                }
                                else
                                {
                                    _thumbFileName = _thumbFileName.Replace(".jpg", "");
                                }
                            }
                            // string status = MediaCloudStorage.UploadMediaFiles("", "", publishedPath, _arr, PubPrefix, thumbsPath, _thumbFileName, _rec.thumbs.Count(), "", _rec.userid, ".png");
                            // thumb is not provided, just sent via thumb_url in this version
                            string status = MediaCloudStorage.UploadMediaFiles("", "", publishedPath, _arr, PubPrefix, "", "", 0, "", _rec.userid, ".png");
                            if (status == "PubFailed" || status == "ThumbFailed")
                            {
                                ErrorLgBLL.Add(context, "Error Uploading to Cloud", "", "Error Code 1009, message: storing content to cloud failed");
                            }
                        }
                        else
                        {
                            ErrorLgBLL.Add(context, "Error Uploading to Cloud", "", "Cloud Storage Enabled But No Cloud Storage Settings Available");
                        }
                    }
                }
                catch (Exception ex)
                {
                    var err = ex.Message;
                }

                var cloud_url = Url.prepareUrl(_rec.userid);

                // update entity values
                _rec.videofilename         = _rec.videofilename;
                _rec.thumbfilename         = _rec.tfile;
                _rec.originalvideofilename = _rec.sf;
                _rec.pub_url      = cloud_url.publish_filename + PubPrefix + _rec.videofilename;
                _rec.thumb_url    = _rec.thumb_url; // cloud_url.thumb_filename + _rec.thumbfilename;
                _rec.org_url      = "";
                _rec.isexternal   = 0;
                _rec.youtubeid    = "";
                _rec.ispublished  = 1;
                _rec.embed_script = "";

                await VideoBLL.AddVideo(context, _rec);
            }
            return(new { status = "success", message = "Record processed successfully" });
        }
Ejemplo n.º 3
0
        public static async Task <object> aws_proc(ApplicationDbContext context, List <SaveVideoInfo> data)
        {
            if (Jugnoon.Settings.Configs.AwsSettings.enable)
            {
                if (Configs.AwsSettings.bucket != "")
                {
                    try
                    {
                        foreach (var _rec in data)
                        {
                            _rec.isenabled = 1; // by default enabled
                            if (Jugnoon.Settings.Configs.GeneralSettings.content_approval == 1)
                            {
                                _rec.isapproved = 1;
                            }
                            else
                            {
                                _rec.isapproved = 0;
                            }

                            var SourcePath = VideoUrlConfig.Source_Video_Path(_rec.userid); // no source video there
                            if (File.Exists(SourcePath + "/" + _rec.sf))
                            {
                                string source_key_prefix = Jugnoon.Videos.Configs.AwsSettings.elastic_transcoder_directory + "" + Guid.NewGuid().ToString().Substring(0, 10);
                                _rec.originalvideofilename = source_key_prefix + "-" + UtilityBLL.ReplaceSpaceWithHyphin_v2(_rec.sf);
                                // Save unpublished video data in database first before uploading file to aws

                                // update entity values
                                _rec.videofilename = "";
                                _rec.thumbfilename = "";
                                _rec.pub_url       = "";
                                _rec.thumb_url     = "";
                                _rec.org_url       = "";
                                _rec.isexternal    = 0;
                                _rec.youtubeid     = "";
                                _rec.ispublished   = 0;
                                _rec.embed_script  = "";

                                await VideoBLL.AddVideo(context, _rec);

                                string status = MediaCloudStorage.UploadMediaFiles_Elastic(SourcePath, _rec.sf, _rec.originalvideofilename, _rec.userid);
                                if (status == "OrgFailed")
                                {
                                    ErrorLgBLL.Add(context, "Error Uploading to Cloud", "", "Error Code 1009, message: storing content to cloud failed");
                                }
                            }
                            else
                            {
                                ErrorLgBLL.Add(context, "Cloud Upload Error", "", "File Not Exist " + SourcePath + "/" + _rec.sf);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorLgBLL.Add(context, "Upload Video Error", "", ex.Message);
                    }
                }
            }

            return(new { status = "success", message = "Record processed successfully" });
        }