sebsync 1.0.1__tar.gz → 1.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,11 +5,11 @@ import requests
|
|
|
5
5
|
import xml.etree.ElementTree as ElementTree
|
|
6
6
|
import zipfile
|
|
7
7
|
|
|
8
|
-
from contextlib import suppress
|
|
9
8
|
from dataclasses import dataclass
|
|
10
9
|
from datetime import datetime, timezone
|
|
11
10
|
from pathlib import Path
|
|
12
11
|
from requests.auth import HTTPBasicAuth
|
|
12
|
+
from urllib.parse import urlparse
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
_dry_run: bool = False
|
|
@@ -25,13 +25,17 @@ class Status:
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
_epilog = f"""
|
|
28
|
-
|
|
28
|
+
\b
|
|
29
|
+
Download naming conventions:
|
|
30
|
+
• standard: Standard Ebooks' naming (e.g. "edwin-a-abbott_flatland.epub")
|
|
31
|
+
• sortable: sortable author/title (e.g. "Abbott, Edwin A. - Flatland.epub")
|
|
29
32
|
|
|
30
33
|
\b
|
|
31
|
-
|
|
32
|
-
{Status.
|
|
33
|
-
{Status.
|
|
34
|
-
{Status.
|
|
34
|
+
Reported file statuses:
|
|
35
|
+
• {Status.NEW}: new (downloads the new ebook to downloads directory)
|
|
36
|
+
• {Status.UPDATE}: update (overwrites the existing local ebook with new version)
|
|
37
|
+
• {Status.EXTRA}: extraneous (local ebook not found in Standard Ebooks catalog)
|
|
38
|
+
• {Status.UNKNOWN}: unknown (local ebook could not be processed)
|
|
35
39
|
|
|
36
40
|
See https://github.com/pbryan/sebsync/ for updates, bug reports and answers.
|
|
37
41
|
"""
|
|
@@ -101,6 +105,8 @@ def get_remote_ebooks(opds_url: str, email: str, type: str) -> dict[str, Standar
|
|
|
101
105
|
updated=fromisoformat(entry.find("atom:updated", ns).text),
|
|
102
106
|
)
|
|
103
107
|
ebooks[ebook.id] = ebook
|
|
108
|
+
if not ebooks:
|
|
109
|
+
raise click.ClickException("OPDS catalog download failed. Is email address correct?")
|
|
104
110
|
return ebooks
|
|
105
111
|
|
|
106
112
|
|
|
@@ -171,9 +177,13 @@ def sortable_author(author: str) -> str:
|
|
|
171
177
|
|
|
172
178
|
|
|
173
179
|
def ebook_filename(ebook: StandardEbook) -> str:
|
|
174
|
-
"""Return an
|
|
180
|
+
"""Return an EPUB file name for Standard ebook."""
|
|
175
181
|
replace = {"/": "-", "‘": "'", "’": "'", '"': "'", "“": "'", "”": "'"}
|
|
176
|
-
|
|
182
|
+
match _naming:
|
|
183
|
+
case "standard":
|
|
184
|
+
result = Path(urlparse(ebook.href).path).name
|
|
185
|
+
case "sortable":
|
|
186
|
+
result = f"{sortable_author(ebook.author)} - {ebook.title}.epub"
|
|
177
187
|
for k, v in replace.items():
|
|
178
188
|
result = result.replace(k, v)
|
|
179
189
|
return result
|
|
@@ -208,6 +218,12 @@ def ebook_filename(ebook: StandardEbook) -> str:
|
|
|
208
218
|
required=True,
|
|
209
219
|
)
|
|
210
220
|
@click.help_option()
|
|
221
|
+
@click.option(
|
|
222
|
+
"--naming",
|
|
223
|
+
type=click.Choice(["standard", "sortable"]),
|
|
224
|
+
help="Download file naming convention.",
|
|
225
|
+
default="standard",
|
|
226
|
+
)
|
|
211
227
|
@click.option(
|
|
212
228
|
"--opds",
|
|
213
229
|
help="URL of Standard Ebooks OPDS catalog.",
|
|
@@ -236,6 +252,7 @@ def sebsync(
|
|
|
236
252
|
dry_run: bool,
|
|
237
253
|
email: str,
|
|
238
254
|
force_update: bool,
|
|
255
|
+
naming: str,
|
|
239
256
|
opds: str,
|
|
240
257
|
quiet: bool,
|
|
241
258
|
type: str,
|
|
@@ -244,14 +261,14 @@ def sebsync(
|
|
|
244
261
|
global _dry_run
|
|
245
262
|
global _verbose
|
|
246
263
|
global _quiet
|
|
264
|
+
global _naming
|
|
247
265
|
|
|
248
266
|
_dry_run = dry_run
|
|
249
|
-
|
|
267
|
+
_naming = naming
|
|
250
268
|
_quiet = quiet
|
|
269
|
+
_verbose = verbose and not quiet # quiet wins
|
|
251
270
|
|
|
252
271
|
remote_ebooks = get_remote_ebooks(opds, email, type)
|
|
253
|
-
if not remote_ebooks:
|
|
254
|
-
raise click.ClickException("OPDS download failed. Is email address correct?")
|
|
255
272
|
if _verbose:
|
|
256
273
|
click.echo(f"Found {len(remote_ebooks)} remote ebooks.")
|
|
257
274
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|