Example #1
0
        public Task ExecuteAsync(DownloadContext context)
        {
            System.IO.File.Delete(context.VideoOutputFileName);
            System.IO.File.Delete(context.AudioOutputFileName);

            return(Task.CompletedTask);
        }
Example #2
0
        private DownloadContext BuildContext(Dictionary <string, object> context, Dictionary <string, object> contextOverrides)
        {
            var currentContext = new DownloadContext();

            Action <KeyValuePair <string, object> > addItemTtoContext = (KeyValuePair <string, object> item) =>
            {
                if (currentContext.ContainsKey(item.Key))
                {
                    currentContext[item.Key] = item.Value;
                }
                else
                {
                    currentContext.Add(item.Key, item.Value);
                }
            };

            foreach (var item in context)
            {
                addItemTtoContext(item);
            }
            foreach (var item in contextOverrides)
            {
                addItemTtoContext(item);
            }

            return(currentContext);
        }
Example #3
0
        public Task ExecuteAsync(DownloadContext context)
        {
            string[] contextValues = this.Keys.Select(key => (string)context[key]).ToArray();

            context[this.OutputKey] = System.IO.Path.Combine(contextValues);

            return(Task.CompletedTask);
        }
        public Task ExecuteAsync(DownloadContext context)
        {
            VideoDownload(context);

            AudioDownload(context);

            return(Task.CompletedTask);
        }
Example #5
0
        public async Task Run(Dictionary <string, object> contextOverrides = null)
        {
            DownloadContext currentContext = this.BuildContext(this.Context, contextOverrides);

            foreach (IPipelineActivity pipelineActivity in this.Activities)
            {
                await pipelineActivity.ExecuteAsync(currentContext);
            }
        }
        private void VideoDownload(DownloadContext context)
        {
            string defaultDownloadPath = Path.Combine(this.SharedPath, $"{context.Download.Id}.mp4");

            var processStartInfo = new ProcessStartInfo("youtube-dl", $"-o {defaultDownloadPath} {context.Download.OriginalMediaUrl}");

            (string standardOutput, _) = this.Run(processStartInfo);

            context.VideoOutputFilePath = this.ExtractPath(defaultDownloadPath, standardOutput);
        }
        private void AudioDownload(DownloadContext context)
        {
            string defaultDownloadPath = Path.Combine(this.SharedPath, $"{context.Download.Id}.mp3");

            var processStartInfo = new ProcessStartInfo("ffmpeg", $"-i {context.VideoOutputFilePath} {defaultDownloadPath}");

            (string standardOutput, _) = this.Run(processStartInfo);

            context.AudioOutputFilePath = this.ExtractPath(defaultDownloadPath, standardOutput);
        }
Example #8
0
        public async Task ExecuteAsync(DownloadContext context)
        {
            if (context.Download.OriginalMediaUrl == null)
            {
                throw new ArgumentNullException($"The url '{context.Download.OriginalMediaUrl}' is null #invalidUrl");
            }

            this.ValidateUrl(context.Download.OriginalMediaUrl);

            await metadataUpdater.Insert(context.Download);
        }
Example #9
0
        public Task ExecuteAsync(DownloadContext context)
        {
            string defaultDownloadPath = Path.Combine(this.SharedPath, $"{context.Download.Id}.mp4");

            var processStartInfo = new ProcessStartInfo("youtube-dl", $"-o {defaultDownloadPath} {context.Download.OriginalMediaUrl}");

            (string standardOutput, _) = this.Run(processStartInfo);

            context.VideoOutputFilePath = this.ExtractPath(defaultDownloadPath, standardOutput);

            return(Task.CompletedTask);
        }
        public Task ExecuteAsync(DownloadContext context)
        {
            string defaultDownloadPath = Path.Combine(this.SharedPath, $"{context.Download.Id}.mp3");

            var processStartInfo = new ProcessStartInfo("ffmpeg", $"-i {context.VideoOutputFilePath} {defaultDownloadPath}");

            (string standardOutput, _) = this.Run(processStartInfo);

            context.AudioOutputFilePath = this.ExtractPath(defaultDownloadPath, standardOutput);

            return(Task.CompletedTask);
        }
Example #11
0
        public Task ExecuteAsync(DownloadContext context)
        {
            if (context.Download.OriginalMediaUrl == null)
            {
                throw new ArgumentNullException($"The url '{context.Download.OriginalMediaUrl}' is null #invalidUrl");
            }

            this.ValidateUrl(context.Download.OriginalMediaUrl);

            metadataUpdater.InsertOrUpdate(context.Download);

            return(Task.CompletedTask);
        }
Example #12
0
        public async Task ExecuteAsync(DownloadContext context)
        {
            string bucketName = (string)context["defaultBucketName"];

            await minio.PutObjectAsync(bucketName, System.IO.Path.GetFileName(context.OutputFileName), context.OutputFilePath);

            string url = await minio.PresignedGetObjectAsync(bucketName, System.IO.Path.GetFileName(context.OutputFileName), (int)TimeSpan.FromHours(1).TotalSeconds);

            this.metadataUpdater.Update(context.MediaUrl, (download) =>
            {
                download.DownloadUrl = url;
                download.Finished    = DateTime.Now;
            });
        }
Example #13
0
        private static async Task AudioDownload(DownloadContext context)
        {
            var process = System.Diagnostics.Process.Start(new ProcessStartInfo("ffmpeg", $"-i {context.VideoOutputFilePath} {context.AudioOutputFilePath}")
            {
                RedirectStandardOutput = true,
                RedirectStandardError  = true
            });

            process.WaitForExit();
            if (process.ExitCode != 0)
            {
                //Console.WriteLine(await process.StandardError.ReadToEndAsync());
                //Console.WriteLine(await process.StandardOutput.ReadToEndAsync());
                throw new ApplicationException("Download Failure", new Exception(await process.StandardError.ReadToEndAsync() + await process.StandardOutput.ReadToEndAsync()));
            }
        }
Example #14
0
        public async Task ExecuteAsync(DownloadContext context)
        {
            var process = System.Diagnostics.Process.Start(new ProcessStartInfo("youtube-dl", $"-o {context.OutputFilePath} {context.MediaUrl}")
            {
                RedirectStandardOutput = true,
                RedirectStandardError  = true
            });

            process.WaitForExit();
            if (process.ExitCode != 0)
            {
                //Console.WriteLine(await process.StandardError.ReadToEndAsync());
                //Console.WriteLine(await process.StandardOutput.ReadToEndAsync());
                throw new ApplicationException("Download Failure", new Exception(await process.StandardError.ReadToEndAsync() + await process.StandardOutput.ReadToEndAsync()));
            }
        }
Example #15
0
        public async Task ExecuteAsync(DownloadContext context)
        {
            string title = await RunAsync("--get-title", context.MediaUrl);

            string thumbnail = await RunAsync("--get-thumbnail", context.MediaUrl);

            string description = await RunAsync("--get-description", context.MediaUrl);

            TimeSpan duration = TimeSpan.Parse(await RunAsync("--get-duration", context.MediaUrl));

            this.metadataUpdater.Update(context.MediaUrl, (download) =>
            {
                download.Title        = title;
                download.ThumbnailUrl = thumbnail;
                download.Description  = description;
                download.Duration     = duration;
            });
        }
        public async Task ExecuteAsync(DownloadContext context)
        {
            string audioFileName = System.IO.Path.GetFileName(context.AudioOutputFilePath);
            await minio.PutObjectAsync(this.AudioBucketName, audioFileName, context.AudioOutputFilePath);


            string videoFileName = System.IO.Path.GetFileName(context.VideoOutputFilePath);
            await minio.PutObjectAsync(this.VideoBucketName, videoFileName, context.VideoOutputFilePath);


            await this.dataService.Update(context.Download.Id, (update) =>
                                          update.Combine(new[] {
                update.Set(it => it.AudioDownloadUrl, $"/api/media/{this.AudioBucketName}/download/{audioFileName}"),
                update.Set(it => it.VideoDownloadUrl, $"/api/media/{this.VideoBucketName}/download/{videoFileName}"),
                update.Set(it => it.PlayUrl, $"/api/media/{this.VideoBucketName}/stream/{videoFileName}"),
                update.Set(it => it.Finished, DateTime.Now)
            })
                                          );
        }
        public async Task ExecuteAsync(DownloadContext context)
        {
            string title = await RunAsync("--get-title", context.Download.OriginalMediaUrl);

            string thumbnail = await RunAsync("--get-thumbnail", context.Download.OriginalMediaUrl);

            string description = await RunAsync("--get-description", context.Download.OriginalMediaUrl);

            string durationRaw = await RunAsync("--get-duration", context.Download.OriginalMediaUrl);

            TimeSpan duration = this.ParseDuration(durationRaw);

            await this.dataService.Update(context.Download.Id, (update) =>
                                          update.Combine(new[] {
                update.Set(it => it.Title, title),
                update.Set(it => it.ThumbnailUrl, thumbnail),
                update.Set(it => it.Description, description),
                update.Set(it => it.Duration, duration)
            })
                                          );
        }
Example #18
0
 public async Task ExecuteAsync(DownloadContext context)
 {
     await VideoDownload(context);
     await AudioDownload(context);
 }