Exemple #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new MainForm());
            System.Net.ServicePointManager.DefaultConnectionLimit = 100;
            var request = new DownloadRequest(new Uri("http://ipv4.download.thinkbroadband.com/10MB.zip"));

            File.Delete("D:\\Downloads\\TEST\\10MB.zip.tmp");
            var stream           = File.OpenWrite("D:\\Downloads\\TEST\\10MB.zip.tmp");
            var partitionManager = new StreamPartition(stream);
            var streamDownload   = new StreamDownload(request, partitionManager);
            var form             = new DownloadForm(streamDownload);

            Application.Run(form);
        }
Exemple #2
0
        public Task Execute(IJobExecutionContext context)
        {
            JobDataMap     jobDataMap     = context.JobDetail.JobDataMap;
            StreamDownload streamDownload = new StreamDownload(new DirectoryInfo(jobDataMap.GetString("streamDirectory")), true);

            streamDownload.GetVodM3U8(jobDataMap.GetString("url"));

            try {
                streamDownload.GetVodParts(context.CancellationToken);
            } catch (TsFileNotFound e) {
                // test if the stream has gone down.
                try {
                    streamDownload.GetVodM3U8(jobDataMap.GetString("url"));
                } catch (Exception exception) {
                    if (!exception.Message.Contains("is offline"))
                    {
                        // stream is offline, must have finished, so is not an error.
                        // stream has not finished, throw
                        _logger.Error($"Error occured while downloading a live stream. {exception.Message}");
                        Streamer streamer;
                        using (var mainDataContext = new MainDataContext()) {
                            streamer = mainDataContext.Streamers.FirstOrDefault(item => item.streamerId == jobDataMap.GetIntValue("streamerId"));
                        }

                        if (streamer != null)
                        {
                            NotificationLogic.CreateNotification($"LiveStreamDownloadJob{jobDataMap.GetLongValue("streamId")}", Severity.Error, Position.Top, $"Could not download VOD for {streamer.username}.", $"/streamer/{streamer.id}");
                        }

                        streamDownload.CleanUpFiles();
                        throw;
                    }
                }
            }

            streamDownload.CombineTsFiles(jobDataMap.GetString("title"), jobDataMap.GetLongValue("streamId"));
            streamDownload.CleanUpFiles();
            // need to rename file as ffmpeg does not work with special characters.
            File.Move($"{streamDownload._rootDirectory.FullName}/stream.mp4", $"{streamDownload._rootDirectory.FullName}/{jobDataMap.GetString("title")}.{jobDataMap.GetLongValue("streamId")}.mp4");
            StreamHelpers.SetDownloadToFinished(jobDataMap.GetLongValue("streamId"), true);


            return(Task.CompletedTask);
        }
Exemple #3
0
 public DownloadForm(StreamDownload download) : this()
 {
     Download = download;
     Download.ProgressChanged += DownloadOnProgressChanged;
 }