diff --git a/HomeLibProt.CollectionManager/Arguments.fs b/HomeLibProt.CollectionManager/Arguments.fs index 5ace9df..b288337 100644 --- a/HomeLibProt.CollectionManager/Arguments.fs +++ b/HomeLibProt.CollectionManager/Arguments.fs @@ -11,6 +11,10 @@ type ArchiveTypeDownload = | Fb2 | Binary +type LibraryType = + | Fb2 + | All + type CLIArguments = | [] ImportSqlDumps of ParseResults | [] DownloadSqlDumps of ParseResults @@ -59,7 +63,8 @@ and GenerateInpx = | [] PathToLibrary of string | [] PathToInpx of string | [] PathToDatabase of string - + | [] Site of Site + | [] LibraryType of LibraryType interface IArgParserTemplate with member this.Usage = @@ -67,6 +72,8 @@ and GenerateInpx = | PathToLibrary _ -> "Path to library archives on local file system" | PathToInpx _ -> "Path to where save inpx on local file system" | PathToDatabase _ -> "Path to database on local file system" + | Site _ -> "Source of books" + | LibraryType _ -> "Type of library" and DownloadBooks = | [] PathToLibrary of string diff --git a/HomeLibProt.CollectionManager/Inpx/InpxGenerator.fs b/HomeLibProt.CollectionManager/Inpx/InpxGenerator.fs index e031af4..863b92c 100644 --- a/HomeLibProt.CollectionManager/Inpx/InpxGenerator.fs +++ b/HomeLibProt.CollectionManager/Inpx/InpxGenerator.fs @@ -9,9 +9,21 @@ open System.Threading.Tasks open HomeLibProt.Domain.DataAccess open HomeLibProt.Domain.Utils +type Site = + | Flibusta + | Librusec + +type LibraryType = + | Fb2 + | All + +type InpxParameters = + { Site: Site; LibraryType: LibraryType } + type InpxGeneratorParameters = { PathToLibrary: string PathToInpx: string + InpxParameters: InpxParameters ProgressReport: string -> unit ErrorReport: string -> unit DoInTransactionAsync: DbConnection * (DbConnection -> Task) -> Task } @@ -142,14 +154,57 @@ let private importGenreList (connection: DbConnection) (inpx: ZipArchive) : Task do! sw.WriteLineAsync(genreEnumerator.Current |> genreInpxEntityToString) } +let getCode (libraryType: LibraryType) : string = + match libraryType with + | Fb2 -> (65536).ToString Globalization.CultureInfo.InvariantCulture + | All -> (65537).ToString Globalization.CultureInfo.InvariantCulture + +let private getDateString () : string = DateTime.Now.ToString "yyyy-MM-dd" + +let private getLibraryType (libraryType: LibraryType) : string = + match libraryType with + | Fb2 -> "FB2" + | All -> "ALL" + +let private getLibraryName (site: Site) : string = + match site with + | Flibusta -> "Flibusta" + | Librusec -> "Librusec" + +let private getCollectionInfoContent (inpxParameters: InpxParameters) : string = + let name = getLibraryName inpxParameters.Site + let libType = getLibraryType inpxParameters.LibraryType + let date = getDateString () + + $"{name} {libType} - {date} +{name.ToLower}_{libType.ToLower}_{date} +{getCode inpxParameters.LibraryType} +Collection of {name} {libType} books +" + +let private addCollectionInfo (inpx: ZipArchive) (inpxParameters: InpxParameters) : Task = + task { + let collectionInfo = inpx.CreateEntry "collection.info" + + use fs = collectionInfo.Open() + use sw = new StreamWriter(fs) + + do! sw.WriteAsync(getCollectionInfoContent inpxParameters) + } + let private fillInpxAsync (pathToLibrary: string) + (inpxParameters: InpxParameters) (reportProgress: string -> unit) (reportError: string -> unit) (connection: DbConnection) (inpx: ZipArchive) = task { + reportProgress $"Make collection.info" + + do! addCollectionInfo inpx inpxParameters + reportProgress $"Importing Genres List" do! importGenreList connection inpx @@ -192,6 +247,7 @@ let generateInpxAsync (parameters: InpxGeneratorParameters) (connection: DbConne parameters.PathToInpx (fillInpxAsync parameters.PathToLibrary + parameters.InpxParameters parameters.ProgressReport parameters.ErrorReport c) diff --git a/HomeLibProt.CollectionManager/Program.fs b/HomeLibProt.CollectionManager/Program.fs index fcdf71c..22d8dba 100644 --- a/HomeLibProt.CollectionManager/Program.fs +++ b/HomeLibProt.CollectionManager/Program.fs @@ -54,9 +54,9 @@ let downloadBooks (logger: ILogger) (args: ParseResults) : Task BooksDownloader.ArchiveTypeDownload.All - | Fb2 -> BooksDownloader.ArchiveTypeDownload.Fb2 - | Binary -> BooksDownloader.ArchiveTypeDownload.Binary + | ArchiveTypeDownload.All -> BooksDownloader.ArchiveTypeDownload.All + | ArchiveTypeDownload.Fb2 -> BooksDownloader.ArchiveTypeDownload.Fb2 + | ArchiveTypeDownload.Binary -> BooksDownloader.ArchiveTypeDownload.Binary let parameters: BooksDownloader.BooksDownloaderParameters = { PathToLibrary = pathToLibrary @@ -77,6 +77,8 @@ let generateInpx (logger: ILogger) (args: ParseResults) : Task) : Task Inpx.InpxGenerator.Site.Flibusta + | Site.Librusec -> Inpx.InpxGenerator.Site.Librusec + | _ -> raise (InvalidOperationException $"Unknown books source: {site}") + LibraryType = + match libraryType with + | Fb2 -> Inpx.InpxGenerator.LibraryType.Fb2 + | All -> Inpx.InpxGenerator.LibraryType.All } ProgressReport = printProgressReport logger ErrorReport = printErrorReport logger DoInTransactionAsync = ConnectionUtils.DoInTransactionAsync } diff --git a/HomeLibProt.CollectionManager/README.md b/HomeLibProt.CollectionManager/README.md index 18517f9..449883e 100644 --- a/HomeLibProt.CollectionManager/README.md +++ b/HomeLibProt.CollectionManager/README.md @@ -96,7 +96,7 @@ HomeLibProt.CollectionManager.exe importsqldumps -i C:\BookDemo\flibusta_sql\ -d ### Generate INPX ``` -USAGE: HomeLibProt.CollectionManager generateinpx [--help] --pathtolibrary --pathtoinpx --pathtodatabase +USAGE: HomeLibProt.CollectionManager generateinpx [--help] --pathtolibrary --pathtoinpx --pathtodatabase --site --librarytype OPTIONS: @@ -106,13 +106,17 @@ OPTIONS: Path to where save inpx on local file system --pathtodatabase, -d Path to database on local file system + --site, -s + Source of books + --librarytype, -l + Type of library --help display this list of options. ``` Example ``` -HomeLibProt.CollectionManager.exe generateinpx -i C:\BookDemo\Books\ -d C:\BookDemo\sql_dump.db -o C:\BookDemo\Inpx.inpx +HomeLibProt.CollectionManager.exe generateinpx -i C:\BookDemo\Books\ -d C:\BookDemo\sql_dump.db -o C:\BookDemo\Inpx.inpx -s flibusta -l fb2 ``` ### Download book archives diff --git a/HomeLibProt.CollectionManager/Scripts/FlibustaGetDailyUpdateFb2.ps1 b/HomeLibProt.CollectionManager/Scripts/FlibustaGetDailyUpdateFb2.ps1 index 13c0c22..bc0a05f 100644 --- a/HomeLibProt.CollectionManager/Scripts/FlibustaGetDailyUpdateFb2.ps1 +++ b/HomeLibProt.CollectionManager/Scripts/FlibustaGetDailyUpdateFb2.ps1 @@ -50,7 +50,7 @@ if (!$?) { throw "Importing sql dumps failed" } -& $toolPath/HomeLibProt.CollectionManager.exe generateinpx -i $LibraryPath -d "$sqlDumpsPath/sql_dump.db" -o "$sqlDumpsPath/$inpxName" +& $toolPath/HomeLibProt.CollectionManager.exe generateinpx -i $LibraryPath -d "$sqlDumpsPath/sql_dump.db" -o "$sqlDumpsPath/$inpxName" -s $siteKey -l fb2 if (!$?) { throw "Generating inpx failed" diff --git a/HomeLibProt.CollectionManager/Scripts/FlibustaGetDailyUpdateFb2.sh b/HomeLibProt.CollectionManager/Scripts/FlibustaGetDailyUpdateFb2.sh index fc8ca21..ece5360 100644 --- a/HomeLibProt.CollectionManager/Scripts/FlibustaGetDailyUpdateFb2.sh +++ b/HomeLibProt.CollectionManager/Scripts/FlibustaGetDailyUpdateFb2.sh @@ -53,7 +53,7 @@ if [ $? -ne 0 ]; then exit 1 fi -$ToolPath/HomeLibProt.CollectionManager generateinpx -i $LibraryPath -d "$SqlDumpsPath/sql_dump.db" -o "$SqlDumpsPath/$InpxName" +$ToolPath/HomeLibProt.CollectionManager generateinpx -i $LibraryPath -d "$SqlDumpsPath/sql_dump.db" -o "$SqlDumpsPath/$InpxName" -s $SiteKey -l fb2 if [ $? -ne 0 ]; then echo "Generating inpx failed" diff --git a/HomeLibProt.CollectionManager/Scripts/FlibustaGetDailyUpdateFb2AndUsr.ps1 b/HomeLibProt.CollectionManager/Scripts/FlibustaGetDailyUpdateFb2AndUsr.ps1 index db00fba..daad3ae 100644 --- a/HomeLibProt.CollectionManager/Scripts/FlibustaGetDailyUpdateFb2AndUsr.ps1 +++ b/HomeLibProt.CollectionManager/Scripts/FlibustaGetDailyUpdateFb2AndUsr.ps1 @@ -64,7 +64,7 @@ if (!$?) { throw "Importing sql dumps failed" } -& $toolPath/HomeLibProt.CollectionManager.exe generateinpx -i $LibraryPath -d "$sqlDumpsPath/sql_dump.db" -o "$sqlDumpsPath/$inpxName" +& $toolPath/HomeLibProt.CollectionManager.exe generateinpx -i $LibraryPath -d "$sqlDumpsPath/sql_dump.db" -o "$sqlDumpsPath/$inpxName" -s $siteKey -l all if (!$?) { throw "Generating inpx failed" diff --git a/HomeLibProt.CollectionManager/Scripts/FlibustaGetDailyUpdateFb2AndUsr.sh b/HomeLibProt.CollectionManager/Scripts/FlibustaGetDailyUpdateFb2AndUsr.sh index 6aaf5ca..c8aaf43 100644 --- a/HomeLibProt.CollectionManager/Scripts/FlibustaGetDailyUpdateFb2AndUsr.sh +++ b/HomeLibProt.CollectionManager/Scripts/FlibustaGetDailyUpdateFb2AndUsr.sh @@ -69,7 +69,7 @@ if [ $? -ne 0 ]; then exit 1 fi -$ToolPath/HomeLibProt.CollectionManager generateinpx -i $LibraryPath -d "$SqlDumpsPath/sql_dump.db" -o "$SqlDumpsPath/$InpxName" +$ToolPath/HomeLibProt.CollectionManager generateinpx -i $LibraryPath -d "$SqlDumpsPath/sql_dump.db" -o "$SqlDumpsPath/$InpxName" -s $SiteKey -l all if [ $? -ne 0 ]; then echo "Generating inpx failed" diff --git a/HomeLibProt.CollectionManager/Scripts/FlibustaGetMonthlyUpdateFb2.ps1 b/HomeLibProt.CollectionManager/Scripts/FlibustaGetMonthlyUpdateFb2.ps1 index 6acd2b5..5d28b8a 100644 --- a/HomeLibProt.CollectionManager/Scripts/FlibustaGetMonthlyUpdateFb2.ps1 +++ b/HomeLibProt.CollectionManager/Scripts/FlibustaGetMonthlyUpdateFb2.ps1 @@ -42,7 +42,7 @@ if (!$?) { throw "Importing sql dumps failed" } -& $toolPath/HomeLibProt.CollectionManager.exe generateinpx -i $LibraryPath -d "$sqlDumpsPath/sql_dump.db" -o "$sqlDumpsPath/$inpxName" +& $toolPath/HomeLibProt.CollectionManager.exe generateinpx -i $LibraryPath -d "$sqlDumpsPath/sql_dump.db" -o "$sqlDumpsPath/$inpxName" -s $siteKey -l fb2 if (!$?) { throw "Generating inpx failed" diff --git a/HomeLibProt.CollectionManager/Scripts/FlibustaGetMonthlyUpdateFb2.sh b/HomeLibProt.CollectionManager/Scripts/FlibustaGetMonthlyUpdateFb2.sh index 1ae2583..d1fbbae 100644 --- a/HomeLibProt.CollectionManager/Scripts/FlibustaGetMonthlyUpdateFb2.sh +++ b/HomeLibProt.CollectionManager/Scripts/FlibustaGetMonthlyUpdateFb2.sh @@ -44,7 +44,7 @@ if [ $? -ne 0 ]; then exit 1 fi -$ToolPath/HomeLibProt.CollectionManager generateinpx -i $LibraryPath -d "$SqlDumpsPath/sql_dump.db" -o "$SqlDumpsPath/$InpxName" +$ToolPath/HomeLibProt.CollectionManager generateinpx -i $LibraryPath -d "$SqlDumpsPath/sql_dump.db" -o "$SqlDumpsPath/$InpxName" -s $SiteKey -l fb2 if [ $? -ne 0 ]; then echo "Generating inpx failed" diff --git a/HomeLibProt.CollectionManager/Scripts/FlibustaGetMonthlyUpdateFb2AndUsr.ps1 b/HomeLibProt.CollectionManager/Scripts/FlibustaGetMonthlyUpdateFb2AndUsr.ps1 index aef11c9..8c61365 100644 --- a/HomeLibProt.CollectionManager/Scripts/FlibustaGetMonthlyUpdateFb2AndUsr.ps1 +++ b/HomeLibProt.CollectionManager/Scripts/FlibustaGetMonthlyUpdateFb2AndUsr.ps1 @@ -48,7 +48,7 @@ if (!$?) { throw "Importing sql dumps failed" } -& $toolPath/HomeLibProt.CollectionManager.exe generateinpx -i $LibraryPath -d "$sqlDumpsPath/sql_dump.db" -o "$sqlDumpsPath/$inpxName" +& $toolPath/HomeLibProt.CollectionManager.exe generateinpx -i $LibraryPath -d "$sqlDumpsPath/sql_dump.db" -o "$sqlDumpsPath/$inpxName" -s $siteKey -l all if (!$?) { throw "Generating inpx failed" diff --git a/HomeLibProt.CollectionManager/Scripts/FlibustaGetMonthlyUpdateFb2AndUsr.sh b/HomeLibProt.CollectionManager/Scripts/FlibustaGetMonthlyUpdateFb2AndUsr.sh index 7c1dcfa..e819336 100644 --- a/HomeLibProt.CollectionManager/Scripts/FlibustaGetMonthlyUpdateFb2AndUsr.sh +++ b/HomeLibProt.CollectionManager/Scripts/FlibustaGetMonthlyUpdateFb2AndUsr.sh @@ -51,7 +51,7 @@ if [ $? -ne 0 ]; then exit 1 fi -$ToolPath/HomeLibProt.CollectionManager generateinpx -i $LibraryPath -d "$SqlDumpsPath/sql_dump.db" -o "$SqlDumpsPath/$InpxName" +$ToolPath/HomeLibProt.CollectionManager generateinpx -i $LibraryPath -d "$SqlDumpsPath/sql_dump.db" -o "$SqlDumpsPath/$InpxName" -s $SiteKey -l all if [ $? -ne 0 ]; then echo "Generating inpx failed"