Exemple #1
0
        public void CheckForStreamerLiveStatus()
        {
            Notification notification = NotificationLogic.CreateNotification("checkForLiveStreamStatus", Severity.Info, Position.General, "Checking for live streamers...");

            Logger.Info("Checking for live streams to download...");
            List <Streamer> listOfStreamers = new List <Streamer>();

            using (var context = new MainDataContext()) {
                listOfStreamers = context.Streamers.ToList(); //.Where(item => item.getLive).ToList();
            }

            if (listOfStreamers.Count > 100)
            {
                for (int i = 0; i < listOfStreamers.Count; i = i + 100)
                {
                    UpdateLiveStatus(listOfStreamers.Skip(i).Take(100).ToList());
                }
            }
            else
            {
                UpdateLiveStatus(listOfStreamers);
            }

            Logger.Info("Done!");
            NotificationLogic.DeleteNotification("checkForLiveStreamStatus");
        }
Exemple #2
0
        public void CheckForUpdates()
        {
            Notification notification = NotificationLogic.CreateNotification("softwareUpdate", Severity.Info, Position.General, "Checking for software updates...");

            Logger.Info("Checking for application updates...");
            new UpdateLogic().CheckForApplicationUpdates();
            Logger.Info("Checking for yt-dlp updates...");
            new UpdateYtDlp().CheckForYtDlpUpdates();
            NotificationLogic.DeleteNotification("softwareUpdate");
        }
        public Task DownloadStream(StreamExtended stream, string title, string streamDirectory, string formatId,
                                   string url, long duration, CancellationToken cancellationToken)
        {
            StreamDownload streamDownload = new StreamDownload(new DirectoryInfo(streamDirectory), false);

            _logger.Info("Getting vod m3u8..");
            streamDownload.GetVodM3U8(url);
            _logger.Info("Got vod m3u8.");

            try {
                _logger.Info("Getting vod parts...");
                streamDownload.GetVodParts(cancellationToken);
                _logger.Info("Got vod parts.");
            } catch (TsFileNotFound e) {
                // test if the stream has gone down.
                try {
                    streamDownload.GetVodM3U8(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 == stream.streamerId);
                        }

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

                        streamDownload.CleanUpFiles();
                        throw;
                    }
                }
            }

            _logger.Info("Combining ts files...");
            streamDownload.CombineTsFiles(title, stream.streamId);
            _logger.Info("Combined ts files.");
            _logger.Info("Cleaning up files...");
            streamDownload.CleanUpFiles();
            _logger.Info("Cleaned up files.");

            File.Move($"{streamDownload._rootDirectory.FullName}/stream.mp4", $"{streamDownload._rootDirectory.FullName}/{title}.{stream.streamId}.mp4");

            _logger.Info("Moved file.");
            StreamHelpers.SetDownloadToFinished(stream.streamId, false);
            return(Task.CompletedTask);
            //await _hubContext.Clients.All.SendAsync("ReceiveMessage", CheckForDownloadingStreams());
        }
Exemple #4
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 #5
0
        public Task CheckForYtDlpUpdates()
        {
            Version?currentVersion = null;
            string? dbVersion      = GlobalConfig.GetGlobalConfig("yt-dlpVersion");

            if (dbVersion == null)
            {
                // current yt-dlp (if it exists) does not have the version number in the db.
                string?ytDlpInstallLocation = GlobalConfig.GetGlobalConfig("yt-dlp");

                if (ytDlpInstallLocation != null)
                {
                    // yt-dlp is installed, need to get the current version.
                    try {
                        currentVersion = GetCurrentYtDlpVersion(ytDlpInstallLocation);
                    } catch (Exception e) {
                        // ignored, probably an error due to yt-dlp not existing.
                    }

                    if (currentVersion is not null)
                    {
                        GlobalConfig.SetGlobalConfig("yt-dlpVersion", currentVersion.ToString());
                    }
                }
            }
            else
            {
                currentVersion = Version.Parse(dbVersion);
            }

            Version latestVersion = GetLatestYtDlpVersion();

            if (currentVersion != null && currentVersion >= latestVersion)
            {
                return(Task.CompletedTask);
            }

            NotificationLogic.CreateNotification("yt-dlpUpdate", Severity.Info, Position.Top, $"New yt-dlp update! Current version: {(currentVersion != null ? currentVersion : "unknown")}; latest: {latestVersion}.", "/settings/setup");
            GlobalConfig.SetGlobalConfig("yt-dlpUpdate", true.ToString());
            return(Task.CompletedTask);
        }
Exemple #6
0
        public void DatabaseBackup(string database)
        {
            Logger.Info($"Backing up {database} database...");
            Notification notification = NotificationLogic.CreateNotification("databaseBackup", Severity.Info, Position.General, "Backing up database...");
            int          backupCount;

            using (var context = new MainDataContext()) {
                backupCount = context.Backups.Count(item => item.type == database);
            }

            if (backupCount > 5)
            {
                // trim database backups
                using (var context = new MainDataContext()) {
                    Backup oldestBackup = context.Backups.Where(item => item.type == database)
                                          .OrderBy(item => item.datetime).First();
                    FileInfo backupFile = new FileInfo(oldestBackup.location);
                    if (backupFile.Exists)
                    {
                        backupFile.Delete();
                    }

                    context.Remove(oldestBackup);
                    context.SaveChanges();
                }
            }

            DatabaseBackupLogic databaseBackupLogic = new DatabaseBackupLogic();

            if (database == "chatDb")
            {
                databaseBackupLogic.BackupChatDatabase();
            }
            else
            {
                databaseBackupLogic.BackupDatabase("mainDb");
            }

            Logger.Info($"Backed up {database} database.");
            NotificationLogic.DeleteNotification("databaseBackup");
        }
Exemple #7
0
        public void StreamerCheckForUpdates()
        {
            Notification    notification    = NotificationLogic.CreateNotification("streamerCheckForUpdates", Severity.Info, Position.General, "Checking for streamer updates...");
            List <Streamer> listOfStreamers = new List <Streamer>();

            using (var context = new MainDataContext()) {
                listOfStreamers = context.Streamers.ToList();
            }

            if (listOfStreamers.Count > 100)
            {
                for (int i = 0; i < listOfStreamers.Count; i = i + 100)
                {
                    UpdateStreamerDetails(listOfStreamers.Skip(i).Take(100).ToList());
                }
            }
            else
            {
                UpdateStreamerDetails(listOfStreamers);
            }

            NotificationLogic.DeleteNotification("streamerCheckForUpdates");
        }