diff --git a/Jellyfin.Plugin.Newsletters/Configuration/PluginConfiguration.cs b/Jellyfin.Plugin.Newsletters/Configuration/PluginConfiguration.cs index a5cc211..5934748 100644 --- a/Jellyfin.Plugin.Newsletters/Configuration/PluginConfiguration.cs +++ b/Jellyfin.Plugin.Newsletters/Configuration/PluginConfiguration.cs @@ -94,10 +94,6 @@ public PluginConfiguration() // default newsletter paths NewsletterFileName = string.Empty; - MyDataDir = string.Empty; - CurrRunListFileName = "Currlist.txt"; - ArchiveFileName = "Archive.txt"; - NewsletterDataFileName = "NewsletterList.txt"; NewsletterDir = string.Empty; // default libraries @@ -232,31 +228,11 @@ public PluginConfiguration() /// public string NewsletterFileName { get; set; } - /// - /// Gets or sets a string setting. - /// - public string MyDataDir { get; set; } - - /// - /// Gets a string setting. - /// - public string CurrRunListFileName { get; } - - /// - /// Gets a string setting. - /// - public string ArchiveFileName { get; } - /// /// Gets or sets a string setting. /// public string NewsletterDir { get; set; } - /// - /// Gets or sets a string setting. - /// - public string NewsletterDataFileName { get; set; } - /// /// Gets or sets a value indicating whether Series should be scanned. /// diff --git a/Jellyfin.Plugin.Newsletters/Configuration/configPage.html b/Jellyfin.Plugin.Newsletters/Configuration/configPage.html index b82e926..e273f52 100644 --- a/Jellyfin.Plugin.Newsletters/Configuration/configPage.html +++ b/Jellyfin.Plugin.Newsletters/Configuration/configPage.html @@ -195,7 +195,7 @@ } function saveConfig() { - console.log("test"); + //console.log("test"); ApiClient.getPluginConfiguration(NewsletterConfig.pluginUniqueId).then(function (config) { config.DebugMode = document.querySelector('#DebugMode').checked; //serverDetails diff --git a/Jellyfin.Plugin.Newsletters/Emails/HTMLBuilder.cs b/Jellyfin.Plugin.Newsletters/Emails/HTMLBuilder.cs index df9ce58..33b08cb 100644 --- a/Jellyfin.Plugin.Newsletters/Emails/HTMLBuilder.cs +++ b/Jellyfin.Plugin.Newsletters/Emails/HTMLBuilder.cs @@ -33,7 +33,7 @@ public class HtmlBuilder private readonly PluginConfiguration config; private readonly string newslettersDir; private readonly string newsletterHTMLFile; - private readonly string newsletterDataFile; + // private readonly string newsletterDataFile; private string emailBody; private Logger logger; @@ -51,7 +51,6 @@ public HtmlBuilder() jsonHelper = new JsonFileObj(); db = new SQLiteDatabase(); config = Plugin.Instance!.Configuration; - newsletterDataFile = config.MyDataDir + config.NewsletterDataFileName; emailBody = config.Body; newslettersDir = config.NewsletterDir; // newsletterdir @@ -74,7 +73,6 @@ public HtmlBuilder() public string GetDefaultHTMLBody() { - // emailBody = "
REPLACEME

Jellyfin Newsletter

" + DateTime.Today.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) + "

"; emailBody = config.Body; return emailBody; } @@ -392,14 +390,10 @@ public void CleanUp(string htmlBody) // append newsletter cycle data to Archive.txt CopyNewsletterDataToArchive(); - - // remove newsletter cycle data - File.Delete(newsletterDataFile); } private void CopyNewsletterDataToArchive() { - string archiveFile = config.MyDataDir + config.ArchiveFileName; logger.Info("Appending NewsletterData for Current Newsletter Cycle to Archive Database.."); // copy tables diff --git a/Jellyfin.Plugin.Newsletters/Emails/smtp.cs b/Jellyfin.Plugin.Newsletters/Emails/smtp.cs index 341bc5c..7953306 100644 --- a/Jellyfin.Plugin.Newsletters/Emails/smtp.cs +++ b/Jellyfin.Plugin.Newsletters/Emails/smtp.cs @@ -1,21 +1,14 @@ #pragma warning disable 1591 using System; using System.Globalization; -using System.IO; using System.Net; using System.Net.Mail; -using System.Threading; -using System.Threading.Tasks; using Jellyfin.Plugin.Newsletters.Configuration; using Jellyfin.Plugin.Newsletters.Emails.HTMLBuilder; using Jellyfin.Plugin.Newsletters.LOGGER; using Jellyfin.Plugin.Newsletters.Shared.DATA; -using MediaBrowser.Common.Configuration; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.Library; -using MediaBrowser.Model.Globalization; -using MediaBrowser.Model.Tasks; -using Microsoft.AspNetCore.Http; +using MediaBrowser.Common.Api; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; // using System.Net.NetworkCredential; @@ -26,12 +19,13 @@ namespace Jellyfin.Plugin.Newsletters.Emails.EMAIL; /// Interaction logic for SendMail.xaml. /// // [Route("newsletters/[controller]")] +[Authorize(Policy = Policies.RequiresElevation)] [ApiController] [Route("Smtp")] public class Smtp : ControllerBase { private readonly PluginConfiguration config; - private readonly string newsletterDataFile; + // private readonly string newsletterDataFile; private SQLiteDatabase db; private Logger logger; @@ -40,7 +34,6 @@ public Smtp() db = new SQLiteDatabase(); logger = new Logger(); config = Plugin.Instance!.Configuration; - newsletterDataFile = config.MyDataDir + config.NewsletterDataFileName; } [HttpPost("SendTestMail")] @@ -142,7 +135,7 @@ public void SendEmail() } } - public bool NewsletterDbIsPopulated() + private bool NewsletterDbIsPopulated() { foreach (var row in db.Query("SELECT COUNT(*) FROM CurrNewsletterData;")) { diff --git a/Jellyfin.Plugin.Newsletters/Jellyfin.Plugin.Newsletters.csproj b/Jellyfin.Plugin.Newsletters/Jellyfin.Plugin.Newsletters.csproj index e58e07d..d102937 100644 --- a/Jellyfin.Plugin.Newsletters/Jellyfin.Plugin.Newsletters.csproj +++ b/Jellyfin.Plugin.Newsletters/Jellyfin.Plugin.Newsletters.csproj @@ -4,7 +4,7 @@ net8.0 Jellyfin.Plugin.Newsletters true - true + false enable AllEnabledByDefault ../jellyfin.ruleset diff --git a/Jellyfin.Plugin.Newsletters/Plugin.cs b/Jellyfin.Plugin.Newsletters/Plugin.cs index 265eed6..7340feb 100644 --- a/Jellyfin.Plugin.Newsletters/Plugin.cs +++ b/Jellyfin.Plugin.Newsletters/Plugin.cs @@ -43,8 +43,7 @@ void SetConfigPaths(IApplicationPaths dataPaths) config.LogDirectoryPath = dataPaths.LogDirectoryPath; // Custom Paths - config.MyDataDir = $"{config.TempDirectory}/Newsletters/"; - config.NewsletterDir = $"{config.MyDataDir}myNewsletters/"; + config.NewsletterDir = $"{config.TempDirectory}/Newsletters/"; } SetConfigPaths(applicationPaths); diff --git a/Jellyfin.Plugin.Newsletters/Scanner/NewsletterDataGenerator.cs b/Jellyfin.Plugin.Newsletters/Scanner/NewsletterDataGenerator.cs index 67f7464..f316dc2 100644 --- a/Jellyfin.Plugin.Newsletters/Scanner/NewsletterDataGenerator.cs +++ b/Jellyfin.Plugin.Newsletters/Scanner/NewsletterDataGenerator.cs @@ -32,12 +32,6 @@ public class NewsletterDataGenerator // Global Vars // Readonly private readonly PluginConfiguration config; - private readonly string newslettersDir; - private readonly string newsletterDataFile; - - private readonly string currRunList; - private readonly string archiveFile; - private readonly string myDataDir; private Logger logger; private SQLiteDatabase db; @@ -50,56 +44,8 @@ public NewsletterDataGenerator() logger = new Logger(); db = new SQLiteDatabase(); config = Plugin.Instance!.Configuration; - myDataDir = config.TempDirectory + "/Newsletters"; - - archiveFile = config.MyDataDir + config.ArchiveFileName; // curlist/archive - currRunList = config.MyDataDir + config.CurrRunListFileName; - newsletterDataFile = config.MyDataDir + config.NewsletterDataFileName; archiveSeriesList = new List(); - newslettersDir = config.NewsletterDir; // newsletterdir - Directory.CreateDirectory(newslettersDir); - } - - public Task GenerateDataForNextNewsletter() - { - try - { - db.CreateConnection(); - archiveSeriesList = PopulateFromArchive(db); // Files that shouldn't be processed again - CopyCurrRunDataToNewsletterData(); - } - catch (Exception e) - { - logger.Error("An error has occured: " + e); - } - finally - { - db.CloseConnection(); - } - - return Task.CompletedTask; - } - - public List PopulateFromArchive(SQLiteDatabase database) - { - List myObj = new List(); - JsonFileObj helper, currArcObj; - - foreach (var row in database.Query("SELECT * FROM ArchiveData;")) - { - logger.Debug("Inside of foreach.."); - if (row is not null) - { - helper = new JsonFileObj(); - currArcObj = helper.ConvertToObj(row); - myObj.Add(currArcObj); - } - } - - logger.Debug("Returning ArchObj"); - - return myObj; } public string FetchImagePoster(JsonFileObj item) @@ -161,15 +107,4 @@ private string UploadToImgur(string posterFilePath) } } } - - private void CopyCurrRunDataToNewsletterData() - { - if (File.Exists(currRunList)) // archiveFile - { - Stream input = File.OpenRead(currRunList); - Stream output = new FileStream(newsletterDataFile, FileMode.Append, FileAccess.Write, FileShare.None); - input.CopyTo(output); - File.Delete(currRunList); - } - } } \ No newline at end of file diff --git a/Jellyfin.Plugin.Newsletters/Scanner/Scraper.cs b/Jellyfin.Plugin.Newsletters/Scanner/Scraper.cs index 43278f2..8a11378 100644 --- a/Jellyfin.Plugin.Newsletters/Scanner/Scraper.cs +++ b/Jellyfin.Plugin.Newsletters/Scanner/Scraper.cs @@ -32,9 +32,9 @@ public class Scraper // Global Vars // Readonly private readonly PluginConfiguration config; - private readonly string currRunScanList; - private readonly string archiveFile; - private readonly string currNewsletterDataFile; + // private readonly string currRunScanList; + // private readonly string archiveFile; + // private readonly string currNewsletterDataFile; private readonly ILibraryManager libManager; // Non-readonly @@ -58,25 +58,19 @@ public Scraper(ILibraryManager libraryManager, IProgress passedProgress, libManager = libraryManager; totalLibCount = currCount = 0; - // currRunScanListDir = config.TempDirectory + "/Newsletters/"; - archiveFile = config.MyDataDir + config.ArchiveFileName; - currRunScanList = config.MyDataDir + config.CurrRunListFileName; - currNewsletterDataFile = config.MyDataDir + config.NewsletterDataFileName; - Directory.CreateDirectory(config.MyDataDir); ng = new NewsletterDataGenerator(); db = new SQLiteDatabase(); logger.Debug("Setting Config Paths: "); logger.Debug("\n DataPath: " + config.DataPath + - "\n TempDirectory: " + config.TempDirectory + - "\n PluginsPath: " + config.PluginsPath + - "\n MyDataDir: " + config.MyDataDir + - "\n NewsletterDir: " + config.NewsletterDir + - "\n ProgramDataPath: " + config.ProgramDataPath + - "\n ProgramSystemPath: " + config.ProgramSystemPath + - "\n SystemConfigurationFilePath: " + config.SystemConfigurationFilePath + - "\n LogDirectoryPath: " + config.LogDirectoryPath ); + "\n TempDirectory: " + config.TempDirectory + + "\n PluginsPath: " + config.PluginsPath + + "\n NewsletterDir: " + config.NewsletterDir + + "\n ProgramDataPath: " + config.ProgramDataPath + + "\n ProgramSystemPath: " + config.ProgramSystemPath + + "\n SystemConfigurationFilePath: " + config.SystemConfigurationFilePath + + "\n LogDirectoryPath: " + config.LogDirectoryPath ); } // This is the main function @@ -86,7 +80,6 @@ public Task GetSeriesData() try { db.CreateConnection(); - // archiveObj = ng.PopulateFromArchive(db); BuildJsonObjsToCurrScanfile(); CopyCurrRunDataToNewsletterData(); } @@ -134,8 +127,6 @@ public void BuildObjs(List items, string type) foreach (BaseItem item in items) { currCount++; - // logger.Info("PROGRESS: " + currCount + " " + totalLibCount); - // double percentage = (double)currCount / (double)totalLibCount * 100; progress.Report((double)currCount / (double)totalLibCount * 100); if (item is not null) { @@ -184,7 +175,9 @@ public void BuildObjs(List items, string type) currFileObj.Filename = episode.PhysicalLocations[0]; currFileObj.Title = series.Name; currFileObj.Type = type; - if (!InDatabase("CurrRunData", currFileObj.Filename.Replace("'", string.Empty, StringComparison.Ordinal)) && !InDatabase("CurrNewsletterData", currFileObj.Filename.Replace("'", string.Empty, StringComparison.Ordinal)) && !InDatabase("ArchiveData", currFileObj.Filename.Replace("'", string.Empty, StringComparison.Ordinal))) + if (!InDatabase("CurrRunData", currFileObj.Filename.Replace("'", string.Empty, StringComparison.Ordinal)) && + !InDatabase("CurrNewsletterData", currFileObj.Filename.Replace("'", string.Empty, StringComparison.Ordinal)) && + !InDatabase("ArchiveData", currFileObj.Filename.Replace("'", string.Empty, StringComparison.Ordinal))) { try { @@ -251,7 +244,6 @@ public void BuildObjs(List items, string type) finally { // save to "database" : Table currRunScanList - // WriteFile(append, currRunScanList, JsonConvert.SerializeObject(currFileObj) + ";;;"); logger.Debug("Adding to CurrRunData DB..."); currFileObj = NoNull(currFileObj); db.ExecuteSQL("INSERT INTO CurrRunData (Filename, Title, Season, Episode, SeriesOverview, ImageURL, ItemID, PosterPath, Type) " + @@ -274,8 +266,6 @@ public void BuildObjs(List items, string type) logger.Debug("\"" + currFileObj.Filename + "\" has already been processed either by Previous or Current Newsletter!"); } } - - // currCount++; } } @@ -378,7 +368,6 @@ private string SetImageURL(JsonFileObj currObj) } } - // string url = ng.FetchImagePoster(obj.Title); logger.Debug("Uploading poster..."); logger.Debug(currObj.ItemID); logger.Debug(currObj.PosterPath); diff --git a/Jellyfin.Plugin.Newsletters/ScheduledTasks/ScanLibraryTask.cs b/Jellyfin.Plugin.Newsletters/ScheduledTasks/ScanLibraryTask.cs index 58ce11e..a0aa289 100644 --- a/Jellyfin.Plugin.Newsletters/ScheduledTasks/ScanLibraryTask.cs +++ b/Jellyfin.Plugin.Newsletters/ScheduledTasks/ScanLibraryTask.cs @@ -53,12 +53,9 @@ public Task ExecuteAsync(IProgress progress, CancellationToken cancellat { cancellationToken.ThrowIfCancellationRequested(); progress.Report(0); - // _scanner - // ILibraryManager libManager = _scanner.GetLibrary(); - // Scraper myScraper = new Scraper(); + Scraper myScraper = new Scraper(_libraryManager, progress, cancellationToken); - return myScraper.GetSeriesData(); // .ConfigureAwait(false); - // return Task.CompletedTask; + return myScraper.GetSeriesData(); } } } \ No newline at end of file diff --git a/jellyfin.ruleset b/jellyfin.ruleset index 8af791c..a5d223b 100644 --- a/jellyfin.ruleset +++ b/jellyfin.ruleset @@ -35,6 +35,10 @@ + + + +