Exemplo n.º 1
0
        public IHttpActionResult PutVideo(int id, VideoLibrary.Video video)
        {
            connString = @"/Files/videos.csv";
            dal        = new DAL.DAL(connString);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != video.id)
            {
                return(BadRequest());
            }

            try
            {
                dal.update(video);
            }
            catch (Exception)
            {
                return(NotFound());
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 2
0
        public IHttpActionResult GetVideo(int id)
        {
            connString = @"/Files/videos.csv";
            dal        = new DAL.DAL(connString);

            VideoLibrary.Video vid = dal.getTheVideo(id);
            if (vid == null)
            {
                return(NotFound());
            }

            return(Ok(vid));
        }
Exemplo n.º 3
0
        public Stream DownloadAndConvert(string source, string target, VideoLibrary.Video video, IVideoDownloader downloader)
        {
            source = $@"Downloads\{source}";
            target = $@"Downloads\{target}";

            VideoConversionJob job = null;

            lock (_lock)
            {
                if (!_downloads.TryGetValue(source, out job))
                {
                    job = new VideoConversionJob(new Task(() =>
                    {
                        downloader.Download(video.Uri, source);

                        var args = string.Format("-y -i {0} -r 20 -s 352x288 -b 400k -acodec aac -strict experimental -ac 1 -ar 8000 -ab 24k {1}", source, target);
                        try
                        {
                            var proc = new Process()
                            {
                                StartInfo = new ProcessStartInfo(YoutubeFeed.VideoConversionPath, args)
                                {
                                    CreateNoWindow         = true,
                                    RedirectStandardOutput = false,
                                    RedirectStandardError  = false,
                                    UseShellExecute        = false,
                                },
                            };

                            proc.Start();
                            proc.WaitForExit();
                        }
                        catch (InvalidOperationException)
                        {
                        }
                        catch (Win32Exception)
                        {
                        }
                    }));
                    _downloads.Add(source, job);
                }
            }

            job.Join();

            return(new StreamReader(target).BaseStream);
        }
Exemplo n.º 4
0
        public IHttpActionResult PostVideo(Object model)
        {
            connString = @"/Files/videos.csv";
            dal        = new DAL.DAL(connString);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            VideoLibrary.Video video = new VideoLibrary.Video();

            var jsonString = model.ToString();

            video = JsonConvert.DeserializeObject <VideoLibrary.Video>(jsonString);

            int newID = dal.add(video);

            return(CreatedAtRoute("DefaultApi", new { id = newID }, video));
        }
 public VideoDownload(VideoLibrary.Video video, string filepath)
 {
     Video = video;
     Filepath = filepath;
 }