Exemplo n.º 1
0
        public static async Task <string> generateRSS(ApplicationDbContext context, VideoEntity Entity)
        {
            var str = new StringBuilder();

            str.AppendLine("<rss version=\"2.0\">");
            str.AppendLine("<channel>");
            str.AppendLine("<title>" + Jugnoon.Settings.Configs.GeneralSettings.website_title + "</title>");
            str.AppendLine("<description>" + Jugnoon.Settings.Configs.GeneralSettings.website_description + "</description>");
            str.AppendLine("<link>" + Config.GetUrl() + "</link>");
            str.AppendLine("<guid>" + Config.GetUrl() + "videos/" + "</guid>");
            var _lst = await VideoBLL.LoadItems(context, Entity);

            foreach (var Item in _lst)
            {
                string title_url = VideoUrlConfig.PrepareUrl(Item);
                string body      = WebUtility.HtmlEncode(UtilityBLL.StripHTML_v2(Item.description));
                str.AppendLine("<item>");
                str.AppendLine("<title>" + UtilityBLL.CleanBlogHTML(UtilityBLL.StripHTML(Item.title)) + "</title>");
                str.AppendLine("<link>" + title_url + "</link>");
                str.AppendLine("<guid>" + title_url + "</guid>");
                str.AppendLine("<pubDate>" + String.Format("{0:R}", Item.created_at) + "</pubDate>");
                str.AppendLine("<description>" + body + "</description>");
                str.AppendLine("</item>");
            }
            str.AppendLine("</channel>");
            str.AppendLine("</rss>");

            return(str.ToString());
        }
Exemplo n.º 2
0
        public static async Task <string> generateGoogleSitemap(ApplicationDbContext context, VideoEntity Entity)
        {
            var str = new StringBuilder();

            str.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            str.AppendLine("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"");
            str.AppendLine(" xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\"");
            str.AppendLine(" xmlns:video=\"http://www.google.com/schemas/sitemap-video/1.1\">");
            var _lst = await VideoBLL.LoadItems(context, Entity);

            foreach (var Item in _lst)
            {
                string mediaUrl = "";
                if (Item.type == 1)
                {
                    mediaUrl = VideoUrlConfig.Return_MP3_Audio_Url(Item.pub_url, Item.userid) + "/" + Item.videofilename;
                }
                else
                {
                    mediaUrl = VideoUrlConfig.Return_FLV_Video_Url(Item.pub_url, Item.userid) + "/" + Item.videofilename;
                }


                string thumburl = VideoUrlConfig.Return_Video_Thumb_Url(Item.thumb_url, Item.userid) + "/" + Item.thumbfilename;

                str.AppendLine("<url>");
                str.AppendLine("<loc>" + VideoUrlConfig.PrepareUrl(Item) + "</loc>");
                str.AppendLine("<image:image>");
                str.AppendLine("<image:loc>" + thumburl + "</image:loc>");
                str.AppendLine("<image:caption>" + Item.title + "</image:caption>");
                str.AppendLine("</image:image>");
                str.AppendLine("<video:video>");
                str.AppendLine("<video:content_loc>");
                str.AppendLine(mediaUrl);
                str.AppendLine("</video:content_loc>");

                str.AppendLine("<video:thumbnail_loc>");
                str.AppendLine(thumburl);
                str.AppendLine("</video:thumbnail_loc>");
                str.AppendLine("<video:title>" + Item.title + "</video:title>");

                if (Item.description != "")
                {
                    str.AppendLine("<video:description>");
                    str.AppendLine(Item.description);
                    str.AppendLine("</video:description>");
                }
                str.AppendLine("</video:video>");
                str.AppendLine("</url>");
            }
            str.AppendLine("</urlset>");

            return(str.ToString());
        }
Exemplo n.º 3
0
        public static async Task <string> GenerateBingSitemap(ApplicationDbContext context, VideoEntity Entity)
        {
            var str = new StringBuilder();

            str.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            str.AppendLine("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">");
            var _lst = await VideoBLL.LoadItems(context, Entity);

            foreach (var Item in _lst)
            {
                str.AppendLine("<url>");
                str.AppendLine("<loc>" + VideoUrlConfig.PrepareUrl(Item) + "</loc>");
                str.Append("</url>");
            }
            str.AppendLine("</urlset>");

            return(str.ToString());
        }
Exemplo n.º 4
0
        public static async Task <string> generateATOM(ApplicationDbContext context, VideoEntity Entity, string url)
        {
            var str = new StringBuilder();

            str.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
            str.AppendLine("<feed xmlns=\"http://www.w3.org/2005/Atom\">\n");
            str.AppendLine("<title type=\"text\">" + Jugnoon.Settings.Configs.GeneralSettings.website_title + "</title>\n");
            str.AppendLine("<subtitle type=\"html\">" + Jugnoon.Settings.Configs.GeneralSettings.website_description + "</subtitle>");
            str.AppendLine("<id>tag:" + Config.GetUrl() + "," + DateTime.Now.Year + ":3</id>");
            str.AppendLine("<link rel=\"alternate\" type=\"text/html\" hreflang=\"en\" href=\"" + Config.GetUrl("videos/?type=atom") + "\"/>");
            str.AppendLine("<link rel=\"self\" type=\"application/atom+xml\" href=\"" + url + "\"/>");
            str.AppendLine("<rights>" + Jugnoon.Settings.Configs.GeneralSettings.website_title + "</rights>");
            str.AppendLine("<generator uri=\"" + Config.GetUrl("videos/") + "\" version=\"1.0\">");
            str.AppendLine(Jugnoon.Settings.Configs.GeneralSettings.website_title + " (" + Assembly.GetEntryAssembly().GetName().Version + ")");
            str.AppendLine("</generator>");
            var _lst = await VideoBLL.LoadItems(context, Entity);

            foreach (var Item in _lst)
            {
                string title_url = VideoUrlConfig.PrepareUrl(Item);
                string body      = WebUtility.HtmlEncode(UtilityBLL.StripHTML_v2(Item.description));

                str.AppendLine("<entry>");
                str.AppendLine("<title type=\"text\">" + Item.title + "</title>");
                str.AppendLine("<link rel=\"alternate\" type=\"text/html\" href=\"" + title_url + "\"/>");
                str.AppendLine("<id>tag:" + Config.GetUrl() + "," + Item.created_at.Year + ":3." + Item.id + "</id>\n");
                str.AppendLine("<updated>" + String.Format("{0:R}", Item.created_at) + "</updated>\n");
                str.AppendLine("<published>" + String.Format("{0:R}", Item.created_at) + "</published>\n");
                str.AppendLine("<author>\n");
                str.AppendLine("<name>" + Item.userid + "</name>\n");
                str.AppendLine("<uri>" + Config.GetUrl("videos/") + "</uri>\n");
                str.AppendLine("</author>\n");
                str.AppendLine("<content type=\"html\">" + body + "</content>\n");
                str.AppendLine("</entry>\n");
            }
            str.AppendLine("</feed>");

            return(str.ToString());
        }
Exemplo n.º 5
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" });
        }
Exemplo n.º 6
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" });
        }
Exemplo n.º 7
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" });
        }
        private static string Process_Normal_Video_Thumb(StringBuilder img_str, string username, string mediapath, string thumburl, ListItems attr)
        {
            if (!attr.isresize)
            {
                // no resize needed
                string MediaName = mediapath;
                if (MediaName.Contains("_"))
                {
                    string thumb_start_index         = MediaName.Remove(MediaName.LastIndexOf("_"));
                    string _thumb_url                = VideoUrlConfig.Return_Video_Thumb_Url(thumburl, username);
                    string thumb_start_sequence_path = "";
                    string imagepath = "";
                    if (thumburl == "" || thumburl == "none")
                    {
                        // default thumb fetching
                        thumb_start_sequence_path = _thumb_url + "/" + thumb_start_index + "_";
                        imagepath = _thumb_url + "/" + MediaName;
                    }
                    else
                    {
                        // cloud thumb fetching
                        if (_thumb_url.Contains("_"))
                        {
                            thumb_start_sequence_path = _thumb_url.Remove(_thumb_url.LastIndexOf("_")) + "_";
                        }
                        imagepath = _thumb_url;
                    }

                    img_str.Append(imagepath);
                }
            }
            else
            {
                // resizable thumbs
                string _filename = "";
                int    _iscloud  = 0;
                if (thumburl != "")
                {
                    _iscloud  = 1;
                    _filename = thumburl;
                }
                else
                {
                    // generate filename
                    string _MediaName                = mediapath;
                    string thumb_start_index         = _MediaName.Remove(_MediaName.LastIndexOf("_"));
                    string _thumb_url                = VideoUrlConfig.Return_Video_Thumb_Url(thumburl, username);
                    string thumb_start_sequence_path = "";
                    if (_thumb_url.Contains("_"))
                    {
                        thumb_start_sequence_path = _thumb_url.Remove(_thumb_url.LastIndexOf("_")) + "_";
                    }
                    _filename = _thumb_url;
                }

                string _size = "800x600";
                if (attr.size != "")
                {
                    _size = attr.size;
                }

                img_str.Append(Config.GetUrl("videos/resize?u=" + username + "&file=" + WebUtility.UrlEncode(thumburl) + "&cloud=" + _iscloud + "&size=" + _size));
            }

            return(img_str.ToString());
        }