Esempio n. 1
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" });
        }
Esempio n. 2
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" });
        }