mirror of
https://github.com/calibrain/shelfmark.git
synced 2026-11-21 08:56:38 +00:00
feat(hardcover): owned books, simpler queries, dead sources and failed releases (#1535)
A request whose book turns out to be in the library is closed with the note `[auto] Already in the library.` instead of sitting in Needs Review. A request an admin handled by hand while a pass was running is skipped. A series label in front of a Calibre title no longer hides an owned book, and a Calibre title marked as another edition (full cast, dramatized, GraphicAudio) is not the book. When no source matches, up to three simpler forms of the title are tried on each source under the same strict match. Optionally (off by default), an unmatched audiobook request is looked up on Audible US and UK through Audiobookshelf's metadata search and the request says what the store answered. It never declines anything. A Soulseek peer whose recent transfers all failed, and an AudiobookBay post whose comments say it has no seeders, are tried after the other matches and never excluded. A failed or stalled release is kept out for AUTO_DOWNLOAD_RETRY_FAILED_RELEASE_DAYS and then tried again, and a torrent that died for one request is not offered to another. A request stuck on queued or downloading is settled from the download history. Optionally (off by default) a failed download is retried with another release within minutes.
This commit is contained in:
1 parent
9d5b47d17b
commit
86fff32297
25 files changed
+3948
-87
No files matched your search
@@ -495,3 +495,32 @@ class TestExtractMagnetLink:
|
||||
assert magnet_link is not None
|
||||
# Info hash should be cleaned (no spaces, uppercase)
|
||||
assert "ABC123DEF456" in magnet_link
|
||||
|
||||
|
||||
def _post_with_comments(*comments: str) -> str:
|
||||
bodies = "".join(
|
||||
f'<li itemprop="review"><div itemprop="reviewBody"><p>{text}</p></div></li>'
|
||||
for text in comments
|
||||
)
|
||||
return f"<html><body><p>Seed it please, this page text is not a comment</p><ul>{bodies}</ul></body></html>"
|
||||
|
||||
|
||||
def test_seed_complaints_counts_the_comments_that_say_nobody_is_seeding():
|
||||
html = _post_with_comments(
|
||||
"Please seed and thank you",
|
||||
"I think you have a problem, as it has 0 seeders. Can somebody please seed or reup?",
|
||||
"No seeds :(",
|
||||
"Great narrator, thanks for the upload",
|
||||
)
|
||||
|
||||
assert scraper.extract_seed_complaints(html) == 3
|
||||
|
||||
|
||||
def test_seed_complaints_ignores_page_text_outside_the_comments():
|
||||
assert scraper.extract_seed_complaints(_post_with_comments("Loved it")) == 0
|
||||
|
||||
|
||||
def test_seed_complaints_reads_dead_and_unseeded():
|
||||
html = _post_with_comments("link is dead", "all of these are unseeded", "worked for me")
|
||||
|
||||
assert scraper.extract_seed_complaints(html) == 2
|
||||
@@ -0,0 +1,283 @@
|
||||
[
|
||||
{
|
||||
"title": "The Hobbit (Dramatised)",
|
||||
"subtitle": "The Classic BBC Radio Production",
|
||||
"author": "J.R.R. Tolkien",
|
||||
"narrator": "Heron Carvic, Paul Daneman, Anthony Jackson, Francis de Wolff, John Justin, John Pullen, Full cast",
|
||||
"publisher": "BBC Digital Audio",
|
||||
"publishedYear": "2007",
|
||||
"description": "Dwarves, elves, goblins, trolls, dragons and wizards - these are the ingredients of J.R.R. Tolkien's wonderful fantasy, ...",
|
||||
"cover": "https://m.media-amazon.com/images/I/81wq-zTbNNL.jpg",
|
||||
"asin": "B004F440NU",
|
||||
"isbn": "9781405629423",
|
||||
"genres": [
|
||||
"Children's Audiobooks",
|
||||
"Science Fiction & Fantasy"
|
||||
],
|
||||
"tags": [
|
||||
"Science Fiction & Fantasy",
|
||||
"Fantasy",
|
||||
"Science Fiction"
|
||||
],
|
||||
"series": null,
|
||||
"language": "English",
|
||||
"duration": 222,
|
||||
"region": "uk",
|
||||
"rating": "4.4",
|
||||
"abridged": false,
|
||||
"descriptionPlain": "Dwarves, elves, goblins, trolls, dragons and wizards - these are the ingredients of J.R.R. Tolkien's wonderful fantasy, ..."
|
||||
},
|
||||
{
|
||||
"title": "The Hobbit",
|
||||
"subtitle": null,
|
||||
"author": "J. R. R. Tolkien",
|
||||
"narrator": "Martin Shaw",
|
||||
"publisher": "HarperCollins",
|
||||
"publishedYear": "2005",
|
||||
"description": "<p>Bilbo Baggins is a hobbit who enjoys a comfortable and quiet life. His contentment is disturbed one day when the wiza...",
|
||||
"cover": "https://m.media-amazon.com/images/I/61giqd1Hw2L.jpg",
|
||||
"asin": "B004EWDDIQ",
|
||||
"isbn": "9780007227761",
|
||||
"genres": [
|
||||
"Literature & Fiction",
|
||||
"Science Fiction & Fantasy"
|
||||
],
|
||||
"tags": [
|
||||
"Historical Fiction",
|
||||
"Fantasy",
|
||||
"Action & Adventure",
|
||||
"Epic"
|
||||
],
|
||||
"series": null,
|
||||
"language": "English",
|
||||
"duration": 357,
|
||||
"region": "uk",
|
||||
"rating": "4.6",
|
||||
"abridged": true,
|
||||
"descriptionPlain": "Bilbo Baggins is a hobbit who enjoys a comfortable and quiet life. His contentment is disturbed one day when the wizard,..."
|
||||
},
|
||||
{
|
||||
"title": "Le Hobbit",
|
||||
"subtitle": null,
|
||||
"author": "J. R. R. Tolkien",
|
||||
"narrator": "Dominique Pinon",
|
||||
"publisher": "Audiolib",
|
||||
"publishedYear": "2012",
|
||||
"description": "<p>Premier récit publié par J.R.R. Tolkien, en 1937, cette histoire, inventée par l’auteur pour ses propres enfants, rac...",
|
||||
"cover": "https://m.media-amazon.com/images/I/61QhIC8qW1L.jpg",
|
||||
"asin": "B00U6GZ0DU",
|
||||
"isbn": "9782356414847",
|
||||
"genres": [
|
||||
"Science Fiction & Fantasy"
|
||||
],
|
||||
"tags": [
|
||||
"Fantasy",
|
||||
"Action & Adventure"
|
||||
],
|
||||
"series": null,
|
||||
"language": "French",
|
||||
"duration": 614,
|
||||
"region": "uk",
|
||||
"rating": "4.7",
|
||||
"abridged": false,
|
||||
"descriptionPlain": "Premier récit publié par J.R.R. Tolkien, en 1937, cette histoire, inventée par l’auteur pour ses propres enfants, racont..."
|
||||
},
|
||||
{
|
||||
"title": "Der Hobbit",
|
||||
"subtitle": "Der Herr der Ringe 0.5",
|
||||
"author": "J. R. R. Tolkien",
|
||||
"narrator": "Gert Heidenreich",
|
||||
"publisher": "Der Hörverlag",
|
||||
"publishedYear": "2010",
|
||||
"description": "Bilbo Beutlin, der kleine Hobbit, macht sich auf den Weg zum Einsamen Berg, um den rechtmäßigen Schatz der Zwerge zurück...",
|
||||
"cover": "https://m.media-amazon.com/images/I/91k9ci7Xf4L.jpg",
|
||||
"asin": "B00THFMDYA",
|
||||
"genres": null,
|
||||
"tags": [
|
||||
"Literature & Fiction",
|
||||
"Genre Fiction",
|
||||
"Movie, TV & Video Game Tie-Ins",
|
||||
"Science Fiction & Fantasy",
|
||||
"Fantasy",
|
||||
"Action & Adventure",
|
||||
"Dragons & Mythical Creatures"
|
||||
],
|
||||
"series": null,
|
||||
"language": "German",
|
||||
"duration": 653,
|
||||
"region": "us",
|
||||
"rating": "4.7",
|
||||
"abridged": false,
|
||||
"descriptionPlain": "Bilbo Beutlin, der kleine Hobbit, macht sich auf den Weg zum Einsamen Berg, um den rechtmäßigen Schatz der Zwerge zurück..."
|
||||
},
|
||||
{
|
||||
"title": "A Hobbit",
|
||||
"subtitle": null,
|
||||
"author": "J. R. R. Tolkien",
|
||||
"narrator": "Kaszás Attila",
|
||||
"publisher": "Mojzer Publishing House",
|
||||
"publishedYear": "2019",
|
||||
"description": "<p>A Hobbit, mint Tolkien sok más írása, gyermekeinek szóló történetként indult. Először 1937-ben jelent meg és ma méltá...",
|
||||
"cover": "https://m.media-amazon.com/images/I/91t3yGvAcNL.jpg",
|
||||
"asin": "9630999633",
|
||||
"isbn": "9789630999632",
|
||||
"genres": [
|
||||
"Science Fiction & Fantasy"
|
||||
],
|
||||
"tags": [
|
||||
"Fantasy",
|
||||
"Epic"
|
||||
],
|
||||
"series": null,
|
||||
"language": "Hungarian",
|
||||
"duration": 742,
|
||||
"region": "uk",
|
||||
"rating": "5.0",
|
||||
"abridged": false,
|
||||
"descriptionPlain": "A Hobbit, mint Tolkien sok más írása, gyermekeinek szóló történetként indult. Először 1937-ben jelent meg és ma méltán v..."
|
||||
},
|
||||
{
|
||||
"title": "The Hobbit",
|
||||
"subtitle": "The BBC TV soundtrack of the Jackanory multi-voice reading",
|
||||
"author": "J. R. R. Tolkien",
|
||||
"narrator": "Bernard Cribbins, Maurice Denham, Jan Francis, David Wood",
|
||||
"publisher": "BBC Digital Audio",
|
||||
"publishedYear": "2013",
|
||||
"description": "<p>The BBC TV soundtrack of the acclaimed Jackanory multi-voice reading of <i>The Hobbit</i>. Broadcast to mark the 3000...",
|
||||
"cover": "https://m.media-amazon.com/images/I/91QjFToijwL.jpg",
|
||||
"asin": "B00FH7B866",
|
||||
"isbn": "9781471358388",
|
||||
"genres": [
|
||||
"Science Fiction & Fantasy",
|
||||
"Arts & Entertainment"
|
||||
],
|
||||
"tags": [
|
||||
"Fantasy",
|
||||
"Entertainment & Performing Arts"
|
||||
],
|
||||
"series": null,
|
||||
"language": "English",
|
||||
"duration": 147,
|
||||
"region": "uk",
|
||||
"rating": "4.6",
|
||||
"abridged": true,
|
||||
"descriptionPlain": "The BBC TV soundtrack of the acclaimed Jackanory multi-voice reading of The Hobbit. Broadcast to mark the 3000th program..."
|
||||
},
|
||||
{
|
||||
"title": "El Hobbit",
|
||||
"subtitle": null,
|
||||
"author": "J. R. R. Tolkien",
|
||||
"narrator": "Javier Gutiérrez",
|
||||
"publisher": "Audible Studios y Planeta Audio",
|
||||
"publishedYear": "2023",
|
||||
"description": "<p>La extraordinaria precuela de El Señor de los Anillos.</p> <p>Smaug parecía profundamente dormido cuando Bilbo espió ...",
|
||||
"cover": "https://m.media-amazon.com/images/I/91snBF2IakL.jpg",
|
||||
"asin": "B0C8YZD5HL",
|
||||
"isbn": "9788445016282",
|
||||
"genres": [
|
||||
"Science Fiction & Fantasy"
|
||||
],
|
||||
"tags": [
|
||||
"Fantasy"
|
||||
],
|
||||
"series": [
|
||||
{
|
||||
"series": "El Señor de los Anillos",
|
||||
"sequence": "0.5"
|
||||
}
|
||||
],
|
||||
"language": "Spanish",
|
||||
"duration": 640,
|
||||
"region": "uk",
|
||||
"rating": "4.7",
|
||||
"abridged": false,
|
||||
"descriptionPlain": "La extraordinaria precuela de El Señor de los Anillos. Smaug parecía profundamente dormido cuando Bilbo espió una vez má..."
|
||||
},
|
||||
{
|
||||
"title": "Der Hobbit",
|
||||
"subtitle": "Das Hörspiel",
|
||||
"author": "J. R. R. Tolkien",
|
||||
"narrator": "Martin Benrath, Horst Bollmann, Bernhard Minetti",
|
||||
"publisher": "Der Hörverlag",
|
||||
"publishedYear": "2010",
|
||||
"description": "\"Der Hobbit\", erschienen 1937, ist Tolkiens erstes nichtwissenschaftliches Werk und gilt als Vorläufer der großen Trilog...",
|
||||
"cover": "https://m.media-amazon.com/images/I/91BI9o5aCCL.jpg",
|
||||
"asin": "B00TPM5GLW",
|
||||
"genres": null,
|
||||
"tags": [
|
||||
"Literature & Fiction",
|
||||
"Genre Fiction",
|
||||
"Movie, TV & Video Game Tie-Ins",
|
||||
"Science Fiction & Fantasy",
|
||||
"Fantasy",
|
||||
"Dragons & Mythical Creatures"
|
||||
],
|
||||
"series": null,
|
||||
"language": "German",
|
||||
"duration": 267,
|
||||
"region": "us",
|
||||
"rating": "5.0",
|
||||
"abridged": false,
|
||||
"descriptionPlain": "\"Der Hobbit\", erschienen 1937, ist Tolkiens erstes nichtwissenschaftliches Werk und gilt als Vorläufer der großen Trilog..."
|
||||
},
|
||||
{
|
||||
"title": "The Hobbit",
|
||||
"subtitle": null,
|
||||
"author": "J.R.R. Tolkien",
|
||||
"narrator": "Rob Inglis",
|
||||
"publisher": "Recorded Books",
|
||||
"publishedYear": "2012",
|
||||
"description": "Like every other hobbit, Bilbo Baggins likes nothing better than a quiet evening in his snug hole in the ground, dining ...",
|
||||
"cover": "https://m.media-amazon.com/images/I/81K05vSpbxL.jpg",
|
||||
"asin": "B07935Q3J5",
|
||||
"isbn": "9781470337582",
|
||||
"genres": [
|
||||
"Children's Audiobooks",
|
||||
"Teen & Young Adult"
|
||||
],
|
||||
"tags": [
|
||||
"Literature & Fiction",
|
||||
"Classics",
|
||||
"Science Fiction & Fantasy"
|
||||
],
|
||||
"series": [
|
||||
{
|
||||
"series": "The Lord of the Rings",
|
||||
"sequence": "0.5"
|
||||
}
|
||||
],
|
||||
"language": "English",
|
||||
"duration": 664,
|
||||
"region": "uk",
|
||||
"rating": "0.0",
|
||||
"abridged": false,
|
||||
"descriptionPlain": "Like every other hobbit, Bilbo Baggins likes nothing better than a quiet evening in his snug hole in the ground, dining ..."
|
||||
},
|
||||
{
|
||||
"title": "El hòbbit [The Hobbit]",
|
||||
"subtitle": "o viatge d’anada i tornada [Or, There and Back Again]",
|
||||
"author": "J.R.R. Tolkien",
|
||||
"narrator": "Jordi Boixaderas",
|
||||
"publisher": "Penguin Random House Audio",
|
||||
"publishedYear": "2022",
|
||||
"description": "<p><b>Acompanya en Bilbo Saquet en una aventura plena de màgia, criatures fantàstiques i un anell misteriós...</b></p> <...",
|
||||
"cover": "https://m.media-amazon.com/images/I/71D9MZTRzPL.jpg",
|
||||
"asin": "B0BK4WJMHJ",
|
||||
"genres": null,
|
||||
"tags": [
|
||||
"Literature & Fiction",
|
||||
"Classics",
|
||||
"Science Fiction & Fantasy",
|
||||
"Fantasy",
|
||||
"Action & Adventure",
|
||||
"Epic"
|
||||
],
|
||||
"series": null,
|
||||
"language": "Catalan",
|
||||
"duration": 677,
|
||||
"region": "us",
|
||||
"rating": "0.0",
|
||||
"abridged": false,
|
||||
"descriptionPlain": "Acompanya en Bilbo Saquet en una aventura plena de màgia, criatures fantàstiques i un anell misteriós... Situada l'any 2..."
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
@@ -0,0 +1,34 @@
|
||||
[
|
||||
{
|
||||
"title": "The Advocate's Dilemma",
|
||||
"subtitle": "The Advocate Series, Book 4",
|
||||
"author": "Teresa Burrell",
|
||||
"narrator": "Laurel Schroeder",
|
||||
"publisher": "Teresa Burrell",
|
||||
"publishedYear": "2014",
|
||||
"description": "<p>Attorney Sabre Brown's day is going well until she walks into her office and finds a dead man sprawled across her des...",
|
||||
"cover": "https://m.media-amazon.com/images/I/817+pXebv0L.jpg",
|
||||
"asin": "B00K23YZJM",
|
||||
"isbn": "",
|
||||
"genres": [
|
||||
"Mystery, Thriller & Suspense"
|
||||
],
|
||||
"tags": [
|
||||
"Mystery",
|
||||
"Thriller & Suspense",
|
||||
"Legal"
|
||||
],
|
||||
"series": [
|
||||
{
|
||||
"series": "The Advocate",
|
||||
"sequence": "4"
|
||||
}
|
||||
],
|
||||
"language": "English",
|
||||
"duration": 516,
|
||||
"region": "us",
|
||||
"rating": "4.2",
|
||||
"abridged": false,
|
||||
"descriptionPlain": "Attorney Sabre Brown's day is going well until she walks into her office and finds a dead man sprawled across her desk. ..."
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,302 @@
|
||||
[
|
||||
{
|
||||
"title": "The Hobbit",
|
||||
"subtitle": null,
|
||||
"author": "J. R. R. Tolkien",
|
||||
"narrator": "Andy Serkis",
|
||||
"publisher": "Recorded Books",
|
||||
"publishedYear": "2020",
|
||||
"description": "<p>THE GREAT MODERN CLASSIC AND PRELUDE TO THE LORD OF THE RINGS<br /> <br /> Deep down here by the dark water lived old...",
|
||||
"cover": "https://m.media-amazon.com/images/I/91Q00mYqCFL.jpg",
|
||||
"asin": "1705009050",
|
||||
"isbn": "9781705009055",
|
||||
"genres": [
|
||||
"Literature & Fiction",
|
||||
"Science Fiction & Fantasy",
|
||||
"Teen & Young Adult"
|
||||
],
|
||||
"tags": [
|
||||
"Action & Adventure",
|
||||
"Classics",
|
||||
"Genre Fiction",
|
||||
"Literary Fiction",
|
||||
"Fantasy"
|
||||
],
|
||||
"series": [
|
||||
{
|
||||
"series": "The Lord of the Rings",
|
||||
"sequence": "0.5"
|
||||
}
|
||||
],
|
||||
"language": "English",
|
||||
"duration": 625,
|
||||
"region": "us",
|
||||
"rating": "4.9",
|
||||
"abridged": false,
|
||||
"descriptionPlain": "THE GREAT MODERN CLASSIC AND PRELUDE TO THE LORD OF THE RINGS Deep down here by the dark water lived old Gollum, a smal..."
|
||||
},
|
||||
{
|
||||
"title": "The Hobbit",
|
||||
"subtitle": null,
|
||||
"author": "J.R.R. Tolkien",
|
||||
"narrator": "Rob Inglis",
|
||||
"publisher": "Recorded Books",
|
||||
"publishedYear": "2012",
|
||||
"description": "Like every other hobbit, Bilbo Baggins likes nothing better than a quiet evening in his snug hole in the ground, dining ...",
|
||||
"cover": "https://m.media-amazon.com/images/I/81K05vSpbxL.jpg",
|
||||
"asin": "B0099RKI5W",
|
||||
"isbn": "9781470337582",
|
||||
"genres": [
|
||||
"Children's Audiobooks",
|
||||
"Teen & Young Adult"
|
||||
],
|
||||
"tags": [
|
||||
"Literature & Fiction",
|
||||
"Classics",
|
||||
"Science Fiction & Fantasy",
|
||||
"Fantasy & Magic",
|
||||
"Fantasy",
|
||||
"Epic"
|
||||
],
|
||||
"series": [
|
||||
{
|
||||
"series": "The Lord of the Rings",
|
||||
"sequence": "0.5"
|
||||
}
|
||||
],
|
||||
"language": "English",
|
||||
"duration": 664,
|
||||
"region": "us",
|
||||
"rating": "4.8",
|
||||
"abridged": false,
|
||||
"descriptionPlain": "Like every other hobbit, Bilbo Baggins likes nothing better than a quiet evening in his snug hole in the ground, dining ..."
|
||||
},
|
||||
{
|
||||
"title": "The Hobbit",
|
||||
"subtitle": null,
|
||||
"author": "J.R.R. Tolkien",
|
||||
"narrator": "Ensemble Cast",
|
||||
"publisher": "Highbridge Audio",
|
||||
"publishedYear": "2007",
|
||||
"description": "The original American full dramatization as broadcast on National Public Radio. <p>Bilbo Baggins, a gentle hobbit who lo...",
|
||||
"cover": "https://m.media-amazon.com/images/I/51+Hqnuf-YL.jpg",
|
||||
"asin": "B002VA9IR8",
|
||||
"isbn": "9781598874495",
|
||||
"genres": [
|
||||
"Literature & Fiction",
|
||||
"Science Fiction & Fantasy"
|
||||
],
|
||||
"tags": [
|
||||
"Classics",
|
||||
"Fantasy",
|
||||
"Epic"
|
||||
],
|
||||
"series": null,
|
||||
"language": "English",
|
||||
"duration": 253,
|
||||
"region": "us",
|
||||
"rating": "4.3",
|
||||
"abridged": false,
|
||||
"descriptionPlain": "The original American full dramatization as broadcast on National Public Radio. Bilbo Baggins, a gentle hobbit who loves..."
|
||||
},
|
||||
{
|
||||
"title": "Le Hobbit",
|
||||
"subtitle": null,
|
||||
"author": "J. R. R. Tolkien",
|
||||
"narrator": "Dominique Pinon",
|
||||
"publisher": "Audiolib",
|
||||
"publishedYear": "2012",
|
||||
"description": "<p>Premier récit publié par J.R.R. Tolkien, en 1937, cette histoire, inventée par l’auteur pour ses propres enfants, rac...",
|
||||
"cover": "https://m.media-amazon.com/images/I/61QhIC8qW1L.jpg",
|
||||
"asin": "B00U6GS58C",
|
||||
"isbn": "9782356414847",
|
||||
"genres": [
|
||||
"Mystery, Thriller & Suspense",
|
||||
"Science Fiction & Fantasy"
|
||||
],
|
||||
"tags": [
|
||||
"Thriller & Suspense",
|
||||
"Fantasy",
|
||||
"Action & Adventure"
|
||||
],
|
||||
"series": null,
|
||||
"language": "French",
|
||||
"duration": 614,
|
||||
"region": "us",
|
||||
"rating": "4.8",
|
||||
"abridged": false,
|
||||
"descriptionPlain": "Premier récit publié par J.R.R. Tolkien, en 1937, cette histoire, inventée par l’auteur pour ses propres enfants, racont..."
|
||||
},
|
||||
{
|
||||
"title": "The Hobbit",
|
||||
"subtitle": null,
|
||||
"author": "J. R. R. Tolkien",
|
||||
"narrator": "Martin Shaw",
|
||||
"publisher": "HarperCollins",
|
||||
"publishedYear": "2005",
|
||||
"description": "<p>Bilbo Baggins is a hobbit who enjoys a comfortable and quiet life. His contentment is disturbed one day when the wiza...",
|
||||
"cover": "https://m.media-amazon.com/images/I/61giqd1Hw2L.jpg",
|
||||
"asin": "B0036GMKSK",
|
||||
"isbn": "9780007227761",
|
||||
"genres": [
|
||||
"Literature & Fiction",
|
||||
"Science Fiction & Fantasy"
|
||||
],
|
||||
"tags": [
|
||||
"Historical Fiction",
|
||||
"Fantasy",
|
||||
"Action & Adventure",
|
||||
"Epic"
|
||||
],
|
||||
"series": null,
|
||||
"language": "English",
|
||||
"duration": 357,
|
||||
"region": "us",
|
||||
"rating": "4.6",
|
||||
"abridged": true,
|
||||
"descriptionPlain": "Bilbo Baggins is a hobbit who enjoys a comfortable and quiet life. His contentment is disturbed one day when the wizard,..."
|
||||
},
|
||||
{
|
||||
"title": "Der Hobbit",
|
||||
"subtitle": "Der Herr der Ringe 0.5",
|
||||
"author": "J. R. R. Tolkien",
|
||||
"narrator": "Gert Heidenreich",
|
||||
"publisher": "Der Hörverlag",
|
||||
"publishedYear": "2010",
|
||||
"description": "Bilbo Beutlin, der kleine Hobbit, macht sich auf den Weg zum Einsamen Berg, um den rechtmäßigen Schatz der Zwerge zurück...",
|
||||
"cover": "https://m.media-amazon.com/images/I/91m09wFq9PL.jpg",
|
||||
"asin": "B00TJF0K5W",
|
||||
"isbn": "9783844507157",
|
||||
"genres": [
|
||||
"Literature & Fiction",
|
||||
"Science Fiction & Fantasy"
|
||||
],
|
||||
"tags": [
|
||||
"Genre Fiction",
|
||||
"Movie, TV & Video Game Tie-Ins",
|
||||
"Fantasy",
|
||||
"Action & Adventure",
|
||||
"Dragons & Mythical Creatures"
|
||||
],
|
||||
"series": null,
|
||||
"language": "German",
|
||||
"duration": 653,
|
||||
"region": "us",
|
||||
"rating": "4.8",
|
||||
"abridged": false,
|
||||
"descriptionPlain": "Bilbo Beutlin, der kleine Hobbit, macht sich auf den Weg zum Einsamen Berg, um den rechtmäßigen Schatz der Zwerge zurück..."
|
||||
},
|
||||
{
|
||||
"title": "El Hobbit",
|
||||
"subtitle": null,
|
||||
"author": "J. R. R. Tolkien",
|
||||
"narrator": "Javier Gutiérrez",
|
||||
"publisher": "Audible Studios y Planeta Audio",
|
||||
"publishedYear": "2023",
|
||||
"description": "<p>La extraordinaria precuela de El Señor de los Anillos.</p> <p>Smaug parecía profundamente dormido cuando Bilbo espió ...",
|
||||
"cover": "https://m.media-amazon.com/images/I/91snBF2IakL.jpg",
|
||||
"asin": "B0C8Z11P9T",
|
||||
"isbn": "9788445016282",
|
||||
"genres": [
|
||||
"Science Fiction & Fantasy"
|
||||
],
|
||||
"tags": [
|
||||
"Fantasy"
|
||||
],
|
||||
"series": [
|
||||
{
|
||||
"series": "El Señor de los Anillos",
|
||||
"sequence": "0.5"
|
||||
}
|
||||
],
|
||||
"language": "Spanish",
|
||||
"duration": 640,
|
||||
"region": "us",
|
||||
"rating": "4.8",
|
||||
"abridged": false,
|
||||
"descriptionPlain": "La extraordinaria precuela de El Señor de los Anillos. Smaug parecía profundamente dormido cuando Bilbo espió una vez má..."
|
||||
},
|
||||
{
|
||||
"title": "A Hobbit",
|
||||
"subtitle": null,
|
||||
"author": "J. R. R. Tolkien",
|
||||
"narrator": "Kaszás Attila",
|
||||
"publisher": "Mojzer Publishing House",
|
||||
"publishedYear": "2019",
|
||||
"description": "<p>A Hobbit, mint Tolkien sok más írása, gyermekeinek szóló történetként indult. Először 1937-ben jelent meg és ma méltá...",
|
||||
"cover": "https://m.media-amazon.com/images/I/91t3yGvAcNL.jpg",
|
||||
"asin": "9630999633",
|
||||
"isbn": "9789630999632",
|
||||
"genres": [
|
||||
"Science Fiction & Fantasy"
|
||||
],
|
||||
"tags": [
|
||||
"Fantasy",
|
||||
"Epic"
|
||||
],
|
||||
"series": null,
|
||||
"language": "Hungarian",
|
||||
"duration": 742,
|
||||
"region": "us",
|
||||
"rating": "4.8",
|
||||
"abridged": false,
|
||||
"descriptionPlain": "A Hobbit, mint Tolkien sok más írása, gyermekeinek szóló történetként indult. Először 1937-ben jelent meg és ma méltán v..."
|
||||
},
|
||||
{
|
||||
"title": "The Hobbit (Dramatised)",
|
||||
"subtitle": "The Classic BBC Radio Production",
|
||||
"author": "J.R.R. Tolkien",
|
||||
"narrator": "Heron Carvic, Paul Daneman, Anthony Jackson, Francis de Wolff, John Justin, John Pullen, Full cast",
|
||||
"publisher": "BBC Digital Audio",
|
||||
"publishedYear": "2007",
|
||||
"description": "Dwarves, elves, goblins, trolls, dragons and wizards - these are the ingredients of J.R.R. Tolkien's wonderful fantasy, ...",
|
||||
"cover": "https://m.media-amazon.com/images/I/81wq-zTbNNL.jpg",
|
||||
"asin": "B002VA91WK",
|
||||
"isbn": "9781405629423",
|
||||
"genres": [
|
||||
"Children's Audiobooks",
|
||||
"Science Fiction & Fantasy"
|
||||
],
|
||||
"tags": [
|
||||
"Science Fiction & Fantasy",
|
||||
"Fantasy & Magic",
|
||||
"Fantasy",
|
||||
"Science Fiction"
|
||||
],
|
||||
"series": null,
|
||||
"language": "English",
|
||||
"duration": 222,
|
||||
"region": "us",
|
||||
"rating": "4.0",
|
||||
"abridged": false,
|
||||
"descriptionPlain": "Dwarves, elves, goblins, trolls, dragons and wizards - these are the ingredients of J.R.R. Tolkien's wonderful fantasy, ..."
|
||||
},
|
||||
{
|
||||
"title": "The Hobbit",
|
||||
"subtitle": "The BBC TV soundtrack of the Jackanory multi-voice reading",
|
||||
"author": "J. R. R. Tolkien",
|
||||
"narrator": "Bernard Cribbins, Maurice Denham, Jan Francis, David Wood",
|
||||
"publisher": "BBC Digital Audio",
|
||||
"publishedYear": "2013",
|
||||
"description": "<p>The BBC TV soundtrack of the acclaimed Jackanory multi-voice reading of <i>The Hobbit</i>. Broadcast to mark the 3000...",
|
||||
"cover": "https://m.media-amazon.com/images/I/91QjFToijwL.jpg",
|
||||
"asin": "B00FH73ZA8",
|
||||
"isbn": "9781471358388",
|
||||
"genres": [
|
||||
"Arts & Entertainment",
|
||||
"Science Fiction & Fantasy"
|
||||
],
|
||||
"tags": [
|
||||
"Entertainment & Performing Arts",
|
||||
"Radio",
|
||||
"Fantasy"
|
||||
],
|
||||
"series": null,
|
||||
"language": "English",
|
||||
"duration": 147,
|
||||
"region": "us",
|
||||
"rating": "4.4",
|
||||
"abridged": true,
|
||||
"descriptionPlain": "The BBC TV soundtrack of the acclaimed Jackanory multi-voice reading of The Hobbit. Broadcast to mark the 3000th program..."
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,39 @@
|
||||
[
|
||||
{
|
||||
"title": "The Mummy or Ramses the Damned",
|
||||
"subtitle": "A Novel",
|
||||
"author": "Anne Rice",
|
||||
"narrator": "Michael York",
|
||||
"publisher": "Random House Audio",
|
||||
"publishedYear": "2000",
|
||||
"description": "He was Ramses the Damned in ancient Egypt, but awoke in opulent Edwardian London as Dr. Ramsey, expert in Egyptology. He...",
|
||||
"cover": "https://m.media-amazon.com/images/I/9194bYyVy9L.jpg",
|
||||
"asin": "B002UUKMQA",
|
||||
"isbn": "9780375418259",
|
||||
"genres": [
|
||||
"Literature & Fiction",
|
||||
"Science Fiction & Fantasy"
|
||||
],
|
||||
"tags": [
|
||||
"Genre Fiction",
|
||||
"Psychological",
|
||||
"Sagas",
|
||||
"Horror",
|
||||
"Fantasy",
|
||||
"Paranormal & Urban",
|
||||
"Paranormal"
|
||||
],
|
||||
"series": [
|
||||
{
|
||||
"series": "Ramses the Damned (abridged)",
|
||||
"sequence": "1"
|
||||
}
|
||||
],
|
||||
"language": "English",
|
||||
"duration": 177,
|
||||
"region": "us",
|
||||
"rating": "3.9",
|
||||
"abridged": true,
|
||||
"descriptionPlain": "He was Ramses the Damned in ancient Egypt, but awoke in opulent Edwardian London as Dr. Ramsey, expert in Egyptology. He..."
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,432 @@
|
||||
"""Tests for the audiobook existence check (does Audible sell this audiobook at all?).
|
||||
|
||||
The store answers are real ``/api/search/books`` responses from Audiobookshelf, recorded
|
||||
in ``fixtures/audible_search`` (descriptions trimmed): a book the US store sells, a book
|
||||
neither store sells, the canary on both stores, and an alternative-title listing.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
from shelfmark.core import auto_download, existence_check
|
||||
from shelfmark.core.existence_match import find_match, search_title, titles_match
|
||||
from shelfmark.core.requests_service import reject_request
|
||||
from shelfmark.core.user_db import UserDB
|
||||
from tests.core.fakes import FakeConfig
|
||||
|
||||
FIXTURES = Path(__file__).parent / "fixtures" / "audible_search"
|
||||
NOW = datetime(2026, 10, 11, 18, 0, tzinfo=UTC)
|
||||
|
||||
|
||||
def _recorded(name: str) -> list[dict]:
|
||||
return json.loads((FIXTURES / f"{name}.json").read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
# (query sent, provider) -> recorded answer. Anything else is an empty answer, which is
|
||||
# also what Audiobookshelf gives for a title the store does not know.
|
||||
RECORDED = {
|
||||
("The Advocate's Dilemma", "audible"): "us_advocates_dilemma",
|
||||
("Young Zaphod Plays It Safe", "audible"): "us_young_zaphod",
|
||||
("Young Zaphod Plays It Safe", "audible.uk"): "uk_young_zaphod",
|
||||
("The Hobbit", "audible"): "us_hobbit",
|
||||
("The Hobbit", "audible.uk"): "uk_hobbit",
|
||||
("The Mummy", "audible"): "us_the_mummy",
|
||||
}
|
||||
|
||||
|
||||
class FakeStore:
|
||||
"""Stands in for ``audiobookshelf.search_books``, answering from the recordings."""
|
||||
|
||||
def __init__(self, *, fail_on: str | None = None, canary_lost: bool = False) -> None:
|
||||
self.calls: list[tuple[str, str, str]] = []
|
||||
self.fail_on = fail_on
|
||||
self.canary_lost = canary_lost
|
||||
|
||||
def __call__(self, title, author, provider, *, timeout=None, overrides=None):
|
||||
self.calls.append((title, author, provider))
|
||||
if self.fail_on == provider:
|
||||
raise requests.ConnectionError("Audiobookshelf did not answer")
|
||||
if self.canary_lost and title == existence_check.CANARY[0]:
|
||||
return []
|
||||
name = RECORDED.get((title, provider))
|
||||
return _recorded(name) if name else []
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def store(monkeypatch):
|
||||
fake = FakeStore()
|
||||
monkeypatch.setattr(existence_check.audiobookshelf, "search_books", fake)
|
||||
return fake
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def settings(monkeypatch):
|
||||
fake = FakeConfig(
|
||||
AUTO_DOWNLOAD_EXISTENCE_CHECK_ENABLED=True,
|
||||
AUTO_DOWNLOAD_EXISTENCE_CHECK_AFTER_PASSES=3,
|
||||
)
|
||||
monkeypatch.setattr(existence_check, "app_config", fake)
|
||||
return fake
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user_db(tmp_path):
|
||||
db = UserDB(str(tmp_path / "users.db"))
|
||||
db.initialize()
|
||||
return db
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def admin(user_db):
|
||||
return user_db.create_user(username="admin", role="admin")
|
||||
|
||||
|
||||
def _request(user_db, admin, title, author, content_type="audiobook"):
|
||||
return user_db.create_request(
|
||||
user_id=admin["id"],
|
||||
content_type=content_type,
|
||||
request_level="book",
|
||||
policy_mode="request_book",
|
||||
book_data={
|
||||
"title": title,
|
||||
"author": author,
|
||||
"provider": "hardcover",
|
||||
"provider_id": "1",
|
||||
"content_type": content_type,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def _pass(user_db, admin, request, status="no_match", *, now=NOW, content_type="audiobook"):
|
||||
row = user_db.get_request(int(request["id"]))
|
||||
outcome = auto_download.AutoDownloadOutcome(int(request["id"]), status)
|
||||
return existence_check.after_request(
|
||||
user_db,
|
||||
row,
|
||||
outcome,
|
||||
admin_user_id=admin["id"],
|
||||
content_type=content_type,
|
||||
now=now,
|
||||
)
|
||||
|
||||
|
||||
def _state(user_db, request):
|
||||
book_data = user_db.get_request(int(request["id"]))["book_data"]
|
||||
return book_data.get(existence_check.BOOK_DATA_KEY)
|
||||
|
||||
|
||||
class TestMatching:
|
||||
@pytest.mark.parametrize(
|
||||
("raw", "author", "expected"),
|
||||
[
|
||||
("The Frood: The Authorised and Very Official History", "Jem Roberts", "The Frood"),
|
||||
("The Hobbit, or There and Back Again", "Tolkien", "The Hobbit"),
|
||||
("Running Blind aka The Visitor", "Lee Child", "Running Blind"),
|
||||
("Born a Crime- Stories from a South African Childhood", "", "Born a Crime"),
|
||||
("The Armour of Light (Unabridged)", "", "The Armour of Light"),
|
||||
("[Pillars of the Earth 02] - World Without End", "", "World Without End"),
|
||||
("Robert Langdon, Book 4 - Inferno", "Dan Brown", "Inferno"),
|
||||
(
|
||||
"Anne Rice - Mayfair Witches 01 - The Witching Hour",
|
||||
"Anne Rice",
|
||||
"The Witching Hour",
|
||||
),
|
||||
(
|
||||
"HGTTG [01] The Hitchhiker's Guide to the Galaxy",
|
||||
"",
|
||||
"The Hitchhiker's Guide to the Galaxy",
|
||||
),
|
||||
("And Another Thing... (Unabridged)", "", "And Another Thing"),
|
||||
("Fahrenheit 451 - A Novel", "", "Fahrenheit 451"),
|
||||
("Catch-22", "", "Catch-22"),
|
||||
],
|
||||
)
|
||||
def test_search_title(self, raw, author, expected):
|
||||
assert search_title(raw, author) == expected
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("wanted", "candidate"),
|
||||
[
|
||||
("The Book of Lost Tales, Part II", "The Book of Lost Tales, Part Two"),
|
||||
("The Book of Lost Tales, Part II", "The Book of Lost Tales: Part 2"),
|
||||
("The Fall of Númenor", "The Fall of Numenor"),
|
||||
("Morgoth’s Ring", "Morgoth's Ring"),
|
||||
("Merry Christmas", "Merry Christmas, Alex Cross"),
|
||||
("Start With Why", "Start with Why 15th Anniversary Edition"),
|
||||
("The Reign of Osiris", "Ramses the Damned: The Reign of Osiris"),
|
||||
("The Mummy, or Ramses the Damned", "The Mummy or Ramses the Damned"),
|
||||
("The Armour of Light", "The Armor of Light"),
|
||||
],
|
||||
)
|
||||
def test_same_book(self, wanted, candidate):
|
||||
assert titles_match(wanted, candidate)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("wanted", "candidate"),
|
||||
[
|
||||
("Cross", "Cross Fire"), # one word never matches a longer title
|
||||
("The Lays of Beleriand", "The Lost Road"),
|
||||
("Sauron Defeated", "Sauron"),
|
||||
],
|
||||
)
|
||||
def test_different_book(self, wanted, candidate):
|
||||
assert not titles_match(wanted, candidate)
|
||||
|
||||
def test_author_is_any_surname_in_the_field(self):
|
||||
results = [{"title": "The Martian", "author": "Andy Weir", "asin": "B082BHJMFF"}]
|
||||
assert find_match("The Martian", "R.C. Bray, Andy Weir", results) is not None
|
||||
assert find_match("The Martian", "Kristin Hannah/Polly Stone", results) is None
|
||||
|
||||
def test_result_without_asin_is_skipped(self):
|
||||
results = [{"title": "Blood Canticle", "author": "Anne Rice", "asin": ""}]
|
||||
assert find_match("Blood Canticle", "Anne Rice", results) is None
|
||||
|
||||
|
||||
class TestLookUp:
|
||||
def test_found_on_the_us_store(self, store):
|
||||
result = existence_check.look_up("The Advocate's Dilemma", "Teresa Burrell")
|
||||
|
||||
assert result.status == "found"
|
||||
assert result.store == "US"
|
||||
assert result.match.asin == "B00K23YZJM"
|
||||
assert [call[2] for call in store.calls] == ["audible"]
|
||||
|
||||
def test_found_under_its_alternative_title(self, store):
|
||||
result = existence_check.look_up("The Mummy, or Ramses the Damned", "Anne Rice")
|
||||
|
||||
assert result.status == "found"
|
||||
assert result.match.asin == "B002UUKMQA"
|
||||
|
||||
def test_not_found_on_either_store(self, store):
|
||||
result = existence_check.look_up("Young Zaphod Plays It Safe", "Douglas Adams")
|
||||
|
||||
assert result.status == "not_found"
|
||||
asked = [(title, provider) for title, _author, provider in store.calls]
|
||||
assert asked == [
|
||||
("Young Zaphod Plays It Safe", "audible"),
|
||||
("Young Zaphod Plays It Safe", "audible.uk"),
|
||||
("The Hobbit", "audible"),
|
||||
("The Hobbit", "audible.uk"),
|
||||
]
|
||||
|
||||
def test_store_that_lost_the_canary_too_decides_nothing(self, monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
existence_check.audiobookshelf, "search_books", FakeStore(canary_lost=True)
|
||||
)
|
||||
|
||||
result = existence_check.look_up("Young Zaphod Plays It Safe", "Douglas Adams")
|
||||
|
||||
assert result.status == "unknown"
|
||||
|
||||
@pytest.mark.parametrize("failing", ["audible", "audible.uk"])
|
||||
def test_error_is_unknown_not_missing(self, monkeypatch, failing):
|
||||
monkeypatch.setattr(
|
||||
existence_check.audiobookshelf, "search_books", FakeStore(fail_on=failing)
|
||||
)
|
||||
|
||||
result = existence_check.look_up("Young Zaphod Plays It Safe", "Douglas Adams")
|
||||
|
||||
assert result.status == "unknown"
|
||||
assert "did not answer" in result.detail
|
||||
|
||||
def test_us_store_is_asked_in_us_spelling(self, store):
|
||||
existence_check.look_up("The Armour of Light", "Ken Follett")
|
||||
|
||||
asked = [(title, provider) for title, _author, provider in store.calls[:2]]
|
||||
assert asked == [("The Armor of Light", "audible"), ("The Armour of Light", "audible.uk")]
|
||||
|
||||
def test_no_budget_left_asks_nothing(self, store):
|
||||
result = existence_check.look_up(
|
||||
"Young Zaphod Plays It Safe", "Douglas Adams", budget_seconds=1
|
||||
)
|
||||
|
||||
assert result.status == "unknown"
|
||||
assert store.calls == []
|
||||
|
||||
|
||||
class TestAfterRequest:
|
||||
def test_setting_off_counts_nothing(self, user_db, admin, store, settings):
|
||||
settings.values["AUTO_DOWNLOAD_EXISTENCE_CHECK_ENABLED"] = False
|
||||
request = _request(user_db, admin, "Young Zaphod Plays It Safe", "Douglas Adams")
|
||||
|
||||
for _ in range(5):
|
||||
assert _pass(user_db, admin, request) is None
|
||||
|
||||
assert _state(user_db, request) is None
|
||||
assert user_db.get_request(int(request["id"]))["status"] == "pending"
|
||||
assert store.calls == []
|
||||
|
||||
def test_ebook_requests_are_not_checked(self, user_db, admin, store, settings):
|
||||
request = _request(user_db, admin, "Young Zaphod Plays It Safe", "Douglas Adams", "ebook")
|
||||
|
||||
for _ in range(5):
|
||||
assert _pass(user_db, admin, request, content_type="ebook") is None
|
||||
|
||||
assert _state(user_db, request) is None
|
||||
assert store.calls == []
|
||||
|
||||
def test_not_listed_is_marked_not_declined(self, user_db, admin, store, settings):
|
||||
request = _request(user_db, admin, "Young Zaphod Plays It Safe", "Douglas Adams")
|
||||
|
||||
assert _pass(user_db, admin, request) == "counted"
|
||||
assert _pass(user_db, admin, request) == "counted"
|
||||
assert store.calls == []
|
||||
assert _pass(user_db, admin, request) == "not_listed"
|
||||
|
||||
row = user_db.get_request(int(request["id"]))
|
||||
assert row["status"] == "pending"
|
||||
assert row["last_failure_reason"] == (
|
||||
"Not found on Audible (US/UK) after 3 searches, 2026-10-11"
|
||||
)
|
||||
assert row["reviewed_by"] is None
|
||||
assert _state(user_db, request)["result"] == "not_found"
|
||||
# Not asked again inside the week.
|
||||
assert _pass(user_db, admin, request) == "waiting"
|
||||
|
||||
def test_listed_stays_pending_and_says_why(self, user_db, admin, store, settings):
|
||||
settings.values["AUTO_DOWNLOAD_EXISTENCE_CHECK_AFTER_PASSES"] = 1
|
||||
request = _request(user_db, admin, "The Advocate's Dilemma", "Teresa Burrell")
|
||||
|
||||
assert _pass(user_db, admin, request) == "listed"
|
||||
|
||||
row = user_db.get_request(int(request["id"]))
|
||||
assert row["status"] == "pending"
|
||||
assert row["last_failure_reason"] == (
|
||||
"Exists on Audible (B00K23YZJM), not on our sources yet"
|
||||
)
|
||||
state = _state(user_db, request)
|
||||
assert state["result"] == "found"
|
||||
assert state["asin"] == "B00K23YZJM"
|
||||
|
||||
def test_listed_book_is_asked_again_after_a_week(self, user_db, admin, store, settings):
|
||||
settings.values["AUTO_DOWNLOAD_EXISTENCE_CHECK_AFTER_PASSES"] = 1
|
||||
request = _request(user_db, admin, "The Advocate's Dilemma", "Teresa Burrell")
|
||||
assert _pass(user_db, admin, request) == "listed"
|
||||
asked = len(store.calls)
|
||||
|
||||
assert _pass(user_db, admin, request, now=NOW + timedelta(days=1)) == "waiting"
|
||||
assert _pass(user_db, admin, request, now=NOW + timedelta(days=6)) == "waiting"
|
||||
assert len(store.calls) == asked
|
||||
|
||||
assert _pass(user_db, admin, request, now=NOW + timedelta(days=7)) == "listed"
|
||||
assert len(store.calls) == asked + 1
|
||||
assert _state(user_db, request)["checked_at"] == (NOW + timedelta(days=7)).isoformat(
|
||||
timespec="seconds"
|
||||
)
|
||||
|
||||
def test_lookup_error_changes_nothing_and_asks_again_next_pass(
|
||||
self, user_db, admin, settings, monkeypatch
|
||||
):
|
||||
settings.values["AUTO_DOWNLOAD_EXISTENCE_CHECK_AFTER_PASSES"] = 1
|
||||
failing = FakeStore(fail_on="audible")
|
||||
monkeypatch.setattr(existence_check.audiobookshelf, "search_books", failing)
|
||||
request = _request(user_db, admin, "Young Zaphod Plays It Safe", "Douglas Adams")
|
||||
|
||||
assert _pass(user_db, admin, request) == "unknown"
|
||||
assert _pass(user_db, admin, request) == "unknown"
|
||||
|
||||
row = user_db.get_request(int(request["id"]))
|
||||
assert row["status"] == "pending"
|
||||
assert row["last_failure_reason"] is None
|
||||
assert len(failing.calls) == 2
|
||||
|
||||
def test_a_match_resets_the_count(self, user_db, admin, store, settings):
|
||||
request = _request(user_db, admin, "Young Zaphod Plays It Safe", "Douglas Adams")
|
||||
_pass(user_db, admin, request)
|
||||
_pass(user_db, admin, request)
|
||||
assert _state(user_db, request)["no_match_passes"] == 2
|
||||
|
||||
assert _pass(user_db, admin, request, status="queued") is None
|
||||
|
||||
assert _state(user_db, request) is None
|
||||
|
||||
def test_a_search_error_neither_counts_nor_resets(self, user_db, admin, store, settings):
|
||||
request = _request(user_db, admin, "Young Zaphod Plays It Safe", "Douglas Adams")
|
||||
_pass(user_db, admin, request)
|
||||
|
||||
assert _pass(user_db, admin, request, status="error") is None
|
||||
|
||||
assert _state(user_db, request)["no_match_passes"] == 1
|
||||
|
||||
def test_any_rejection_drops_the_count_so_a_reopen_starts_over(
|
||||
self, user_db, admin, store, settings
|
||||
):
|
||||
request = _request(user_db, admin, "Young Zaphod Plays It Safe", "Douglas Adams")
|
||||
_pass(user_db, admin, request)
|
||||
_pass(user_db, admin, request)
|
||||
|
||||
reject_request(user_db, request_id=int(request["id"]), admin_user_id=admin["id"])
|
||||
assert _state(user_db, request) is None
|
||||
|
||||
# What the admin reopen does to the row: back to pending, review undone.
|
||||
conn = user_db._connect()
|
||||
try:
|
||||
conn.execute(
|
||||
"UPDATE download_requests SET status = 'pending', reviewed_by = NULL, "
|
||||
"reviewed_at = NULL WHERE id = ?",
|
||||
(int(request["id"]),),
|
||||
)
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
assert _pass(user_db, admin, request) == "counted"
|
||||
assert _state(user_db, request)["no_match_passes"] == 1
|
||||
|
||||
def test_pass_works_from_the_stored_row_not_the_stale_one(
|
||||
self, user_db, admin, store, settings
|
||||
):
|
||||
request = _request(user_db, admin, "Young Zaphod Plays It Safe", "Douglas Adams")
|
||||
stale = user_db.get_request(int(request["id"]))
|
||||
# The pass recorded a failed release after the row was read.
|
||||
book_data = dict(stale["book_data"], failed_releases=[{"source": "s", "source_id": "1"}])
|
||||
user_db.update_request(int(request["id"]), book_data=book_data)
|
||||
|
||||
existence_check.after_request(
|
||||
user_db,
|
||||
stale,
|
||||
auto_download.AutoDownloadOutcome(int(request["id"]), "no_match"),
|
||||
admin_user_id=admin["id"],
|
||||
content_type="audiobook",
|
||||
now=NOW,
|
||||
)
|
||||
|
||||
stored = user_db.get_request(int(request["id"]))["book_data"]
|
||||
assert stored["failed_releases"] == [{"source": "s", "source_id": "1"}]
|
||||
assert stored[existence_check.BOOK_DATA_KEY]["no_match_passes"] == 1
|
||||
|
||||
|
||||
def test_the_pass_runs_the_check_and_counts_not_listed(user_db, admin, store, monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
auto_download,
|
||||
"app_config",
|
||||
FakeConfig(AUTO_DOWNLOAD_ENABLED=True),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
existence_check,
|
||||
"app_config",
|
||||
FakeConfig(
|
||||
AUTO_DOWNLOAD_EXISTENCE_CHECK_ENABLED=True,
|
||||
AUTO_DOWNLOAD_EXISTENCE_CHECK_AFTER_PASSES=1,
|
||||
),
|
||||
)
|
||||
monkeypatch.setattr(auto_download, "_configured_source_priority", lambda _t: ["src"])
|
||||
monkeypatch.setattr(
|
||||
auto_download,
|
||||
"auto_download_request",
|
||||
lambda _db, row, **_kw: auto_download.AutoDownloadOutcome(int(row["id"]), "no_match"),
|
||||
)
|
||||
request = _request(user_db, admin, "Young Zaphod Plays It Safe", "Douglas Adams")
|
||||
|
||||
summary = auto_download.auto_download_pending(
|
||||
user_db, queue_release=lambda *_a, **_kw: (True, None), admin_user_id=admin["id"]
|
||||
)
|
||||
|
||||
assert summary["no_match"] == 1
|
||||
assert summary["not_listed"] == 1
|
||||
assert user_db.get_request(int(request["id"]))["status"] == "pending"
|
||||
@@ -167,3 +167,79 @@ class TestTriggerAsync:
|
||||
assert scheduler.trigger_async(force=force) is True
|
||||
assert finished.wait(timeout=5)
|
||||
assert seen == [{"force": force}]
|
||||
|
||||
|
||||
class _Clock:
|
||||
"""A clock the scheduler's sleeps move, so a wait that is hours long runs instantly."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.now = 0.0
|
||||
self.sleeps: list[float] = []
|
||||
|
||||
def sleep(self, seconds: float) -> None:
|
||||
self.sleeps.append(seconds)
|
||||
self.now += seconds
|
||||
|
||||
def monotonic(self) -> float:
|
||||
return self.now
|
||||
|
||||
|
||||
def _run_wait(monkeypatch, *, interval, quick, retries):
|
||||
clock = _Clock()
|
||||
monkeypatch.setattr(scheduler.time, "sleep", clock.sleep)
|
||||
monkeypatch.setattr(scheduler.time, "monotonic", clock.monotonic)
|
||||
monkeypatch.setattr(scheduler, "_interval_seconds", lambda: interval)
|
||||
monkeypatch.setattr(scheduler, "_quick_retry_interval_seconds", lambda: quick)
|
||||
monkeypatch.setattr(scheduler, "run_quick_retry", lambda: retries.append(clock.now))
|
||||
scheduler._wait_for_next_cycle()
|
||||
return clock
|
||||
|
||||
|
||||
def test_the_wait_between_cycles_is_one_sleep_when_the_quick_retry_is_off(monkeypatch):
|
||||
retries: list[float] = []
|
||||
|
||||
clock = _run_wait(monkeypatch, interval=3600.0, quick=0.0, retries=retries)
|
||||
|
||||
assert clock.sleeps == [3600.0]
|
||||
assert retries == []
|
||||
|
||||
|
||||
def test_failed_downloads_are_looked_at_between_cycles_when_it_is_on(monkeypatch):
|
||||
retries: list[float] = []
|
||||
|
||||
clock = _run_wait(monkeypatch, interval=3600.0, quick=900.0, retries=retries)
|
||||
|
||||
assert clock.now == 3600.0
|
||||
assert retries == [900.0, 1800.0, 2700.0] # not again at the cycle itself
|
||||
|
||||
|
||||
def test_a_failing_quick_retry_does_not_stop_the_wait(monkeypatch):
|
||||
clock = _Clock()
|
||||
monkeypatch.setattr(scheduler.time, "sleep", clock.sleep)
|
||||
monkeypatch.setattr(scheduler.time, "monotonic", clock.monotonic)
|
||||
monkeypatch.setattr(scheduler, "_interval_seconds", lambda: 3600.0)
|
||||
monkeypatch.setattr(scheduler, "_quick_retry_interval_seconds", lambda: 1800.0)
|
||||
|
||||
def boom():
|
||||
raise RuntimeError("search down")
|
||||
|
||||
monkeypatch.setattr(scheduler, "run_quick_retry", boom)
|
||||
|
||||
scheduler._wait_for_next_cycle()
|
||||
|
||||
assert clock.now == 3600.0
|
||||
|
||||
|
||||
def test_the_quick_retry_interval(monkeypatch):
|
||||
monkeypatch.setattr(scheduler, "app_config", _Config(AUTO_DOWNLOAD_FAILURE_RETRY_MINUTES=20))
|
||||
assert scheduler._quick_retry_interval_seconds() == 1200.0
|
||||
monkeypatch.setattr(scheduler, "app_config", _Config())
|
||||
assert scheduler._quick_retry_interval_seconds() == 0.0
|
||||
|
||||
|
||||
def test_the_quick_retry_skips_while_a_cycle_holds_the_lock():
|
||||
scheduler._run_lock.acquire()
|
||||
try:
|
||||
assert scheduler.run_quick_retry() is None
|
||||
finally:
|
||||
scheduler._run_lock.release()
|
||||
@@ -159,6 +159,88 @@ def test_a_plain_shelf_title_is_unchanged_by_the_series_handling() -> None:
|
||||
assert library_index.match_entries(_searching("Kiss the Girls"), [entry]) == "owned"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"shelf_title",
|
||||
[
|
||||
"Dungeon Crawler Carl (Full Cast Edition)",
|
||||
"Dungeon Crawler Carl (Audio Immersion Tunnel)",
|
||||
"Dungeon Crawler Carl (GraphicAudio)",
|
||||
"Dungeon Crawler Carl [Dramatized Adaptation]",
|
||||
"Dungeon Crawler Carl (Part 1 of 3) (Dramatized Adaptation)",
|
||||
],
|
||||
)
|
||||
def test_an_alternate_edition_on_the_shelf_is_not_the_book(shelf_title: str) -> None:
|
||||
# A full-cast or dramatized recording shares the title and author of the
|
||||
# single-narrator original, but owning one is not owning the other. The bracketed
|
||||
# words stay in the title set, where the matcher reads them as naming another
|
||||
# edition.
|
||||
entry = audiobookshelf._item_to_entry(_item(shelf_title, "Matt Dinniman"))
|
||||
|
||||
assert (
|
||||
library_index.match_entries(_searching("Dungeon Crawler Carl", "Matt Dinniman"), [entry])
|
||||
is None
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("shelf_title", "searching"),
|
||||
[
|
||||
("Dungeon Crawler Carl (Unabridged)", "Dungeon Crawler Carl"),
|
||||
("Dungeon Crawler Carl (Abridged)", "Dungeon Crawler Carl"),
|
||||
("Dungeon Crawler Carl (Illustrated Edition)", "Dungeon Crawler Carl"),
|
||||
("Dungeon Crawler Carl (Full Cast Edition)", "Dungeon Crawler Carl (Full Cast Edition)"),
|
||||
],
|
||||
)
|
||||
def test_a_printing_word_or_the_same_edition_marker_is_still_the_book(
|
||||
shelf_title: str, searching: str
|
||||
) -> None:
|
||||
# "(Unabridged)" is shelf noise, not an edition; and the edition asked for by its
|
||||
# own name is the one on the shelf.
|
||||
entry = audiobookshelf._item_to_entry(_item(shelf_title, "Matt Dinniman"))
|
||||
|
||||
assert library_index.match_entries(_searching(searching, "Matt Dinniman"), [entry]) == "owned"
|
||||
|
||||
|
||||
def test_a_marker_on_the_searched_title_alone_is_not_on_the_shelf() -> None:
|
||||
entry = audiobookshelf._item_to_entry(_item("Dungeon Crawler Carl", "Matt Dinniman"))
|
||||
|
||||
assert (
|
||||
library_index.match_entries(
|
||||
_searching("Dungeon Crawler Carl (GraphicAudio)", "Matt Dinniman"), [entry]
|
||||
)
|
||||
is None
|
||||
)
|
||||
|
||||
|
||||
class _Response:
|
||||
def __init__(self, payload: dict[str, Any]) -> None:
|
||||
self.payload = payload
|
||||
|
||||
def raise_for_status(self) -> None:
|
||||
return None
|
||||
|
||||
def json(self) -> dict[str, Any]:
|
||||
return self.payload
|
||||
|
||||
|
||||
class _Session:
|
||||
def __init__(self, libraries: list[dict[str, Any]], pages: dict[int, dict[str, Any]]) -> None:
|
||||
self.libraries = libraries
|
||||
self.pages = pages
|
||||
self.calls: list[tuple[str, dict[str, Any]]] = []
|
||||
|
||||
def get(self, url: str, params: dict[str, Any] | None = None, timeout: int = 0) -> _Response:
|
||||
self.calls.append((url, dict(params or {})))
|
||||
if url.endswith("/api/libraries"):
|
||||
return _Response({"libraries": self.libraries})
|
||||
return _Response(self.pages[int(self.calls[-1][1]["page"])])
|
||||
|
||||
|
||||
def _install(monkeypatch: pytest.MonkeyPatch, session: _Session) -> None:
|
||||
monkeypatch.setattr(audiobookshelf, "_session", lambda url, token: session)
|
||||
monkeypatch.setattr(audiobookshelf, "_ITEMS_PAGE_LIMIT", 2)
|
||||
|
||||
|
||||
def test_fetch_pages_through_book_libraries(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
session = _Session(
|
||||
libraries=[{"id": "books", "mediaType": "book"}, {"id": "pods", "mediaType": "podcast"}],
|
||||
|
||||
@@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
import os
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -13,6 +13,9 @@ from shelfmark.core import library_index
|
||||
from shelfmark.core.library_providers import calibre
|
||||
from shelfmark.metadata_providers import BookMetadata
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Callable
|
||||
|
||||
_SCHEMA = """
|
||||
CREATE TABLE books (id INTEGER PRIMARY KEY, title TEXT NOT NULL, uuid TEXT);
|
||||
CREATE TABLE authors (id INTEGER PRIMARY KEY, name TEXT NOT NULL);
|
||||
@@ -74,6 +77,19 @@ def _configure(monkeypatch: pytest.MonkeyPatch, path: Path, *, enabled: bool = T
|
||||
monkeypatch.setattr(library_index, "_cache", {})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def calibre_library(monkeypatch: pytest.MonkeyPatch) -> Callable[..., Path]:
|
||||
"""Point the provider at a library, building it first unless ``create=False``."""
|
||||
|
||||
def make(*, path: Path, create: bool = True, enabled: bool = True) -> Path:
|
||||
if create:
|
||||
_make_library(path)
|
||||
_configure(monkeypatch, path, enabled=enabled)
|
||||
return path
|
||||
|
||||
return make
|
||||
|
||||
|
||||
def _infos(monkeypatch: pytest.MonkeyPatch) -> list[str]:
|
||||
messages: list[str] = []
|
||||
monkeypatch.setattr(calibre.logger, "info", lambda msg, *args: messages.append(msg % args))
|
||||
@@ -317,3 +333,126 @@ def test_fingerprint_follows_the_database_and_wal_mtime(
|
||||
os.utime(wal, (later, later))
|
||||
|
||||
assert provider.fingerprint() == later
|
||||
|
||||
|
||||
def _library_with(path: Path, books: list[tuple[int, str, str, str | None]]) -> None:
|
||||
"""A library of (id, title, author, series) rows."""
|
||||
conn = sqlite3.connect(path)
|
||||
conn.executescript(_SCHEMA)
|
||||
series_ids: dict[str, int] = {}
|
||||
for book_id, title, author, series_name in books:
|
||||
conn.execute(
|
||||
"INSERT INTO books(id, title, uuid) VALUES (?, ?, ?)", (book_id, title, f"u{book_id}")
|
||||
)
|
||||
conn.execute("INSERT INTO authors(id, name) VALUES (?, ?)", (book_id, author))
|
||||
conn.execute(
|
||||
"INSERT INTO books_authors_link(book, author) VALUES (?, ?)", (book_id, book_id)
|
||||
)
|
||||
if series_name:
|
||||
sid = series_ids.setdefault(series_name, len(series_ids) + 1)
|
||||
conn.execute("INSERT OR IGNORE INTO series(id, name) VALUES (?, ?)", (sid, series_name))
|
||||
conn.execute(
|
||||
"INSERT INTO books_series_link(book, series) VALUES (?, ?)", (book_id, sid)
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
def _owned(entries: list[Any], title: str, author: str) -> str | None:
|
||||
book = BookMetadata(provider="hardcover", provider_id="x", title=title, authors=[author])
|
||||
return library_index.match_entries(book, entries)
|
||||
|
||||
|
||||
def test_an_abbreviated_series_label_in_the_title_does_not_hide_an_owned_book(
|
||||
tmp_path: Path, calibre_library: Callable[..., Path]
|
||||
) -> None:
|
||||
# The library names books "Label NN: Title". When the label abbreviates the series
|
||||
# ("HHG" for The Hitchhiker's Guide to the Galaxy) its words are in neither the
|
||||
# series nor the author, and the book read as not owned, so it was fetched again.
|
||||
path = tmp_path / "metadata.db"
|
||||
_library_with(
|
||||
path,
|
||||
[
|
||||
(1, "HHG 5: Mostly Harmless", "Douglas Adams", "The Hitchhiker's Guide to the Galaxy"),
|
||||
(2, "DCC 7: This Inevitable Ruin", "Matt Dinniman", "Dungeon Crawler Carl"),
|
||||
],
|
||||
)
|
||||
calibre_library(path=path, create=False)
|
||||
entries = calibre.CalibreLibrary().fetch_entries()
|
||||
|
||||
assert _owned(entries, "Mostly Harmless", "Douglas Adams") == "owned"
|
||||
assert _owned(entries, "This Inevitable Ruin", "Matt Dinniman") == "owned"
|
||||
|
||||
|
||||
def test_a_series_label_still_does_not_make_a_different_book_match(
|
||||
tmp_path: Path, calibre_library: Callable[..., Path]
|
||||
) -> None:
|
||||
path = tmp_path / "metadata.db"
|
||||
_library_with(
|
||||
path,
|
||||
[(1, "HHG 5: Mostly Harmless", "Douglas Adams", "The Hitchhiker's Guide to the Galaxy")],
|
||||
)
|
||||
calibre_library(path=path, create=False)
|
||||
entries = calibre.CalibreLibrary().fetch_entries()
|
||||
|
||||
assert _owned(entries, "Harmless", "Douglas Adams") is None
|
||||
assert _owned(entries, "Mostly Harmless", "Someone Else") is None
|
||||
|
||||
|
||||
def test_a_title_prefix_without_a_series_is_left_alone(
|
||||
tmp_path: Path, calibre_library: Callable[..., Path]
|
||||
) -> None:
|
||||
# Only a book that has a series gets its leading "Label NN:" treated as the label.
|
||||
path = tmp_path / "metadata.db"
|
||||
_library_with(path, [(1, "Messiah 2: Dune", "Frank Herbert", None)])
|
||||
calibre_library(path=path, create=False)
|
||||
entries = calibre.CalibreLibrary().fetch_entries()
|
||||
|
||||
assert _owned(entries, "Dune", "Frank Herbert") is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"shelf_title",
|
||||
[
|
||||
"Dungeon Crawler Carl (Full Cast Edition)",
|
||||
"Dungeon Crawler Carl (Dramatized Adaptation)",
|
||||
"Dungeon Crawler Carl [GraphicAudio]",
|
||||
],
|
||||
)
|
||||
def test_an_edition_marker_in_the_title_is_a_different_edition(
|
||||
tmp_path: Path, calibre_library: Callable[..., Path], shelf_title: str
|
||||
) -> None:
|
||||
# A bracketed marker with no number in it describes the edition. Owning a full-cast
|
||||
# or dramatized recording is not owning the book it adapts, so the request must
|
||||
# not be closed as already in the library.
|
||||
path = tmp_path / "metadata.db"
|
||||
_library_with(path, [(1, shelf_title, "Matt Dinniman", None)])
|
||||
calibre_library(path=path, create=False)
|
||||
entries = calibre.CalibreLibrary().fetch_entries()
|
||||
|
||||
assert _owned(entries, "Dungeon Crawler Carl", "Matt Dinniman") is None
|
||||
# The same edition, asked for by its own name, is on the shelf.
|
||||
assert _owned(entries, shelf_title, "Matt Dinniman") == "owned"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("shelf_title", "series"),
|
||||
[
|
||||
("Kiss the Girls (Alex Cross Series #11)", None),
|
||||
("Kiss the Girls (Alex Cross, Book 2)", None),
|
||||
("Alex Cross 02: Kiss the Girls", "Alex Cross"),
|
||||
("Kiss the Girls (Illustrated Edition)", None),
|
||||
("Kiss the Girls (Unabridged)", None),
|
||||
],
|
||||
)
|
||||
def test_series_metadata_and_printing_words_in_the_title_do_not_hide_the_book(
|
||||
tmp_path: Path, calibre_library: Callable[..., Path], shelf_title: str, series: str | None
|
||||
) -> None:
|
||||
# A numbered parenthetical is the series by Calibre convention, often in place of
|
||||
# the series field, and a printing word changes nothing about which work it is.
|
||||
path = tmp_path / "metadata.db"
|
||||
_library_with(path, [(1, shelf_title, "James Patterson", series)])
|
||||
calibre_library(path=path, create=False)
|
||||
entries = calibre.CalibreLibrary().fetch_entries()
|
||||
|
||||
assert _owned(entries, "Kiss the Girls", "James Patterson") == "owned"
|
||||
Reference in new issue
Block a user