Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate calibre web integration, it doesn't work #100

Merged
merged 1 commit into from
Mar 4, 2023
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
21 changes: 0 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ It adds several new features.
* Use `kobodl book get`. There will not be a download button in the webpage for audiobooks because they consist of many large files.
* **multi-user support**; fetch books for multiple accounts.
* **web interface**; adds new browser gui (with flask)
* **CalibreWeb Integration**; send books directly to CalibreWeb from the web interface.
* [docker image](https://github.com/subdavis/kobodl/pkgs/container/kobodl)
* [pypi package](https://pypi.org/project/kobodl/)
* [pyinstaller bundles](https://github.com/subdavis/kobo-book-downloader/releases/latest)
Expand Down Expand Up @@ -206,26 +205,6 @@ Adding a user requires a bit of hackery to get a reCAPTCHA code from Kobo's webs

![Gif explaining how to get reCAPTHCA](docs/captcha.gif)

## CalibreWeb Integration: **Experimental**

Kobodl's web interface can send books directly to your calibre web server. Only supported from web client.

You must add your CalibreWeb server and user details directly in kobodl.json. Make sure to include `/upload` in the url. If you don't have CalibreWeb authentication on, leave these fields blank (`""`).

``` json
{
"users": [ /* ... */ ],
"calibre_web": {
"enabled": true,
"url": "https://calibre.domain.com/upload",
"username": "CHANGEME",
"password": "CHANGEME"
}
}
```

> **NOTE**: you may need to add escape characters if your password contains a `\`, `"`, or others that require JSON escaping.

## Troubleshooting

> I can't log in. My credentials are rejected.
Expand Down
38 changes: 1 addition & 37 deletions kobodl/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ def getUserBooks(userid, error=None, success=None):
if not user:
abort(404)
books = actions.ListBooks([user], False, None)
calibre = Globals.Settings.UserList.calibre_web
return render_template(
'books.j2',
books=books,
calibre=calibre,
error=error,
success=success,
)
Expand All @@ -72,42 +70,8 @@ def downloadBook(userid, productid):
return send_from_directory(absOutputDir, tail, as_attachment=True, attachment_filename=tail)


@app.route('/user/<userid>/book/<productid>/send_to_calibre', methods=['POST'])
def sendToCalibre(userid, productid):
user = Globals.Settings.UserList.getUser(userid)
if not user:
abort(404)
outputDir = app.config.get('output_dir')
os.makedirs(outputDir, exist_ok=True)
# GetBookOrBooks always returns an absolute path
outputFileName = actions.GetBookOrBooks(user, outputDir, productId=productid)
req = Request(
'POST',
url=Globals.Settings.UserList.calibre_web.url,
files={'btn-upload': open(outputFileName, 'rb')},
)
if Globals.Settings.UserList.calibre_web.username:
req.auth = HTTPBasicAuth(
Globals.Settings.UserList.calibre_web.username,
Globals.Settings.UserList.calibre_web.password,
)
success = None
try:
resp = Session().send(req.prepare())
resp.raise_for_status()
success = f"New book uploaded to {resp.json()['location']}"
except HTTPError as err:
return getUserBooks(userid=userid, error=err)
except json.decoder.JSONDecodeError:
return getUserBooks(
userid=userid, error="Could not decode response. Check your CalibreWeb Credentials."
)
return getUserBooks(userid=userid, success=success)


@app.route('/book', methods=['GET'])
def books():
userlist = Globals.Settings.UserList.users
books = actions.ListBooks(userlist, False, None)
calibre = Globals.Settings.UserList.calibre_web
return render_template('books.j2', books=books, calibre=calibre)
return render_template('books.j2', books=books)
2 changes: 0 additions & 2 deletions kobodl/kobo.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ def AuthenticateDevice(self, userKey: str = "") -> None:
# Downloading archived books is not possible, the "content_access_book" API endpoint returns with empty ContentKeys
# and ContentUrls for them.
def Download(self, bookMetadata: dict, isAudiobook: bool, outputPath: str) -> None:

downloadUrl, hasDrm = self.__GetDownloadInfo(bookMetadata, isAudiobook)
revisionId = Kobo.GetProductId(bookMetadata)
temporaryOutputPath = outputPath + ".downloading"
Expand Down Expand Up @@ -375,7 +374,6 @@ def Download(self, bookMetadata: dict, isAudiobook: bool, outputPath: str) -> No
# "library_items" instead to get the My Books list, but "library_items" gives back less info (even with the
# embed=ProductMetadata query parameter set).
def GetMyBookList(self) -> list:

if not self.user.AreAuthenticationSettingsSet():
raise NotAuthenticatedException(f'User {self.user.Email} is not authenticated')

Expand Down
10 changes: 0 additions & 10 deletions kobodl/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@
from dataclasses_json import dataclass_json


@dataclass_json
@dataclasses.dataclass
class CalibreWeb:
enabled: bool = False
url: str = "http://localhost:8083"
username: str = ""
password: str = ""


@dataclass_json
@dataclasses.dataclass
class User:
Expand All @@ -35,7 +26,6 @@ def IsLoggedIn(self) -> bool:
@dataclasses.dataclass
class UserList:
users: List[User] = dataclasses.field(default_factory=list)
calibre_web: CalibreWeb = dataclasses.field(default_factory=CalibreWeb)

def getUser(self, identifier: str) -> Union[User, None]:
for user in self.users:
Expand Down
18 changes: 0 additions & 18 deletions kobodl/templates/books.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
<th class="p-2 pl-4"> Title </th>
<th class="p-2 pl-4"> Author </th>
<th class="p-2 pl-4"> Owner </th>
{% if calibre.enabled %}
<th class="p-2 pl-4"> CalibreWeb </th>
{% endif %}
</tr>
</thead>
<tbody>
Expand All @@ -34,21 +31,6 @@
</td>
<td class="border px-4 p-1">{{ book.Author }}</td>
<td class="border px-4 p-1">{{ book.Owner.Email }}</td>
{% if calibre.enabled %}
<td class="border p-1">
<form
action="{{ url_for('sendToCalibre', userid=book.Owner.UserKey, productid=book.RevisionId) }}"
method="post"
>
<button
class="px-4 mx-1 rounded text-sm bg-blue-500 hover:bg-blue-700 text-white font-bold"
type="submit"
>
Send to Calibre
</button>
</form>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
Expand Down