Пример #1
0
        public ActionResult EditVideo(VIDEO video2, HttpPostedFileBase UserPhoto, HttpPostedFileBase fileupload)
        {
            var whichVideo = ent.VIDEOs.FirstOrDefault(x => x.ID == video2.ID);

            whichVideo.Name = video2.Name;
            ent.SaveChanges();

            whichVideo.UploadDateTime = DateTime.Now;
            ent.SaveChanges();

            if (fileupload != null)
            {
                string fileName = Path.GetFileName(fileupload.FileName);
                int    fileSize = fileupload.ContentLength;
                int    Size     = fileSize / 1000;
                fileupload.SaveAs(Server.MapPath("~/Controllers/VideoFileUpload/" + fileName));

                whichVideo.FileSize = fileSize;
                whichVideo.FilePath = "~/Controllers/VideoFileUpload/" + fileName;



                if (UserPhoto != null)
                {
                    MemoryStream target = new MemoryStream();
                    UserPhoto.InputStream.CopyTo(target);
                    byte[] data = target.ToArray();
                    whichVideo.CoverImage = data;
                }

                ent.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Пример #2
0
        public ActionResult UploadVideo(HttpPostedFileBase fileupload)
        {
            if (fileupload != null)
            {
                string fileName = Path.GetFileName(fileupload.FileName);
                int    fileSize = fileupload.ContentLength;
                int    Size     = fileSize / 1000;
                fileupload.SaveAs(Server.MapPath("~/Controllers/VideoFileUpload/" + fileName));

                VIDEO video = new VIDEO();
                video.Name           = fileName;
                video.FileSize       = fileSize;
                video.FilePath       = "~/Controllers/VideoFileUpload/" + fileName;
                video.UploadDateTime = DateTime.Now;
                ent.VIDEOs.Add(video);
                ent.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Пример #3
0
        public ActionResult RegisterVideo(VIDEO video2, HttpPostedFileBase UserPhoto, HttpPostedFileBase fileupload)
        {
            if (fileupload != null && string.IsNullOrEmpty(video2.Name) && string.IsNullOrEmpty(video2.Email))
            {
                VIDEO video = new VIDEO();
                video.Name  = video2.Name;
                video.Email = video2.Email;

                string fileName = Path.GetFileName(fileupload.FileName);
                int    fileSize = fileupload.ContentLength;
                int    Size     = fileSize / 1000;

                video.FileSize       = fileSize;
                video.FilePath       = "~/Controllers/VideoFileUpload/" + video.ID.ToString() + ".mp4";
                video.UploadDateTime = DateTime.Now;
                video.ViewCount      = 0;
                ent.VIDEOs.Add(video);

                if (UserPhoto != null)
                {
                    MemoryStream target = new MemoryStream();
                    UserPhoto.InputStream.CopyTo(target);
                    byte[] data = target.ToArray();
                    video.CoverImage = data;
                }


                ent.SaveChanges();

                string msg = "Your video are in processing. You will receive an email once the process is done.";
                Response.Write("<script>alert('" + msg + "')</script>");



                fileupload.SaveAs(Server.MapPath("~/Controllers/VideoFileUpload/" + video.ID.ToString() + ".mp4"));

                string subdir = @"C:\Users\chuan\source\repos\SceneChangeDetector\SceneChangeDetector\Controllers\VideoFileUpload\" + video.ID.ToString();
                Directory.CreateDirectory(subdir);

                var filepath = subdir + "/" + video.ID.ToString() + "-Scenes.csv";
                using (StreamWriter writer = new StreamWriter(new FileStream(filepath,
                                                                             FileMode.Create, FileAccess.Write)))
                {
                    writer.WriteLine("");
                }


                string path = @"C:\Program Files\Python36\Scripts\output_dir\" + video.ID.ToString() + ".txt";
                if (!System.IO.File.Exists(path))
                {
                    // Create a file to write to.
                    using (StreamWriter sw = System.IO.File.CreateText(path))
                    {
                        sw.WriteLine("@echo off");
                        sw.WriteLine(@"cd C:\Program Files\Python36\Scripts");
                        sw.WriteLine(@"scenedetect -i C:\Users\chuan\source\repos\SceneChangeDetector\SceneChangeDetector\Controllers\VideoFileUpload\" + video.ID.ToString() + @".mp4 -o C:\Users\chuan\source\repos\SceneChangeDetector\SceneChangeDetector\Controllers\VideoFileUpload\" + video.ID.ToString() + " detect-content -t 27 list-scenes split-video");
                        sw.WriteLine(@"SET GmailAccount =% ~1");
                        sw.WriteLine(@"SET GmailPassword =% ~2");
                        sw.WriteLine(@"SET TargetAccount =% ~3");
                        sw.WriteLine(@"SET PowerShellDir = C:\Windows\System32\WindowsPowerShell\v1.0");
                        sw.WriteLine(@"CD /D "" % PowerShellDir % """);
                        sw.WriteLine(@"Powershell -ExecutionPolicy Bypass -Command "" & 'C:\ChuaN\Degree\Degree Sem4\Multimedia Database\Stage2 & 3\SendEmail.ps1' 'email-address' 'password' " + video.Email + @" 'Dear user, Your video has been processed into seperated scenes. Click on the link to access it. Link:" + " http://7aee1956700c.ngrok.io/Home/ViewVideo/" + video.ID.ToString() + "'");
                        sw.WriteLine(@"pause");
                    }
                }

                // Open the file to read from.
                using (StreamReader sr = System.IO.File.OpenText(path))
                {
                    string s = "";
                    while ((s = sr.ReadLine()) != null)
                    {
                        Console.WriteLine(s);
                    }
                }

                System.IO.File.Move(path, @"C:\Program Files\Python36\Scripts\output_dir\" + video.ID.ToString() + ".bat");

                ProcessStartInfo psi = new ProcessStartInfo();
                psi.FileName = @"C:\Program Files\Python36\Scripts\output_dir\" + video.ID.ToString() + ".bat";
                psi.Verb     = "runas";
                Process.Start(psi);

                return(RedirectToAction("Index", "Home", new { message = "Your video is under processing, an email will be send to you once the process is done." }));
            }
            else
            {
                return(RedirectToAction("RegisterVideo", "Home", new { message = "Please fill in all of the fields." }));
            }
        }