Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion HomeLibProt.CollectionManager/Arguments.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ type ArchiveTypeDownload =
| Fb2
| Binary

type LibraryType =
| Fb2
| All

type CLIArguments =
| [<CliPrefix(CliPrefix.None)>] ImportSqlDumps of ParseResults<ImportSqlDumps>
| [<CliPrefix(CliPrefix.None)>] DownloadSqlDumps of ParseResults<DownloadSqlDumps>
Expand Down Expand Up @@ -59,14 +63,17 @@ and GenerateInpx =
| [<ExactlyOnce; AltCommandLine("-i")>] PathToLibrary of string
| [<ExactlyOnce; AltCommandLine("-o")>] PathToInpx of string
| [<ExactlyOnce; AltCommandLine("-d")>] PathToDatabase of string

| [<ExactlyOnce; AltCommandLine("-s")>] Site of Site
| [<ExactlyOnce; AltCommandLine("-l")>] LibraryType of LibraryType

interface IArgParserTemplate with
member this.Usage =
match this with
| 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 =
| [<ExactlyOnce; AltCommandLine("-i")>] PathToLibrary of string
Expand Down
56 changes: 56 additions & 0 deletions HomeLibProt.CollectionManager/Inpx/InpxGenerator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -192,6 +247,7 @@ let generateInpxAsync (parameters: InpxGeneratorParameters) (connection: DbConne
parameters.PathToInpx
(fillInpxAsync
parameters.PathToLibrary
parameters.InpxParameters
parameters.ProgressReport
parameters.ErrorReport
c)
Expand Down
18 changes: 15 additions & 3 deletions HomeLibProt.CollectionManager/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ let downloadBooks (logger: ILogger) (args: ParseResults<DownloadBooks>) : Task<u

let aTD =
match archiveTypeDownload with
| All -> 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
Expand All @@ -77,6 +77,8 @@ let generateInpx (logger: ILogger) (args: ParseResults<GenerateInpx>) : Task<uni
let pathToDb = args.GetResult GenerateInpx.PathToDatabase
let pathToLibrary = args.GetResult GenerateInpx.PathToLibrary
let pathToInpx = args.GetResult GenerateInpx.PathToInpx
let site = args.GetResult GenerateInpx.Site
let libraryType = args.GetResult GenerateInpx.LibraryType

let connection =
pathToDb
Expand All @@ -86,6 +88,16 @@ let generateInpx (logger: ILogger) (args: ParseResults<GenerateInpx>) : Task<uni
let parameters: Inpx.InpxGenerator.InpxGeneratorParameters =
{ PathToLibrary = pathToLibrary
PathToInpx = pathToInpx
InpxParameters =
{ Site =
match site with
| Site.Flibusta -> 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 }
Expand Down
8 changes: 6 additions & 2 deletions HomeLibProt.CollectionManager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ HomeLibProt.CollectionManager.exe importsqldumps -i C:\BookDemo\flibusta_sql\ -d
### Generate INPX

```
USAGE: HomeLibProt.CollectionManager generateinpx [--help] --pathtolibrary <string> --pathtoinpx <string> --pathtodatabase <string>
USAGE: HomeLibProt.CollectionManager generateinpx [--help] --pathtolibrary <string> --pathtoinpx <string> --pathtodatabase <string> --site <flibusta|librusec> --librarytype <fb2|all>

OPTIONS:

Expand All @@ -106,13 +106,17 @@ OPTIONS:
Path to where save inpx on local file system
--pathtodatabase, -d <string>
Path to database on local file system
--site, -s <flibusta|librusec>
Source of books
--librarytype, -l <fb2|all>
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading