forked from biblioverse/biblioteca
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kobo): Convert ebooks using kepubify on the fly
- Loading branch information
Showing
13 changed files
with
422 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace App\Kobo; | ||
|
||
class BookDownloadInfo | ||
{ | ||
public function __construct(private int $size, private string $url) | ||
{ | ||
} | ||
|
||
public function getSize(): int | ||
{ | ||
return $this->size; | ||
} | ||
|
||
public function getUrl(): string | ||
{ | ||
return $this->url; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Kobo\Kepubify; | ||
|
||
class KebpubifyCachedData implements \JsonSerializable | ||
{ | ||
private string $content; | ||
private int $size; | ||
|
||
public function __construct(string $filename) | ||
{ | ||
$this->size = (int) filesize($filename); | ||
$this->content = (string) file_get_contents($filename); | ||
} | ||
|
||
public function getSize(): int | ||
{ | ||
return $this->size; | ||
} | ||
|
||
public function getContent(): string | ||
{ | ||
return $this->content; | ||
} | ||
|
||
public function jsonSerialize(): array | ||
{ | ||
return [ | ||
'size' => $this->size, | ||
'content' => $this->content, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Kobo\Kepubify; | ||
|
||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
|
||
class KepubifyEnabler | ||
{ | ||
public function __construct( | ||
#[Autowire(param: 'KEPUBIFY_BIN')] | ||
private string $kepubifyBinary, | ||
) { | ||
} | ||
|
||
public function setKepubifyBinary(string $kepubifyBinary): void | ||
{ | ||
$this->kepubifyBinary = $kepubifyBinary; | ||
} | ||
|
||
public function isEnabled(): bool | ||
{ | ||
return trim($this->kepubifyBinary) !== ''; | ||
} | ||
|
||
public function getKepubifyBinary(): string | ||
{ | ||
return $this->kepubifyBinary; | ||
} | ||
|
||
public function disable(): string | ||
{ | ||
$lastValue = $this->kepubifyBinary; | ||
$this->kepubifyBinary = ''; | ||
|
||
return $lastValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Kobo\Kepubify; | ||
|
||
/** | ||
* Convert an ebook with kepubify binary | ||
* The destination property will be set to the path of the converted file, | ||
*/ | ||
class KepubifyMessage | ||
{ | ||
/** | ||
* @var string|null Path of the destination file (which aim to be a temporary file). Null if the conversion failed. | ||
*/ | ||
public ?string $destination = null; | ||
public ?int $size = null; // File size of the destination file | ||
|
||
public function __construct( | ||
/** Path of the source ebook to convert */ | ||
public string $source, | ||
) { | ||
} | ||
} |
Oops, something went wrong.