Example #1
0
        public void PrepareLiveChat(IJobDetail chatDownloadJob, long streamId)
        {
            var        schedulerFactory = new StdSchedulerFactory(QuartzSchedulers.RamScheduler());
            IScheduler scheduler        = schedulerFactory.GetScheduler().Result;

            scheduler.Start();

            ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create()
                                     .WithIdentity("LiveStreamDownloadTrigger" + streamId)
                                     .StartNow()
                                     .Build();

            scheduler.ScheduleJob(chatDownloadJob, trigger);
        }
Example #2
0
        public Task PrepareLiveStreamDownload(StreamExtended stream, string streamerName)
        {
            streamUrl = "https://twitch.tv/" + streamerName;

            YoutubeDlVideoJson.YoutubeDlVideoInfo youtubeDlVideoInfo = StreamHelpers.GetDownloadQualityUrl(streamUrl, stream.streamerId);
            streamDirectory = $"{GlobalConfig.GetGlobalConfig("contentRootPath")}streamers/{stream.streamerId}/vods/{stream.streamId}";

            try {
                Directory.CreateDirectory(streamDirectory);
            } catch (UnauthorizedAccessException e) {
                _logger.Error(e);
                // todo handle this
                throw;
            }

            outputPath = $"{streamDirectory}/{stream.title}.{stream.streamId}";

            dbOutputPath = $"streamers/{stream.streamerId}/vods/{stream.streamId}/{stream.title}.{stream.streamId}.mp4";

            var job = JobBuilder.Create <LiveStreamDownloadJob>()
                      .WithIdentity("LiveStreamDownloadJob" + stream.streamId)
                      .UsingJobData("url", streamUrl)
                      .UsingJobData("streamDirectory", streamDirectory)
                      .UsingJobData("streamId", stream.streamId)
                      .UsingJobData("title", stream.title)
                      .UsingJobData("streamerId", stream.streamerId)
                      .Build();

            var triggerIdentity = $"LiveStreamDownload{stream.streamId}";

            var chatDownloadJob = JobBuilder.Create <LiveStreamChatDownloadJob>()
                                  .WithIdentity("LiveStreamChatDownloadJob" + stream.streamId)
                                  .UsingJobData("channel", streamerName)
                                  .UsingJobData("streamId", stream.streamId)
                                  .Build();

            using (var context = new MainDataContext()) {
                var dbStream = new Stream {
                    streamId          = stream.streamId,
                    vodId             = stream.vodId,
                    streamerId        = stream.streamerId,
                    quality           = youtubeDlVideoInfo.quality,
                    title             = stream.title,
                    url               = youtubeDlVideoInfo.url,
                    createdAt         = stream.createdAt,
                    location          = $"streamers/{stream.streamerId}/vods/{stream.streamId}/",
                    fileName          = $"{stream.title}.{stream.streamId}.mp4",
                    downloading       = true,
                    chatDownloading   = true,
                    downloadJobId     = job.Key.ToString(),
                    chatDownloadJobId = chatDownloadJob.Key.ToString()
                };

                context.Add(dbStream);
                context.SaveChanges();
            }

            var        schedulerFactory = new StdSchedulerFactory(QuartzSchedulers.RamScheduler());
            IScheduler scheduler        = schedulerFactory.GetScheduler().Result;

            scheduler.Start();

            ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create()
                                     .WithIdentity(triggerIdentity)
                                     .StartNow()
                                     .Build();

            scheduler.ScheduleJob(job, trigger);

            PrepareLiveChat(chatDownloadJob, stream.streamId);
            return(Task.CompletedTask);
        }